Skip to content

Fix pyspark.pandas coerce+nullable failure case reporting - #2256

Merged
cosmicbboy merged 4 commits into
unionai-oss:mainfrom
RedZapdos123:fix-2150-pysparkpandas-coerce-nullable
Apr 4, 2026
Merged

cosmicbboy merged 4 commits into
unionai-oss:mainfrom
RedZapdos123:fix-2150-pysparkpandas-coerce-nullable

Conversation

@RedZapdos123

@RedZapdos123 RedZapdos123 commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes issue #2150 for pandera.pandas used with pyspark.pandas.

When coerce=True and
ullable=True, invalid values in numeric coercion paths were being converted to nulls and not reported as coercion failure cases.

Changes:

  • Detect coercion introduced nulls in pandas array backend for pyspark.pandas objects.
  • Raise SchemaError with DATATYPE_COERCION and concrete ailure_cases for those values.
  • Add regression test: est_dtype_coercion_nullable_reports_invalid_values.

Reproduction:

  • Confirmed the bug on clean main clone:
    • invalid values in distance (coerce=True,
      ullable=True) were not reported.
    • only unrelated dtype failures were reported.

Validation:

  • pytest tests/pyspark/test_schemas_on_pyspark_pandas.py -q -p no:warnings
    • result: 262 passed, 243 skipped (with Spark ANSI disabled in this environment for stable pyspark behavior)
  • pytest tests/pyspark/test_schemas_on_pyspark_pandas.py -k dtype_coercion_nullable_reports_invalid_values -q
    • result: passed
Screenshot 2026-04-02 175232

Note: Spark ANSI mode setting was environment specific for this run. With ANSI enabled, pyspark can raise NumberFormatException before pandera collects failure cases in some tests. Disabling ANSI aligns behavior with the expected pandas on Spark coercion semantics used by this test module.

Detect coercion-introduced nulls for pyspark.pandas and raise datatype coercion errors with failure cases. Add regression test for issue unionai-oss#2150.

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
@codecov

codecov Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.99%. Comparing base (461d737) to head (13c68ea).
⚠️ Report is 165 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2256      +/-   ##
==========================================
+ Coverage   83.97%   83.99%   +0.02%     
==========================================
  Files         138      138              
  Lines       11114    11130      +16     
==========================================
+ Hits         9333     9349      +16     
  Misses       1781     1781              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Move coercion-guard branch coverage tests into existing pandas schema tests to increase patch coverage for array backend changes.

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
@RedZapdos123

RedZapdos123 commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Coverage follow up pushed to address Codecov patch gaps in pandera/backends/pandas/array.py.

Changes:

  • Moved/added focused branch coverage tests into existing ests/pandas/test_schemas.py (no new test file).
  • Added tests for:
    • introduced-null detection path.
    • normal no-null-introduced path.
    • fallback path when introduced-null detection raises.
    • fallback subpath when failure-case extraction itself raises.

Validation run:

  • pytest tests/pandas/test_schemas.py -k 'array_backend_coerce or series_schema' -q -p no:warnings -> passed
  • pytest tests/pyspark/test_schemas_on_pyspark_pandas.py -k dtype_coercion_nullable_reports_invalid_values -q -p no:warnings -> passed
Screenshot 2026-04-02 180808

This should improve patch coverage for the touched backend lines.

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
@cosmicbboy
cosmicbboy merged commit 04faec3 into unionai-oss:main Apr 4, 2026
291 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants