Skip to content

Conversation

@wtn
Copy link
Contributor

@wtn wtn commented Nov 24, 2025

Fixes #11991.

Calling .dt.year() or other temporal operations on out-of-range dates silently returned the original integer value instead of raising an error.

Cause

The to_temporal_unit! and to_calendar_value! macros used unary() which processes all values including nulls. The .unwrap_or() fallback (from #10114) correctly prevented panics on null values backed by out-of-range integers, but also incorrectly returned the original value for actually out-of-range non-null dates.

Fix

Follow the pattern from PR #15420: replace unary() with from_trusted_len_iter() and .iter().map(). This handles both cases:

  • Null values with out-of-range backing data remain null (no panic)
  • Non-null out-of-range values panic with "out-of-range date" error

@github-actions github-actions bot added fix Bug fix rust Related to Rust Polars labels Nov 24, 2025
@wtn wtn force-pushed the year branch 4 times, most recently from 2af32bb to e7e7483 Compare November 24, 2025 02:02
@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.06%. Comparing base (0eec829) to head (62f70b9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #25471   +/-   ##
=======================================
  Coverage   82.05%   82.06%           
=======================================
  Files        1730     1730           
  Lines      241110   241101    -9     
  Branches     3032     3032           
=======================================
+ Hits       197841   197852   +11     
+ Misses      42487    42467   -20     
  Partials      782      782           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wtn wtn force-pushed the year branch 2 times, most recently from 2e52418 to 7f2015b Compare November 24, 2025 23:48
@wtn wtn marked this pull request as ready for review November 24, 2025 23:50
@wtn wtn force-pushed the year branch 2 times, most recently from 48cac54 to 62f70b9 Compare November 27, 2025 04:54
@wtn wtn marked this pull request as draft November 27, 2025 21:39
Change `to_temporal_unit!`, `to_calendar_value!`, and
`to_boolean_temporal_unit!` macros to return null for out-of-range dates
instead of silently returning incorrect values.

Co-authored-by: Claude <noreply@anthropic.com>
@wtn wtn marked this pull request as ready for review November 27, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix rust Related to Rust Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.dt.year may silently throw wrong results

2 participants