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 on creating nested Array with logical inner dtype with nulls #16210

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

Panic on creating nested Array with logical inner dtype with nulls #16210

stinodego opened this issue May 14, 2024 · 0 comments
Labels
A-dtype-list/array Area: list/array data type A-input-parsing Area: parsing input arguments A-panic Area: code that results in panic exceptions bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@stinodego
Copy link
Member

stinodego commented May 14, 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

import polars as pl

dtype = pl.Array(pl.Array(pl.Datetime, width=2), width=2)
s = pl.Series([[None, None]], dtype=dtype)

print(s)

Log output

thread '<unnamed>' panicked at crates/polars-arrow/src/array/list/mod.rs:82:61:
called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("ListArray's child's DataType must match. However, the expected DataType is FixedSizeList(Field { name: \"item\", data_type: Int64, is_nullable: true, metadata: {} }, 2) while it got FixedSizeList(Field { name: \"item\", data_type: Timestamp(Microsecond, None), is_nullable: true, metadata: {} }, 2)."))
stack backtrace:
   0: rust_begin_unwind
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/result.rs:1654:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/result.rs:1077:23
   4: polars_arrow::array::list::ListArray<O>::new
             at /home/stijn/code/polars/crates/polars-arrow/src/array/list/mod.rs:82:9
   5: polars_arrow::legacy::array::list::AnonymousBuilder::finish
             at /home/stijn/code/polars/crates/polars-arrow/src/legacy/array/list.rs:158:12
   6: <polars_core::chunked_array::builder::list::anonymous::AnonymousOwnedListBuilder as polars_core::chunked_array::builder::list::ListBuilderTrait>::finish
             at /home/stijn/code/polars/crates/polars-core/src/chunked_array/builder/list/anonymous.rs:161:19
   7: <alloc::boxed::Box<S> as polars_core::chunked_array::builder::list::ListBuilderTrait>::finish
             at /home/stijn/code/polars/crates/polars-core/src/chunked_array/builder/list/mod.rs:81:9
   8: <polars_core::series::Series as polars_core::named_from::NamedFrom<T,[core::option::Option<polars_core::series::Series>]>>::new
             at /home/stijn/code/polars/crates/polars-core/src/named_from.rs:166:9
   9: polars::series::construction::<impl polars::series::PySeries>::new_series_list
             at ./src/series/construction.rs:288:9
  10: polars::series::construction::<impl polars::series::PySeries>::__pymethod_new_series_list__
             at ./src/series/construction.rs:183:1
  11: pyo3::impl_::trampoline::cfunction_with_keywords::{{closure}}
             at /home/stijn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:45:29
  12: pyo3::impl_::trampoline::trampoline::{{closure}}
             at /home/stijn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:187:54
  13: std::panicking::try::do_call
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panicking.rs:552:40
  14: __rust_try
  15: std::panicking::try
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panicking.rs:516:19
  16: std::panic::catch_unwind
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panic.rs:149:14
  17: pyo3::impl_::trampoline::trampoline
             at /home/stijn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:187:9
  18: pyo3::impl_::trampoline::cfunction_with_keywords
             at /home/stijn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:45:13
  19: polars::series::construction::_::__INVENTORY::trampoline
             at ./src/series/construction.rs:183:1
  20: cfunction_call
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Objects/methodobject.c:537:18
  21: _PyObject_MakeTpCall
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Objects/call.c:240:18
  22: _PyEval_EvalFrameDefault
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/bytecodes.c:2706:19
  23: _PyObject_FastCallDictTstate
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Objects/call.c:144:15
  24: _PyObject_Call_Prepend
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Objects/call.c:508:24
  25: slot_tp_init
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Objects/typeobject.c:9013:15
  26: type_call
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Objects/typeobject.c:1673:19
  27: _PyObject_MakeTpCall
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Objects/call.c:240:18
  28: _PyEval_EvalFrameDefault
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/bytecodes.c:2706:19
  29: _PyEval_EvalFrame
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/./Include/internal/pycore_ceval.h:89:16
  30: _PyEval_Vector
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/ceval.c:1683:12
  31: PyEval_EvalCode
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/ceval.c:578:21
  32: run_eval_code_obj
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/pythonrun.c:1722:9
  33: run_mod
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/pythonrun.c:1743:19
  34: pyrun_file
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/pythonrun.c:1643:15
  35: _PyRun_SimpleFileObject
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/pythonrun.c:433:13
  36: _PyRun_AnyFileObject
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Python/pythonrun.c:78:15
  37: pymain_run_file_obj
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Modules/main.c:360:15
  38: pymain_run_file
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Modules/main.c:379:15
  39: pymain_run_python
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Modules/main.c:629:21
  40: Py_RunMain
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Modules/main.c:709:5
  41: pymain_main
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Modules/main.c:739:12
  42: Py_BytesMain
             at /tmp/python-build.20240306124936.4980/Python-3.12.2/Modules/main.c:763:12
  43: <unknown>
  44: __libc_start_main
  45: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Traceback (most recent call last):
  File "/home/stijn/code/polars/py-polars/repro.py", line 4, in <module>
    s = pl.Series([[None, None]], dtype=dtype)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  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: ComputeError(ErrString("ListArray's child's DataType must match. However, the expected DataType is FixedSizeList(Field { name: \"item\", data_type: Int64, is_nullable: true, metadata: {} }, 2) while it got FixedSizeList(Field { name: \"item\", data_type: Timestamp(Microsecond, None), is_nullable: true, metadata: {} }, 2)."))

Issue description

It seems like the nulls in the nested array cause this panic. It thinks the first value has inner type Int64, while the second one has Timestamp.

Expected behavior

A new Series should be created.

Installed versions

main

@stinodego stinodego added bug Something isn't working python Related to Python Polars P-medium Priority: medium A-input-parsing Area: parsing input arguments A-dtype-list/array Area: list/array data type A-panic Area: code that results in panic exceptions labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dtype-list/array Area: list/array data type A-input-parsing Area: parsing input arguments A-panic Area: code that results in panic exceptions bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Status: Ready
Development

No branches or pull requests

1 participant