Skip to content

Commit

Permalink
avoid running nullable checks if nullable=true
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Oliveira <[email protected]>
  • Loading branch information
filipeo2-mck committed Nov 2, 2023
1 parent 37c24d9 commit 7675ae8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pandera/backends/pyspark/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ def coerce_dtype(

@validate_scope(scope=ValidationScope.SCHEMA)
def check_nullable(self, check_obj: DataFrame, schema):
isna = (
check_obj.filter(col(schema.name).isNull()).limit(1).count() == 0
)
passed = schema.nullable or isna
# If True, ignore this `nullable` check
passed = schema.nullable

Check warning on line 129 in pandera/backends/pyspark/column.py

View check run for this annotation

Codecov / codecov/patch

pandera/backends/pyspark/column.py#L129

Added line #L129 was not covered by tests

# If False, execute the costly validation
if not schema.nullable:
passed = (

Check warning on line 133 in pandera/backends/pyspark/column.py

View check run for this annotation

Codecov / codecov/patch

pandera/backends/pyspark/column.py#L132-L133

Added lines #L132 - L133 were not covered by tests
check_obj.filter(col(schema.name).isNull()).limit(1).count()
== 0
)

return CoreCheckResult(
check="not_nullable",
reason_code=SchemaErrorReason.SERIES_CONTAINS_NULLS,
Expand Down

0 comments on commit 7675ae8

Please sign in to comment.