Skip to content

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

@svengiegerich

Description

@svengiegerich

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-lowPriority: lowblockedCannot be worked on due to external dependencies, or significant new internal features needed firstbugSomething isn't workingpythonRelated to Python Polars

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions