Skip to content

fix(polars): accept negative literals in parametrized dtype reprs - #2546

Open
barlowa124 wants to merge 1 commit into
unionai-oss:mainfrom
barlowa124:polars-parametrized-dtype-2522
Open

barlowa124 wants to merge 1 commit into
unionai-oss:mainfrom
barlowa124:polars-parametrized-dtype-2522

Conversation

@barlowa124

@barlowa124 barlowa124 commented Oct 6, 2026 •

Copy link
Copy Markdown

Summary

Follow-up to #2523, which reads parametrized polars dtypes back from yaml/json. Its repr parser (_polars_dtype_from_repr) rejects unary minus, so a Decimal with a negative scale fails to deserialize even though polars emits that repr:

str(pl.Decimal(precision=10, scale=-2)) == 'Decimal(precision=10, scale=-2)'

This adds UAdd/USub handling for numeric literals in the AST whitelist, nothing else changes. The original version of this PR implemented the whole repr parser independently. #2523 landed first, so this is rebased down to the remaining gap.

Tests

  • A Decimal with negative scale joins the parametrized round-trip cases (yaml + json).
  • Extra rejected expressions in test_polars_from_yaml_rejects_non_dtype_text: x**y, List(**{'x': 1}), Durat ion, f'{x}'.

pytest tests/io/test_polars_io.py passes.

Backward compatibility

No user-facing behavior change beyond accepting dtype reprs that previously raised TypeError. Rejection cases still raise TypeError with the same "cannot parse input" message. The new test parameters only extend coverage of that contract.

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.00%. Comparing base (29486d1) to head (149fbc6).

Files with missing lines Patch % Lines
pandera/io/polars_io.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2546      +/-   ##
==========================================
- Coverage   83.00%   83.00%   -0.01%     
==========================================
  Files         260      260              
  Lines       22949    22954       +5     
