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

make df strategy less complex #989

Merged
merged 1 commit into from
Oct 28, 2022
Merged
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
15 changes: 12 additions & 3 deletions pandera/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,14 +1103,23 @@ def _dataframe_strategy(draw):
)

# this is a hack to convert np.str_ data values into native python str.
string_columns = []
for col_name, col_dtype in col_dtypes.items():
if col_dtype in {"object", "str"} or col_dtype.startswith(
"string"
):
# pylint: disable=cell-var-from-loop,undefined-loop-variable
strategy = strategy.map(
lambda df: df.assign(**{col_name: df[col_name].map(str)})
string_columns.append(col_name)

if string_columns:
# pylint: disable=cell-var-from-loop,undefined-loop-variable
strategy = strategy.map(
lambda df: df.assign(
**{
col_name: df[col_name].map(str)
for col_name in string_columns
}
)
)

strategy = strategy.map(
lambda df: df if df.empty else df.astype(col_dtypes)
Expand Down