Merged in bugfix/date-format-fixes (pull request #577)

Bugfix/date format fixes

* Switch to 12/31 for auto renews

* Remove redundant postprocessing

* Switch to 12/31 for auto renews

* auto renew = Y


Approved-by: Alex Galarce
This commit is contained in:
Katon Minhas
2025-06-17 20:26:39 +00:00
parent 31e1c43f0a
commit 2e0fa2eed6
2 changed files with 10 additions and 21 deletions
@@ -347,23 +347,6 @@ def auto_renewal(df: pd.DataFrame) -> pd.DataFrame:
df["AUTO_RENEWAL_TERM"] = df["AUTO_RENEWAL_TERM"].apply(normalize_auto_renewal_term) df["AUTO_RENEWAL_TERM"] = df["AUTO_RENEWAL_TERM"].apply(normalize_auto_renewal_term)
return df return df
# Special handling for derived termination date if auto-renewal is present
def handle_auto_renewal_termination_date(df: pd.DataFrame) -> pd.DataFrame:
"""
Handles the derived termination date for rows where auto-renewal is indicated.
Args:
df (pd.DataFrame): The input DataFrame.
Returns:
pd.DataFrame: The updated DataFrame with derived termination dates adjusted for auto-renewal.
"""
if "AARETE_DERIVED_TERMINATION_DT" in df.columns and "AUTO_RENEWAL_IND" in df.columns:
df.loc[
df["AUTO_RENEWAL_IND"] == "Y",
"AARETE_DERIVED_TERMINATION_DT"
] = "9999/01/01"
return df
def update_termination_date_for_conditions(df: pd.DataFrame) -> pd.DataFrame: def update_termination_date_for_conditions(df: pd.DataFrame) -> pd.DataFrame:
""" """
@@ -376,13 +359,22 @@ def update_termination_date_for_conditions(df: pd.DataFrame) -> pd.DataFrame:
Returns: Returns:
pd.DataFrame: The updated DataFrame with modified 'AARETE_DERIVED_TERMINATION_DT' values. pd.DataFrame: The updated DataFrame with modified 'AARETE_DERIVED_TERMINATION_DT' values.
""" """
if "TERMINATION_DT" in df.columns and "AUTO_RENEWAL_IND" in df.columns and "AARETE_DERIVED_TERMINATION_DT" in df.columns: if "TERMINATION_DT" in df.columns and "AUTO_RENEWAL_IND" in df.columns and "AARETE_DERIVED_TERMINATION_DT" in df.columns:
# Replace Y with 9999/12/31
df.loc[
df["AUTO_RENEWAL_IND"] == "Y",
"AARETE_DERIVED_TERMINATION_DT"
] = "9999/12/31"
# Replace "N" and "year to year" with 9999/12/31
df.loc[ df.loc[
(df["TERMINATION_DT"] == "year to year") & (df["TERMINATION_DT"] == "year to year") &
(df["AUTO_RENEWAL_IND"] == "N") & (df["AUTO_RENEWAL_IND"] == "N") &
(df["AARETE_DERIVED_TERMINATION_DT"] == "N/A"), (df["AARETE_DERIVED_TERMINATION_DT"] == "N/A"),
"AARETE_DERIVED_TERMINATION_DT" "AARETE_DERIVED_TERMINATION_DT"
] = "9999/01/01" ] = "9999/12/31"
return df return df
def standardize_reimb_method_and_fee_schedule(df: pd.DataFrame) -> pd.DataFrame: def standardize_reimb_method_and_fee_schedule(df: pd.DataFrame) -> pd.DataFrame:
@@ -49,9 +49,6 @@ def postprocess(df):
# Normalize the 'AUTO_RENEWAL_TERM' column # Normalize the 'AUTO_RENEWAL_TERM' column
df = investment_postprocessing_funcs.auto_renewal(df) df = investment_postprocessing_funcs.auto_renewal(df)
# Special handling for derived termination date if auto-renewal is present
df = investment_postprocessing_funcs.handle_auto_renewal_termination_date(df)
# Check conditions for TERMINATION_DT, AUTO_RENEWAL_IND, and AARETE_DERIVED_TERMINATION_DT # Check conditions for TERMINATION_DT, AUTO_RENEWAL_IND, and AARETE_DERIVED_TERMINATION_DT
df = investment_postprocessing_funcs.update_termination_date_for_conditions(df) df = investment_postprocessing_funcs.update_termination_date_for_conditions(df)