feat: Disallow casting temporal to numeric#3430
Conversation
| @@ -171,6 +171,15 @@ def cast(self, dtype: IntoDType) -> Self: | |||
| Arguments: | |||
| dtype: Data type that the object will be cast into. | |||
|
|
|||
| Note: | |||
| Unlike polars, we don't allow to cast from a temporal to a numeric data type. | |||
There was a problem hiding this comment.
TIL: polars allows also casting to Float, not only to Integer
|
Test was failing due to |
|
@FBruzzesi I know this PR isn't active, but I've been reading through I think this would be pretty painful for them here: In short, they kinda need to be able to do this because |
|
Hey @dangotbanned - which particular bit concerns you? The only cast to numeric in such file are from either decimal or types that are already numerical |
wow 🤦♂️ wow 🤦♂️ wow 🤦♂️ Sorry @FBruzzesi false alarm, JS is rubbing off on me: Contextnarwhals/src/narwhals/_plan/altair/expression.py Lines 302 to 318 in a5c38b7 The right-hand-side are vega expressions,. My mistakeSo I connected the wrong dot here: if dtype == nw.Time:
# Convert to timestamp in ms
col_in_ms = (
col.dt.hour().cast(nw.Int64) * 3600000
# ^^^^Maybe they did too? |
Description
It aligns with the decision of not following polars in supertyping between temporal and numeric in #3396.
Questions/Observations:
What should we do in the case of a polars expr?
Let me know if we want to keep stable also V2, or none at all and do the check for all versions
For lazy backends, you will see an "extra"
dtype.is_numeric(), this is to avoid having to trigger acollect_schema()if there is no need for itWhat type of PR is this? (check all applicable)
Related issues
Checklist