Skip to content

Commit ee42ba8

Browse files
committed
fix: update imputation method to avoid warnings
1 parent 377b659 commit ee42ba8

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/sasctl/pzmm/write_score_code.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,15 @@ def impute_missing_values(data):
766766
"""
767767
impute_values = \\\n + {"var1": 0, "var2": "", "var3": 125.3}
768768
"""
769-
self.score_code += f"\n{'':4}return data.replace(' .', np.nan).fillna(impute_values).apply(pd.to_numeric, errors='ignore')\n"
769+
self.score_code += f"\n\n{'':4}# Specify downcasting behavior for pandas 2.x to avoid warnings\n"
770+
self.score_code += f"{'':4}if int(pd.__version__.split('.')[0]) == 2:\n{'':8}pd.set_option('future.no_silent_downcasting', True)\n"
771+
self.score_code += f"{'':4}return data.replace(r'^\\s*\\.$', np.nan, regex=True).fillna(impute_values).infer_objects()\n"
770772
"""
771773
772-
return data.replace(' .', np.nan).fillna(impute_values).apply(pd.to_numeric, errors='ignore')
774+
# Specify downcasting behavior for pandas 2.x to avoid warnings
775+
if int(pd.__version__.split('.')[0]) == 2:
776+
pd.set_option('future.no_silent_downcasting', True)
777+
return data.replace(r'^\s*\.$', np.nan, regex=True).fillna(impute_values).infer_objects()
773778
"""
774779

775780
# TODO: Needs unit test

0 commit comments

Comments
 (0)