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

Arr.get casts date and datetime columns to integers #7073

Closed
2 tasks done
lucazanna opened this issue Feb 21, 2023 · 0 comments · Fixed by #7094
Closed
2 tasks done

Arr.get casts date and datetime columns to integers #7073

lucazanna opened this issue Feb 21, 2023 · 0 comments · Fixed by #7094
Labels
bug Something isn't working python Related to Python Polars

Comments

@lucazanna
Copy link

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

Arr.get does not seem to keep the data type of the column.

Below an example

Reproducible example

import polars as pl
from datetime import datetime

df = pl.DataFrame({
    'date_col': [[datetime(2023,2,1).date(), datetime(2023,2,2).date()]],
    'datetime_col': [[datetime(2023,2,1), datetime(2023,2,2)]]
})

shape: (1, 2)
┌──────────────────────────┬─────────────────────────────────────┐
│ date_coldatetime_col                        │
│ ------                                 │
│ list[date]               ┆ list[datetime[μs]]                  │
╞══════════════════════════╪═════════════════════════════════════╡
│ [2023-02-01, 2023-02-02] ┆ [2023-02-01 00:00:00, 2023-02-02... │
└──────────────────────────┴─────────────────────────────────────┘

df.with_columns(
    pl.all().arr.get(1).suffix('_element_1')
)

shape: (1, 4)
┌──────────────┬─────────────────────────────────────┬────────────────────┬────────────────────────┐
│ date_coldatetime_coldate_col_element_1datetime_col_element_1 │
│ ------------                    │
│ list[date]   ┆ list[datetime[μs]]                  ┆ i32i64                    │
╞══════════════╪═════════════════════════════════════╪════════════════════╪════════════════════════╡
│ [2023-02-01, ┆ [2023-02-01 00:00:00, 2023-02-02... ┆ 193901675296000000000       │
│ 2023-02-02]  ┆                                     ┆                    ┆                        │
└──────────────┴─────────────────────────────────────┴────────────────────┴────────────────────────┘

Expected behavior

I can cast back the columns to date and datetime, but I would expect arr.get to not change the data type.

Your thoughts?

Installed versions

---Version info---
Polars: 0.16.7
Index type: UInt32
Platform: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
Python: 3.11.1 (main, Dec  7 2022, 01:11:44) [GCC 9.4.0]
---Optional dependencies---
pyarrow: 11.0.0
pandas: 1.5.2
numpy: 1.24.0
fsspec: <not installed>
connectorx: <not installed>
xlsx2csv: 0.8.1
deltalake: <not installed>
matplotlib: 3.6.2
@lucazanna lucazanna added bug Something isn't working python Related to Python Polars labels Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant