Skip to content

Commit 971cae8

Browse files
authored
Allow strict='filter' and coerce='True' at the same time for PySpark schemas. Generalize test to validate this case. (#2032)
Signed-off-by: Gianluca Filaci <[email protected]> Co-authored-by: Gianluca Filaci <>
1 parent 95dd3e9 commit 971cae8

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

pandera/backends/pyspark/container.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ def strict_filter_columns(
390390
)
391391

392392
if schema.strict == "filter":
393+
schema = check_obj.pandera.schema
393394
check_obj = check_obj.drop(*filter_out_columns)
395+
check_obj.pandera.add_schema(schema)
394396

395397
return check_obj
396398

tests/pyspark/test_pyspark_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ def test_dataframe_schema_strict(
370370
if df_out.pandera.errors:
371371
raise pa.PysparkSchemaError
372372

373+
schema.coerce = True
373374
schema.strict = "filter"
374375
assert isinstance(schema.validate(df), DataFrame)
375376

0 commit comments

Comments
 (0)