Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion leakpro/synthetic_data_attacks/anomalies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def encode_categorical_columns(*, df: pd.DataFrame, threshold_one_hot_encoding:
df_encoded = df.copy()
# Iterate through each column in the DataFrame
for column in df_encoded.columns:
if df_encoded[column].dtype == "object":
if pd.api.types.is_string_dtype(df_encoded[column]):
unique_values = df_encoded[column].nunique()
if unique_values <= threshold_one_hot_encoding:
# Perform one-hot encoding
Expand Down
6 changes: 5 additions & 1 deletion leakpro/tests/tests_synthetic_data_attacks/test_anomalies.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

def test_encode_categorical_columns() -> None:
"""Assert results for encode_categorical_columns function with simple input."""
assert list(df.dtypes) == [np.dtype("int64"), np.dtype("bool"), np.dtype("O"), np.dtype("O")]
# Check dtypes - newer pandas may use StringDtype instead of object
assert df["non_cat"].dtype == np.dtype("int64")
assert df["cat_bool"].dtype == np.dtype("bool")
assert pd.api.types.is_string_dtype(df["cat_less_threshold"])
assert pd.api.types.is_string_dtype(df["cat_more_threshold"])
df_encoded = anom.encode_categorical_columns(df=df)
assert list(df_encoded.columns) == ["non_cat", "cat_bool", "cat_more_threshold", "cat_less_threshold_True"]
assert df_encoded[["non_cat", "cat_bool"]].equals(df[["non_cat", "cat_bool"]])
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dev = [
"kornia", # from minv
"albumentations", # federated example
"transformers", # federated example
"requests",
]

[tool.setuptools]
Expand Down