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

Allow expressions of type datetime - duration * 2 #21389

Closed
2 tasks done
sebasv opened this issue Feb 21, 2025 · 1 comment · Fixed by #21394
Closed
2 tasks done

Allow expressions of type datetime - duration * 2 #21389

sebasv opened this issue Feb 21, 2025 · 1 comment · Fixed by #21394
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@sebasv
Copy link

sebasv commented Feb 21, 2025

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

from datetime import datetime, timedelta
import polars as pl

df =pl.DataFrame({"ts": datetime(2024,1,1,1,2,3), "duration": timedelta(days=1)})

# 1
df.select(pl.col("duration")*2) # -> type is duration

# 2
df.select(pl.col("ts")-pl.col("duration")*2) # -> InvalidOperationError, type of `pl.col("duration")*2` is unknown

# 3
df.with_columns(duration2=pl.col("duration")*2).select(pl.col("ts")-pl.col("duration2")) # -> Type is duration

Log output

Issue description

I would expect #2 to work and produce the same output as #3, but instead I get an Exception

Expected behavior

No exception thrown

Installed versions

<not installed>
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
google.auth          2.36.0
great_tables         <not installed>
matplotlib           <not installed>
numpy                1.26.4
openpyxl             <not installed>
pandas               2.2.3
pyarrow              13.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@sebasv sebasv added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Feb 21, 2025
@mcrumiller
Copy link
Contributor

To get around this right now, you can swap the order of your operands:

df.select(pl.col("ts") - pl.col("duration") * 2)  # error
df.select(pl.col("ts") - 2 * pl.col("duration"))  # works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants