Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow duration multiplied w/ primitive to propagate in IR schema #21394

Merged
merged 1 commit into from
Feb 22, 2025

Conversation

mcrumiller
Copy link
Contributor

@mcrumiller mcrumiller commented Feb 21, 2025

Closes #21389.

Right now, duration * primitive does not propagate the dtype and results in a schema error if the resulting expression is used afterwards, despite it being a valid operation.

from datetime import datetime, timedelta
import polars as pl
from polars import col

df = pl.DataFrame({
    "ts": [datetime(2025, 1, 1)],
    "dur": [timedelta(days=1)],
})

df.select(col("dur") * 2)              # OK
df.select(2 * col("dur"))              # OK
df.select(col("ts") + col("dur"))      # OK
df.select(col("ts") + 2 * col("dur"))  # OK
df.select(col("ts") + col("dur") * 2)  # ERROR!!!
# polars.exceptions.InvalidOperationError: + not allowed on datetime[μs] and unknown

After fix:

>>> df.select(col("ts") + col("dur") * 2)
shape: (1, 1)
┌─────────────────────┐
│ ts                  │
│ ---                 │
│ datetime[μs]        │
╞═════════════════════╡
│ 2025-01-03 00:00:00 │
└─────────────────────┘

@github-actions github-actions bot added fix Bug fix rust Related to Rust Polars labels Feb 21, 2025
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 79.96%. Comparing base (3719977) to head (1780991).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-plan/src/plans/aexpr/schema.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21394      +/-   ##
==========================================
+ Coverage   79.89%   79.96%   +0.07%     
==========================================
  Files        1597     1597              
  Lines      228951   228954       +3     
  Branches     2618     2618              
==========================================
+ Hits       182915   183082     +167     
+ Misses      45437    45273     -164     
  Partials      599      599              

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

@ritchie46 ritchie46 changed the title fix(rust): Allow duration * primitive to propagate in IR fix: Allow duration * primitive to propagate in IR Feb 22, 2025
@github-actions github-actions bot added the python Related to Python Polars label Feb 22, 2025
@ritchie46 ritchie46 changed the title fix: Allow duration * primitive to propagate in IR fix: Allow duration multiplied w/ primitive to propagate in IR schema Feb 22, 2025
@ritchie46 ritchie46 merged commit 237b506 into pola-rs:main Feb 22, 2025
27 of 28 checks passed
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 rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow expressions of type datetime - duration * 2
2 participants