Open
Description
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
>>> import polars as pl
>>> from pydantic import BaseModel
>>> from datetime import datetime, UTC
>>> class Test(BaseModel):
... start: datetime
... value: int
...
>>> test = Test(start=datetime(2024,12,12, tzinfo=UTC), value=2)
>>> pl.from_records([test])
shape: (1, 2)
┌─────────────────────┬───────┐
│ start ┆ value │
│ --- ┆ --- │
│ datetime[μs] ┆ i64 │
╞═════════════════════╪═══════╡
│ 2024-12-12 00:00:00 ┆ 2 │
└─────────────────────┴───────┘
>>> pl.from_dicts([test.dict()])
<stdin>:1: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.10/migration/
shape: (1, 2)
┌─────────────────────────┬───────┐
│ start ┆ value │
│ --- ┆ --- │
│ datetime[μs, UTC] ┆ i64 │
╞═════════════════════════╪═══════╡
│ 2024-12-12 00:00:00 UTC ┆ 2 │
└─────────────────────────┴───────┘
>>>
Log output
No response
Issue description
Thanks for the great library; here's another timezone related issue :)
Dropping timezone information on some constructor and not others yeilds confusing results.
I end up using from_dicts([r.dict() for r in records])
a lot because of this.
Expected behavior
The from_records
constructor should keep the timezone information of the records, the same behaviour that from_dicts
have.
Installed versions
>>> pl.show_versions()
--------Version info---------
Polars: 1.17.1
Index type: UInt32
Platform: macOS-15.1-arm64-arm-64bit
Python: 3.12.8 (main, Dec 3 2024, 18:42:41) [Clang 16.0.0 (clang-1600.0.26.4)]
LTS CPU: False
----Optional dependencies----
adbc_driver_manager <not installed>
altair <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 <not installed>
great_tables <not installed>
matplotlib <not installed>
nest_asyncio <not installed>
numpy <not installed>
openpyxl <not installed>
pandas <not installed>
pyarrow <not installed>
pydantic 2.10.3
pyiceberg <not installed>
sqlalchemy <not installed>
torch <not installed>
xlsx2csv <not installed>
xlsxwriter <not installed>
Metadata
Assignees
Type
Projects
Status
Ready