Skip to content

Commit

Permalink
(HP-1932) Handle deprecation warning for fillna
Browse files Browse the repository at this point in the history
  • Loading branch information
george42-ctds committed Feb 20, 2025
1 parent d7b499f commit 8359e72
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions heal/vlmd/extract/redcap_csv_dict_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ def rename_and_fill(source_dataframe) -> list[dict]:
.map(utils.strip_html)
)

# TODO: FutureWarning: Downcasting behavior in `replace` is deprecated and will be removed in a future version.
# To retain the old behavior, explicitly call `result.infer_objects(copy=False)`.
# To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`

# downfill section (if blank -- given we read in with petl, blanks are "" but ffill takes in np.nan)
source_dataframe["section"] = (
source_dataframe.replace({"": np.nan}).groupby("form")["section"].ffill()
)
source_dataframe.fillna("", inplace=True)
# Recover any remaining np.nan (ie, not converted by 'ffill') back to "".
# Include the 'infer_objects' method as described here
# https://pandas.pydata.org/docs/whatsnew/v2.2.0.html#deprecated-automatic-downcasting
source_dataframe = source_dataframe.fillna("").infer_objects(copy=False)
return source_dataframe.to_dict(orient="records")


Expand Down

0 comments on commit 8359e72

Please sign in to comment.