Skip to content

Commit 70d55ee

Browse files
authored
remove assumption from nullable strategies (#641)
fixes #640. This PR improves the performance of schema strategies that involve nullable fields. Instead of a 10x performance hit it's a 2x performance hit for specifying a nullable column.
1 parent 0b3b434 commit 70d55ee

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

pandera/strategies.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ def null_field_masks(draw, strategy: Optional[SearchStrategy]):
8787
val = draw(strategy)
8888
size = val.shape[0]
8989
null_mask = draw(st.lists(st.booleans(), min_size=size, max_size=size))
90-
# assume that there is at least one masked value
91-
hypothesis.assume(any(null_mask))
9290
if isinstance(val, pd.Index):
9391
val = val.to_series()
9492
val = _mask(val, null_mask)
@@ -127,8 +125,6 @@ def null_dataframe_masks(
127125
index=pdst.range_indexes(min_size=size, max_size=size),
128126
)
129127
null_mask = draw(mask_st)
130-
# assume that there is at least one masked value
131-
hypothesis.assume(null_mask.any(axis=None))
132128
for column in val:
133129
val[column] = _mask(val[column], null_mask[column])
134130
return val

tests/strategies/test_strategies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def test_check_nullable_field_strategy(
696696
example = data.draw(strat)
697697

698698
if nullable:
699-
assert example.isna().any()
699+
assert example.isna().sum() >= 0
700700
else:
701701
assert example.notna().all()
702702

@@ -717,7 +717,7 @@ def test_check_nullable_dataframe_strategy(data_type, nullable, data):
717717
)
718718
example = data.draw(strat)
719719
if nullable:
720-
assert example.isna().any(axis=None)
720+
assert example.isna().sum(axis=None).item() >= 0
721721
else:
722722
assert example.notna().all(axis=None)
723723

0 commit comments

Comments
 (0)