feat: Use fixed-scale Decimals#24542
Merged
ritchie46 merged 18 commits intopola-rs:mainfrom Sep 19, 2025
Merged
Conversation
This was referenced Sep 19, 2025
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24542 +/- ##
==========================================
- Coverage 81.81% 81.74% -0.07%
==========================================
Files 1683 1684 +1
Lines 229051 229458 +407
Branches 2946 2952 +6
==========================================
+ Hits 187406 187581 +175
- Misses 40906 41134 +228
- Partials 739 743 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
522ff59 to
89356e5
Compare
ritchie46
approved these changes
Sep 19, 2025
2 tasks
evertlammerts
added a commit
to duckdb/duckdb-python
that referenced
this pull request
Oct 4, 2025
See #98 We have our own Polars IO plugin to create lazy polars dataframes. We try to push as many predicates down into DuckDB as we can, for which we try to map Polars expressions (including datatypes) to SQL expressions. To do this we depend on Polar's `Expr.meta.serialize`. None of this is very stable. Polars IO source plugins are marked `@unstable` and `Expr.meta.serialize` says "Serialization is not stable across Polars versions". In this case the problems seems to come from Polars requiring an explicit scale to be set for decimals ([this pr](pola-rs/polars#24542)). The serialized format seems to have changed into: ```json { "expr": { "Literal": { "Scalar": { "Decimal": [ 1, 38, // This now includes the scale 0 ] } } }, "dtype": { "Literal": { "Decimal": [ 38, // this was already there 0 ] } }, "options": "Strict" } ``` Interestingly, even if we explicitly set precision to e.g. 20, the relevant part of the serialized expression looks as follows: ```json { "expr": { "Literal": { "Scalar": { "Decimal": [ 1, 38, // Still 38? 0 ] } } }, "dtype": { "Literal": { "Decimal": [ 20, // This is correct 0 ] } }, "options": "Strict" } ``` This PR allows for both a 2 and 3 item list for decimals.
2 tasks
2 tasks
2 tasks
2 tasks
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With this PR decimals now always require an explicit scale, with the exception of
Series.str.to_decimaland Python constructors. The scale is now always fixed, even across arithmetic operations. When the inputs to an arithmetic operation have mixed scales the maximum scale is chosen. Precision is respected (and checked) when explicitly specified in casts, or from imported data sources, however any arithmetic operation immediately puts the precision to the maximum allowed (38). Conversions to Decimals round to the nearest value, breaking ties to even.Unlike other arithmetic in Polars (at least, today), Decimal arithmetic is checked by default, meaning you'll get errors on overflow, division by zero, etc.
Fixes #19784.
Fixes #24481.
Fixes #24387.
Fixes #24350.
Fixes #24345.
Fixes #24190.
Fixes #23896.
Fixes #23063.
Fixes #21947.
Fixes #21684.
Fixes #21537.
Fixes #20575.
Fixes #20556.
Fixes #20464.
Fixes #20013.
Fixes #19959.
Fixes #19756.
Fixes #19630.
Fixes #18662.
Fixes #17046.
Fixes #16690.
Fixes #15953.
Fixes #15154.
Fixes #15153.
Fixes #15037.
Fixes #13987.
Fixes #13572.
Fixes #11593.