Skip to content

feat: Disallow casting temporal to numeric#3430

Open
FBruzzesi wants to merge 5 commits intomainfrom
feat/disallow-temporal-to-int
Open

feat: Disallow casting temporal to numeric#3430
FBruzzesi wants to merge 5 commits intomainfrom
feat/disallow-temporal-to-int

Conversation

@FBruzzesi
Copy link
Member

@FBruzzesi FBruzzesi commented Jan 31, 2026

Description

It aligns with the decision of not following polars in supertyping between temporal and numeric in #3396.

Questions/Observations:

  1. What should we do in the case of a polars expr?
  2. Let me know if we want to keep stable also V2, or none at all and do the check for all versions
  3. For lazy backends, you will see an "extra" dtype.is_numeric(), this is to avoid having to trigger a collect_schema() if there is no need for it

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

@FBruzzesi FBruzzesi added enhancement New feature or request error reporting labels Jan 31, 2026
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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: polars allows also casting to Float, not only to Integer

@FBruzzesi
Copy link
Member Author

FBruzzesi commented Jan 31, 2026

CI failure is unrelated?!

Test was failing due to collect_schema in sqlframe with null only, hence the type is not defined. Because of this, you will see a suppress(Exception) context

@FBruzzesi FBruzzesi marked this pull request as ready for review January 31, 2026 18:06
Comment on lines +254 to +262
schema: dict[str, DType] = {}
with suppress(Exception):
schema = df.collect_schema()

if schema:
for name in self._evaluate_output_names(df):
_validate_cast_temporal_to_numeric(
source=schema[name], target=dtype
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not particularly proud of this piece of code 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request error reporting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

disallow casting temporal to integer

1 participant