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

Exploding list of structs fails in some cases #5673

Closed
2 tasks done
indigoviolet opened this issue Nov 29, 2022 · 1 comment · Fixed by #5690
Closed
2 tasks done

Exploding list of structs fails in some cases #5673

indigoviolet opened this issue Nov 29, 2022 · 1 comment · Fixed by #5690
Labels
bug Something isn't working python Related to Python Polars

Comments

@indigoviolet
Copy link

indigoviolet commented Nov 29, 2022

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

Exploding a series of List[struct] containing a list field fails in some situations, in an order-dependent fashion. It is also unclear why a list[struct] would explode to a null-struct (see below)

Reproducible example

import polars as pr
pr.Series(
    [[], [{"b": []}, {"b": ["foo"]}]],
    dtype=pr.List(pr.Struct({"b": pr.List(pr.Utf8)})),
).explode()
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: OutOfSpec("validity mask length must match the number of values")', /root/.cargo/git/checkouts/arrow2-8a2ad61d97265680/368aacc/src/array/list/mod.rs:202:71

Why does the [] row explode to {null}?

import polars as pr
pr.Series(
    [[{"b": []}, {"b": ["foo"]}], []`],
    dtype=pr.List(pr.Struct({"b": pr.List(pr.Utf8)})),
).explode()

pr.Series(
    [[{"b": []}, {"b": ["foo"]}], []],
    dtype=pr.List(pr.Struct({"b": pr.List(pr.Utf8)})),
).explode()
Out [230]:
shape: (3,)
Series: '' [struct[1]]
[
	{[]}
	{["foo"]}
	{null}
]

Expected behavior

I would expect the explode() to work, and for [] to explode to no rows

Installed versions

---Version info---
Polars: 0.15.1
Index type: UInt32
Platform: Linux-4.19.0-22-cloud-amd64-x86_64-with-glibc2.10
Python: 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10) 
[GCC 10.3.0]
---Optional dependencies---
pyarrow: 7.0.1
pandas: 1.5.1
numpy: 1.23.4
fsspec: 2022.10.0
connectorx: <not installed>
xlsx2csv: <not installed>
matplotlib: 3.6.2


@indigoviolet indigoviolet added bug Something isn't working python Related to Python Polars labels Nov 29, 2022
@ritchie46
Copy link
Member

Thanks, will take a look. BTW could you use pl instead of pr? That's how we use it in every example and it really saves me a lot of muscle memory rewiring.

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.

2 participants