Skip to content

Unexpected behaviour when casting time-zone aware datetime to date #22864

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

Open
2 tasks done
svengiegerich opened this issue May 21, 2025 · 0 comments · May be fixed by #22888
Open
2 tasks done

Unexpected behaviour when casting time-zone aware datetime to date #22864

svengiegerich opened this issue May 21, 2025 · 0 comments · May be fixed by #22888
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@svengiegerich
Copy link

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
from zoneinfo import ZoneInfo

import polars as pl

df = pl.DataFrame({"start": datetime(2021, 1, 1, tzinfo=ZoneInfo("Europe/Berlin"))})

# Correct date (2021-01-01)
print(df.select(pl.col("start").dt.date()).item())

# Incorrect date (2020-12-31)
print(df.select(pl.col("start").cast(pl.Date)).item())

Log output

2021-01-01
2020-12-31

Issue description

When casting a time-zone aware datetime column, the result differs from calling polars.Expr.dt.date().

Expected behavior

I would have expected that the time zone would be respected when casting—i.e., both operations return the same value.

Installed versions

--------Version info---------
Polars:              1.27.1
Index type:          UInt32
Platform:            macOS-15.4-arm64-arm-64bit
Python:              3.12.10 | packaged by conda-forge | (main, Apr 10 2025, 22:19:24) [Clang 18.1.8 ]
LTS CPU:             False

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                1.37.1
cloudpickle          3.1.1
connectorx           <not installed>
deltalake            <not installed>
fastexcel            0.13.0
fsspec               2025.3.2
gevent               <not installed>
google.auth          2.39.0
great_tables         <not installed>
matplotlib           3.10.1
numpy                1.26.4
openpyxl             <not installed>
pandas               2.2.3
polars_cloud         <not installed>
pyarrow              19.0.1
pydantic             2.11.3
pyiceberg            0.9.0
sqlalchemy           2.0.40
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>```

</details>
@svengiegerich svengiegerich added bug Something isn't working python Related to Python Polars needs triage Awaiting prioritization by a maintainer labels May 21, 2025
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.

1 participant