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

Inconsistent element types when using to_physical on List(Datetime) vs Array(Datetime, ...) #19396

Open
2 tasks done
egorchakov opened this issue Oct 23, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@egorchakov
Copy link
Contributor

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

import polars as pl

series = pl.Series(values=[[datetime.now()]])  # noqa: DTZ005

for dtype in (pl.List(pl.Datetime), pl.Array(pl.Datetime, 1)):
    print(f"{dtype}: {series.cast(dtype).to_physical().to_list()}")  # noqa: T201

Log output

List(Datetime): [[1729688789716971]]
Array(Datetime, shape=(1,)): [[datetime.datetime(2024, 10, 23, 13, 6, 29, 716971)]]

Issue description

Calling to_physical on a Series(dtype=List(Datetime)) casts the inner elements to an integer type, which is not the case for a Series(dtype=Array(Datetime, ...)).

Technically this behaviour does match the doc, but the inconsistency does seem surprising.
image

Expected behavior

to_physical on container types produces the same inner element type regardless of container type.

Installed versions

--------Version info---------
Polars:              1.10.0
Index type:          UInt32
Platform:            macOS-14.4-arm64-arm-64bit
Python:              3.12.4 (main, Jul 25 2024, 22:11:22) [Clang 18.1.8 ]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          3.1.0
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               2024.10.0
gevent               <not installed>
great_tables         <not installed>
matplotlib           3.9.2
nest_asyncio         1.6.0
numpy                1.26.4
openpyxl             <not installed>
pandas               <not installed>
pyarrow              17.0.0
pydantic             2.9.2
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                2.5.0
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@egorchakov egorchakov added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Oct 23, 2024
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

No branches or pull requests

1 participant