Skip to content

Commit

Permalink
fix: Fix struct reshape fast path
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 18, 2024
1 parent 26e4a53 commit 98e42cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 5 additions & 10 deletions crates/polars-core/src/series/ops/reshape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions py-polars/tests/unit/operations/namespaces/list/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}],
]
}

0 comments on commit 98e42cc

Please sign in to comment.