Skip to content

Commit

Permalink
refactor: pandas deprecates inplace parameter (DEV-2618) (#511)
Browse files Browse the repository at this point in the history
* Remove all the inplace

* Update xml-data-file.md

* Update test_properties.py
  • Loading branch information
Nora-Olivia-Ammann committed Sep 11, 2023
1 parent c25f3b7 commit 8d6d3f7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/dsp_tools/excel2xml.py
Expand Up @@ -1902,8 +1902,8 @@ def _validate_and_prepare_cli_input_file(dataframe: pd.DataFrame) -> pd.DataFram
)

# remove empty columns/rows
dataframe.dropna(axis="columns", how="all", inplace=True)
dataframe.dropna(axis="index", how="all", inplace=True)
dataframe = dataframe.dropna(axis="columns", how="all")
dataframe = dataframe.dropna(axis="index", how="all")

return dataframe

Expand Down
4 changes: 2 additions & 2 deletions src/dsp_tools/utils/excel2json/properties.py
Expand Up @@ -362,7 +362,7 @@ def _rename_deprecated_hlist(df: pd.DataFrame, excelfile: str) -> pd.DataFrame:
# In case there is a hlist, it is the only valid value in gui_attributes and has precedence
df["hlist"] = df["hlist"].fillna(df["gui_attributes"])
df.pop("gui_attributes")
df.rename(columns={"hlist": "gui_attributes"}, inplace=True)
df = df.rename(columns={"hlist": "gui_attributes"})
return df


Expand Down Expand Up @@ -392,7 +392,7 @@ def _rename_deprecated_lang_cols(df: pd.DataFrame, excelfile: str) -> pd.DataFra
f"Please use {[f'label_{lang}' for lang in languages]}"
)
rename_dict = dict(zip(languages, language_label_col))
df.rename(columns=rename_dict, inplace=True)
df = df.rename(columns=rename_dict)
return df


Expand Down
2 changes: 1 addition & 1 deletion src/dsp_tools/utils/excel2json/utils.py
Expand Up @@ -60,7 +60,7 @@ def clean_data_frame(df: pd.DataFrame) -> pd.DataFrame:
lambda x: str(x).strip() if pd.notna(x) and regex.search(r"[\w\p{L}]", str(x), flags=regex.U) else pd.NA
)
# drop all the rows that are entirely empty
df.dropna(axis=0, how="all", inplace=True)
df = df.dropna(axis=0, how="all")
return df


Expand Down
2 changes: 1 addition & 1 deletion test/unittests/test_excel2json/test_lists.py
Expand Up @@ -93,7 +93,7 @@ def test_excel2lists(self) -> None:
input_df = input_df.map(
lambda x: x if pd.notna(x) and regex.search(r"\p{L}", str(x), flags=regex.UNICODE) else pd.NA
)
input_df.dropna(axis="index", how="all", inplace=True)
input_df = input_df.dropna(axis="index", how="all")
excelfolder = f"testdata/excel2json/lists-{mode}"
outfile = f"testdata/tmp/lists_output_{mode}.json"
output_from_method, _ = e2l.excel2lists(excelfolder=excelfolder, path_to_output_file=outfile)
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/test_excel2json/test_properties.py
Expand Up @@ -370,9 +370,9 @@ def test__rename_deprecated_lang_cols(self) -> None:
}
)
returned_df = e2j._rename_deprecated_lang_cols(df=original_df, excelfile="Test")
assert_frame_equal(original_df, returned_df)
assert_frame_equal(expected_df, returned_df)
returned_df = e2j._rename_deprecated_lang_cols(df=expected_df, excelfile="Test")
assert_frame_equal(original_df, returned_df)
assert_frame_equal(expected_df, returned_df)

def test__do_property_excel_compliance(self) -> None:
original_df = pd.DataFrame(
Expand Down

0 comments on commit 8d6d3f7

Please sign in to comment.