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

Empty struct's value change since version 1.3.0 when calling to_dicts #19147

Closed
2 tasks done
HistoireDeBabar opened this issue Oct 8, 2024 · 1 comment
Closed
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@HistoireDeBabar
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

This is the current behaviour (>= 1.5.0):

import polars as pl
pl.__version__
# '1.9.0' (happens on from 1.5.0 onwards. 1.3.0 works (see below)

df = pl.DataFrame([{'empty': {}}])
df.to_dicts()
# [{'empty': None}]

df.schema
#  Schema([('empty', Struct({'': Null}))])

However in previous versions the following happened:

import polars as pl
pl.__version__
# '1.3.0' 

df = pl.DataFrame([{'empty': {}}])
df.to_dicts()
# [{'empty': {'': None}}]

df.schema
#  Schema([('empty', Struct({'': Null}))])

Log output

No response

Issue description

Hello,

I've came across an issue when converting a data frame with nested data, to a dictionary. This behaviour has changed since 1.3.0. I can't find any reference to the updates in the release notes (so I think it's unintentional).

I'm curious if the change in behaviour is deliberate, and the context around the change.

Expected behavior

Ideally, I think calling to_dicts should return an empty dict in this case.

import polars as pl

df = pl.DataFrame([{'empty': {}}])
df.to_dicts()
# [{'empty': {}}]

Installed versions

--------Version info---------
Polars:              1.9.0
Index type:          UInt32
Platform:            macOS-14.7-arm64-arm-64bit
Python:              3.9.12 (main, May 20 2022, 16:50:25) 
[Clang 13.1.6 (clang-1316.0.21.2.3)]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                1.26.4
openpyxl             <not installed>
pandas               <not installed>
pyarrow              17.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>```

</details>
@HistoireDeBabar HistoireDeBabar added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Oct 8, 2024
@ritchie46
Copy link
Member

Both were wrong. This is now fixed in #19123

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

2 participants