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

Panic when using Series.clear on nested Object types #16261

Open
2 tasks done
stinodego opened this issue May 16, 2024 · 0 comments
Open
2 tasks done

Panic when using Series.clear on nested Object types #16261

stinodego opened this issue May 16, 2024 · 0 comments
Labels
A-ops Area: operations A-panic Area: code that results in panic exceptions bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@stinodego
Copy link
Member

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

import polars as pl

s = pl.Series([[object()]], dtype=pl.List(pl.Object()))
s.clear()

Log output

thread '<unnamed>' panicked at /home/stijn/code/polars/crates/polars-core/src/named_from.rs:162:86:
called `Result::unwrap()` on an `Err` value: InvalidOperation(ErrString("`list_builder` operation not supported for dtype `object`"))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/home/stijn/code/polars/py-polars/repro.py", line 11, in <module>
    s = pl.Series([[object()]], dtype=pl.List(pl.Object()))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/series/series.py", line 314, in __init__
    self._s = sequence_to_pyseries(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/_utils/construction/series.py", line 277, in sequence_to_pyseries
    pyseries = PySeries.new_series_list(name, pyseries_list, strict)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: InvalidOperation(ErrString("`list_builder` operation not supported for dtype `object`"))

Issue description

Offending code is here:

pub fn clear(&self) -> Series {
if self.is_empty() {
self.clone()
} else {
match self.dtype() {
#[cfg(feature = "object")]
DataType::Object(_, _) => self
.take(&ChunkedArray::<IdxType>::new_vec("", vec![]))
.unwrap(),
dt => Series::new_empty(self.name(), dt),
}
}
}

Clearly this doesn't account for nested object types.

Expected behavior

Return an empty Series.

Installed versions

main

@stinodego stinodego added bug Something isn't working python Related to Python Polars needs triage Awaiting prioritization by a maintainer P-low Priority: low A-ops Area: operations A-panic Area: code that results in panic exceptions and removed needs triage Awaiting prioritization by a maintainer labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ops Area: operations A-panic Area: code that results in panic exceptions bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
Status: Ready
Development

No branches or pull requests

1 participant