Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid get_dummies dtype change in pandas v2 (keep backwards compatible) #228

Merged
merged 1 commit into from
Jul 23, 2023
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
8 changes: 4 additions & 4 deletions examples/data_quality/pandera/feature_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def seasons_encoded__base(seasons: pd.Series) -> pd.DataFrame:
3 - third season
4 - fourth season
"""
return pd.get_dummies(seasons, prefix="seasons")
return pd.get_dummies(seasons, prefix="seasons", dtype=np.uint8)


@check_output(schema=seasons_encoded_schema)
Expand All @@ -110,7 +110,7 @@ def seasons_encoded__dask(seasons: pd.Series) -> pd.DataFrame:
import dask.dataframe as dd

categorized = seasons.astype(str).to_frame().categorize()
df = dd.get_dummies(categorized, prefix="seasons")
df = dd.get_dummies(categorized, prefix="seasons", dtype=np.uint8)
return df


Expand Down Expand Up @@ -165,7 +165,7 @@ def day_of_week_encoded__base(day_of_the_week: pd.Series) -> pd.DataFrame:
"""One hot encodes day of week into five dimensions -- Saturday & Sunday weren't present.
1 - Sunday, 2 - Monday, 3 - Tuesday, 4 - Wednesday, 5 - Thursday, 6 - Friday, 7 - Saturday.
"""
return pd.get_dummies(day_of_the_week, prefix="day_of_the_week")
return pd.get_dummies(day_of_the_week, prefix="day_of_the_week", dtype=np.uint8)


@check_output(schema=day_of_week_encoded_schema)
Expand All @@ -177,7 +177,7 @@ def day_of_week_encoded__dask(day_of_the_week: pd.Series) -> pd.DataFrame:
import dask.dataframe as dd

categorized = day_of_the_week.astype(str).to_frame().categorize()
df = dd.get_dummies(categorized, prefix="day_of_the_week")
df = dd.get_dummies(categorized, prefix="day_of_the_week", dtype=np.uint8)
return df


Expand Down
4 changes: 2 additions & 2 deletions examples/data_quality/pandera/feature_logic_spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def seasons_encoded(seasons: pd.Series) -> pd.DataFrame:
3 - third season
4 - fourth season
"""
return ps.get_dummies(seasons, prefix="seasons")
return ps.get_dummies(seasons, prefix="seasons", dtype=np.uint8)


seasons_schema = pa.SeriesSchema(
Expand Down Expand Up @@ -140,7 +140,7 @@ def day_of_week_encoded(day_of_the_week: pd.Series) -> pd.DataFrame:
"""One hot encodes day of week into five dimensions -- Saturday & Sunday weren't present.
1 - Sunday, 2 - Monday, 3 - Tuesday, 4 - Wednesday, 5 - Thursday, 6 - Friday, 7 - Saturday.
"""
return ps.get_dummies(day_of_the_week, prefix="day_of_the_week")
return ps.get_dummies(day_of_the_week, prefix="day_of_the_week", dtype=np.uint8)


day_of_week_schema = pa.SeriesSchema(
Expand Down