feat: Improve support for Decimal DType#3377
Conversation
|
Regarding the stable API, how do we feel for this feature? I would say that keeping it backward compatible for v2 might be a stretch, but for v1 it would be ok. cc @MarcoGorelli |
|
thanks for your pr! i was under the impression that |
To save you a long read, there was nothing conclusive in that issue. On the Python-side, all that's changed is There are a lot more changes on the Rust-side (who would've guessed that?) I'm not pitching we do/don't do that - just trying to summarize the old-fashioned way 😉 |
narwhals/dtypes.py
Outdated
| def __init__(self, precision: int | None = None, scale: int = 0) -> None: | ||
| self.precision = 38 if precision is None else precision |
There was a problem hiding this comment.
not sure what i'm missing but why not
precision: int = 38
?
There was a problem hiding this comment.
I suppose if we got an old pl.Decimal, that could have a None already?
Otherwise - yeah if we can avoid introducing the contructor with a None - I'm on board 😄
There was a problem hiding this comment.
It's solely to mirror polars signature: polars.datatypes.Decimal and code
def __init__(
self,
precision: int | None = None,
scale: int = 0,
) -> None:
if precision is None:
precision = 38
self.precision = precision
self.scale = scale|
@MarcoGorelli thanks for reviewing this. I have a couple of questions that might need to be discussed before merging:
Example: import polars as pl
dtype = pl.Decimal(2, 3) # Ok so far
pl.Series([1.2]).cast(dtype)
> InvalidOperationError: scale must be less than or equal to precision |
|
RE: (#3377 (comment)), (#3377 (comment)) @MarcoGorelli did you mean to introduce it as stable in #1571? |
@FBruzzesi I agree, let's do that Note Sorry for blowing up CI with |
Spotted while reviewing #3377 Pretty sure there's more of these to be found
@FBruzzesi Initially I was thinking we should do the same thing for But the more I've read through your PR, I've started to think we might not need it?
Note Only Have I understood all of this correctly? |
seems fine, it should be stable in polars now
Sure sounds good (tbh i wouldn't have worried about standardising it, but no objections as you've already done it) |
|
Thanks both for reviewing 🙏🏼 @dangotbanned as mentioned in discord, I did some digging in the ibis code and settled on f98decc Let me know if you are happy with the state of this PR 😇 |

Description
Adds
precisionandscaleparameters toDecimaldtype.TODO: Decide on stable API
What type of PR is this? (check all applicable)
Related issues
precisionandscalekeywords forDecimaldtype FBruzzesi/anyschema#101Checklist