chore: Fix Decimal precision annotation#25227
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25227 +/- ##
==========================================
+ Coverage 81.77% 81.89% +0.11%
==========================================
Files 1713 1714 +1
Lines 236780 239028 +2248
Branches 3013 3249 +236
==========================================
+ Hits 193629 195745 +2116
- Misses 42381 42485 +104
- Partials 770 798 +28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for contributing - however, as per the docstring, pl.Decimal(precision=None, scale=3)
# Decimal(precision=None, scale=3) |
Add assertion and cast for dtype.precision in _dtype_to_header to work around incorrect polars type stubs where precision is typed as int | None. At runtime, Decimal precision is never None. This workaround is gated by POLARS_VERSION_LT_136 check and can be removed when upgrading to polars >= 1.36, which will include the upstream fix. Upstream fix: pola-rs/polars#25227 Reduces mypy errors from 31 to 30. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
@alexander-beedie are we looking at different versions? I see this: In [1]: import polars as pl
In [2]: pl.Decimal(precision=None, scale=3)
Out[2]: Decimal(precision=38, scale=3)
In [3]: pl.__version__
Out[3]: '1.35.2'It looks like #24742 might have changed the docstring, but not the type annotation. |
|
Oof; I stand corrected - apparently I was looking at this on a secondary laptop that hadn't been updated to latest |
|
|
|
Nevermind, this only touches the member variables and not the constructor. |
|
@alexander-beedie thanks for reviewing so quickly! However, I think the behavior you're showing might be outdated. #24542 modified how precision works for decimals (specifically this diff), see the extended discussion in #19784. As a result precision is always set to a non-None value (of 38) on construction if None is provided. Consider: ❯ uv pip install polars==1.33
...
❯ python -c "import polars as pl; print(pl.Decimal(precision=None, scale=3))"
Decimal(precision=None, scale=3)
❯ uv pip install polars==1.34
...
❯ python -c "import polars as pl; print(pl.Decimal(precision=None, scale=3))" |
|
Ah my browser just refreshed and I see multiple new comments and that you all already figured this out as well and merged the PR, so we're all set. Thanks all! |
On construction the precision if set to None is shifted to 38, so the precision is always non-None.