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

from_dicts without strict=false can result in silent data loss with ragged data #18880

Open
2 tasks done
D3SL opened this issue Sep 24, 2024 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@D3SL
Copy link

D3SL commented Sep 24, 2024

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

dataloss=pl.from_dicts({'colname': [{'intrange': {'prefix': '555',
    'middle': '111',
    'SN_Range': {'start': '00000000', 'stop': '99999999'}}},
  {'intrange': {'prefix': '555',
    'middle': '777',
    'SN_Range': {'start': '00000000', 'stop': '29999999'}},
   'testflag': 'true'}]})

noloss=pl.from_dicts({'colname': [{'intrange': {'prefix': '555',
    'middle': '111',
    'SN_Range': {'start': '00000000', 'stop': '99999999'}}},
  {'intrange': {'prefix': '555',
    'middle': '777',
    'SN_Range': {'start': '00000000', 'stop': '29999999'}},
   'testflag': 'true'}]},strict=False)

Log output

N/A no errors are raised. Jupyter gives no log output of any kind actually.

Issue description

When calling pl.from_dicts() on ragged data, very common with JSON, polars can silently drop data if strict is not set to false.

Expected behavior

strict should be irrelevant here. The issue is not column dtype but number of fields in each row of a struct column. Silent data loss should simply never happen.

Installed versions

--------Version info---------
Polars:              1.7.1
Index type:          UInt32
Platform:            Windows-10-10.0.19045-SP0
Python:              3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:04:44) [MSC v.1940 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          <not installed>
connectorx           0.3.3
deltalake            <not installed>
fastexcel            <not installed>
fsspec               2024.6.1
gevent               <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                2.0.0
openpyxl             3.1.5
pandas               2.2.2
pyarrow              16.1.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           2.0.34
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           3.2.0

#also tested on:
--------Version info---------
Polars:              1.8.1
Index type:          UInt32
Platform:            Linux-3.10.0-1160.119.1.el7.x86_64-x86_64-with-glibc2.36
Python:              3.11.8 (main, Mar 12 2024, 11:52:02) [GCC 12.2.0]
----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         <not installed>
numpy                <not installed>
openpyxl             <not installed>
pandas               <not installed>
pyarrow              <not installed>
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@D3SL D3SL added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 24, 2024
@cmdlineluser
Copy link
Contributor

It can also be seen directly from DataFrame:

pl.DataFrame({"a": [{"x": 1}, {"x": 1, "y": 2}]})
# shape: (2, 1)
# ┌───────────┐
# │ a         │
# │ ---       │
# │ struct[1] │
# ╞═══════════╡
# │ {1}       │
# │ {1}       │
# └───────────┘

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