Skip to content

fix(python): Preserve Duration type in timedelta multiplication#26438

Open
Zakir032002 wants to merge 2 commits intopola-rs:mainfrom
Zakir032002:fix-temporal-float-arithmetic
Open

fix(python): Preserve Duration type in timedelta multiplication#26438
Zakir032002 wants to merge 2 commits intopola-rs:mainfrom
Zakir032002:fix-temporal-float-arithmetic

Conversation

@Zakir032002
Copy link

Handle timedelta multiplication in both mul and rmul to preserve
Duration type instead of silently casting to float. This fixes
datetime/float encoding round-trips commonly used in time-series analysis.

Changes:

  • Added explicit timedelta handling in Series.mul() before the
    _arithmetic fallback
  • Added explicit timedelta handling in Series.rmul() for reverse
    multiplication
  • Both paths use F.lit(timedelta) to preserve temporal type information
    via the expression engine

Fixes #26205

  1. I used AI assistance to help analyze the root cause .
  2. I have reviewed all changes myself and confirm they are correct,
    minimal, and consistent with the existing codebase.

Handle timedelta multiplication in both __mul__ and __rmul__ to preserve
Duration type instead of casting to float. Fixes datetime/float encoding
round-trips for time series analysis.

Changes:
- Added timedelta check in Series.__mul__() before _arithmetic fallback
- Added timedelta check in Series.__rmul__() for reverse multiplication
- Both use F.lit(timedelta) to preserve type information via expression engine

Fixes pola-rs#26205
@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Feb 5, 2026
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.00%. Comparing base (32dbe12) to head (74cc774).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
py-polars/src/polars/series/series.py 0.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #26438      +/-   ##
==========================================
- Coverage   81.02%   81.00%   -0.02%     
==========================================
  Files        1782     1782              
  Lines      243116   243120       +4     
  Branches     3078     3080       +2     
==========================================
- Hits       196980   196940      -40     
- Misses      45333    45375      +42     
- Partials      803      805       +2     

☔ 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.

Copy link
Member

@orlp orlp left a comment

Choose a reason for hiding this comment

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

I don't think this should be fixed by adding a hack in the Python code. Can you trace where the current multiplication implementation goes and fix it there?

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

Labels

fix Bug fix python Related to Python Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arithmetic broken with temporal and float types

2 participants

Comments