==========================================
+ Hits        19048    19052       +4     
- Misses       3901     3902       +1     
Flag Coverage Δ
unit-tests-io-Linux-py3.10-pandas2.3.3-pydantic2.12.3 34.02% <80.00%> (-0.28%) ⬇️
unit-tests-io-Linux-py3.11-pandas2.3.3-pydantic2.12.3 34.02% <80.00%> (-0.07%) ⬇️
unit-tests-io-Linux-py3.11-pandas3.0.0-pydantic2.12.3 33.99% <80.00%> (-0.07%) ⬇️
unit-tests-io-Linux-py3.12-pandas2.3.3-pydantic2.12.3 34.02% <80.00%> (-0.28%) ⬇️
unit-tests-io-Linux-py3.12-pandas3.0.0-pydantic2.12.3 33.99% <80.00%> (-0.07%) ⬇️
unit-tests-io-Linux-py3.13-pandas2.3.3-pydantic2.12.3 34.02% <80.00%> (-0.47%) ⬇️
unit-tests-io-Linux-py3.13-pandas3.0.0-pydantic2.12.3 33.99% <80.00%> (-0.28%) ⬇️
unit-tests-io-Linux-py3.14-pandas2.3.3-pydantic2.12.3 33.93% <80.00%> (-0.07%) ⬇️
unit-tests-io-Linux-py3.14-pandas3.0.0-pydantic2.12.3 33.89% <80.00%> (-0.07%) ⬇️
unit-tests-io-Windows-py3.10-pandas2.3.3-pydantic2.12.3 33.82% <80.00%> (-0.28%) ⬇️
unit-tests-io-Windows-py3.11-pandas2.3.3-pydantic2.12.3 33.82% <80.00%> (-0.28%) ⬇️
unit-tests-io-Windows-py3.11-pandas3.0.0-pydantic2.12.3 33.79% <80.00%> (-0.07%) ⬇️
unit-tests-io-Windows-py3.12-pandas2.3.3-pydantic2.12.3 33.82% <80.00%> (-0.28%) ⬇️
unit-tests-io-Windows-py3.12-pandas3.0.0-pydantic2.12.3 33.79% <80.00%> (-0.28%) ⬇️
unit-tests-io-Windows-py3.13-pandas2.3.3-pydantic2.12.3 33.82% <80.00%> (-0.28%) ⬇️
unit-tests-io-Windows-py3.13-pandas3.0.0-pydantic2.12.3 33.79% <80.00%> (-0.28%) ⬇️
unit-tests-io-Windows-py3.14-pandas2.3.3-pydantic2.12.3 33.73% <80.00%> (-0.28%) ⬇️
unit-tests-io-Windows-py3.14-pandas3.0.0-pydantic2.12.3 33.69% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.10-pandas2.3.3-pydantic2.12.3 33.98% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.11-pandas2.3.3-pydantic2.12.3 33.98% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.11-pandas3.0.0-pydantic2.12.3 33.94% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.12-pandas2.3.3-pydantic2.12.3 33.98% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.12-pandas3.0.0-pydantic2.12.3 33.94% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.13-pandas2.3.3-pydantic2.12.3 33.98% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.13-pandas3.0.0-pydantic2.12.3 33.94% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.14-pandas2.3.3-pydantic2.12.3 33.88% <80.00%> (-0.28%) ⬇️
unit-tests-io-macOS-py3.14-pandas3.0.0-pydantic2.12.3 33.85% <80.00%> (-0.28%) ⬇️
unit-tests-narwhals-backend-polars-py3.10 32.72% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.11 32.71% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.12 32.71% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.13 32.71% <0.00%> (-0.01%) ⬇️
unit-tests-narwhals-backend-polars-py3.14 32.59% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.10-pandas2.3.3-polars1.20.0 27.76% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.11-pandas2.3.3-polars1.20.0 27.75% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.12-pandas2.3.3-polars1.33.1 27.75% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.13-pandas2.3.3-polars1.33.1 27.75% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Linux-py3.14-pandas2.3.3-polars1.42.1 27.64% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.10-pandas2.3.3-polars1.20.0 27.70% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.11-pandas2.3.3-polars1.20.0 27.69% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.12-pandas2.3.3-polars1.33.1 27.69% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.13-pandas2.3.3-polars1.33.1 27.69% <0.00%> (-0.01%) ⬇️
unit-tests-polars-Windows-py3.14-pandas2.3.3-polars1.42.1 27.58% <0.00%> (+2.49%) ⬆️
unit-tests-polars-macOS-py3.10-pandas2.3.3-polars1.20.0 27.71% <0.00%> (+2.78%) ⬆️
unit-tests-polars-macOS-py3.11-pandas2.3.3-polars1.20.0 27.70% <0.00%> (-0.01%) ⬇️
unit-tests-polars-macOS-py3.12-pandas2.3.3-polars1.33.1 27.70% <0.00%> (+2.48%) ⬆️
unit-tests-polars-macOS-py3.13-pandas2.3.3-polars1.33.1 27.70% <0.00%> (+2.63%) ⬆️
unit-tests-polars-macOS-py3.14-pandas2.3.3-polars1.42.1 27.59% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

unionai-oss#2523 reads parametrized polars dtypes back from yaml/json but its
repr parser rejects unary minus, so a Decimal with a negative scale
fails to deserialize even though polars emits that repr, e.g.
Decimal(precision=10, scale=-2). Accept UAdd/USub on numeric
literals. Tests cover the negative-scale round trip plus extra
rejected expressions.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@barlowa124
barlowa124 force-pushed the polars-parametrized-dtype-2522 branch from 62c5136 to 149fbc6 Compare November 21, 2026 22:25
@barlowa124 barlowa124 changed the title fix(polars): deserialize parametrized dtypes from yaml/json fix(polars): accept negative literals in parametrized dtype reprs Nov 21, 2026

This branch has not been deployed

No deployments
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.

1 participant