From 98e42ccc9194ed03de8a2b104167faa63fc49fcd Mon Sep 17 00:00:00 2001 From: ritchie Date: Fri, 18 Oct 2024 10:27:28 +0200 Subject: [PATCH] fix: Fix struct reshape fast path --- crates/polars-core/src/series/ops/reshape.rs | 15 +++++---------- .../unit/operations/namespaces/list/test_list.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/polars-core/src/series/ops/reshape.rs b/crates/polars-core/src/series/ops/reshape.rs index 642faafbfdf8..3bf4898c5bc7 100644 --- a/crates/polars-core/src/series/ops/reshape.rs +++ b/crates/polars-core/src/series/ops/reshape.rs @@ -12,16 +12,11 @@ use crate::datatypes::{DataType, ListChunked}; use crate::prelude::{IntoSeries, Series, *}; fn reshape_fast_path(name: PlSmallStr, s: &Series) -> Series { - let mut ca = match s.dtype() { - #[cfg(feature = "dtype-struct")] - DataType::Struct(_) => { - ListChunked::with_chunk(name, array_to_unit_list(s.array_ref(0).clone())) - }, - _ => ListChunked::from_chunk_iter( - name, - s.chunks().iter().map(|arr| array_to_unit_list(arr.clone())), - ), - }; + let mut ca = ListChunked::from_chunk_iter( + name, + s.chunks().iter().map(|arr| array_to_unit_list(arr.clone())), + ); + ca.set_inner_dtype(s.dtype().clone()); ca.set_fast_explode(); ca.into_series() diff --git a/py-polars/tests/unit/operations/namespaces/list/test_list.py b/py-polars/tests/unit/operations/namespaces/list/test_list.py index 966fee3ea5ac..dfe6adad08d0 100644 --- a/py-polars/tests/unit/operations/namespaces/list/test_list.py +++ b/py-polars/tests/unit/operations/namespaces/list/test_list.py @@ -885,3 +885,18 @@ def test_list_get_with_null() -> None: def test_list_sum_bool_schema() -> None: q = pl.LazyFrame({"x": [[True, True, False]]}) assert q.select(pl.col("x").list.sum()).collect_schema()["x"] == pl.UInt32 + + +def test_list_concat_struct_19279() -> None: + df = pl.select( + pl.struct(s=pl.lit("abcd").str.split("").explode(), i=pl.int_range(0, 4)) + ) + df = pl.concat([df[:2], df[-2:]]) + assert df.select(pl.concat_list("s")).to_dict(as_series=False) == { + "s": [ + [{"s": "a", "i": 0}], + [{"s": "b", "i": 1}], + [{"s": "c", "i": 2}], + [{"s": "d", "i": 3}], + ] + }