Skip to content

Commit

Permalink
fix: Panic in pl.concat_list and list.concat on empty inputs (#17742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Object905 authored Jul 20, 2024
1 parent 4695c4c commit 1df3b0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-core/src/series/ops/reshape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Series {
let mut cols = dimensions[1];

if s_ref.len() == 0_usize {
if (rows == -1 || rows == 0) && (cols == -1 || cols == 0) {
if (rows == -1 || rows == 0) && (cols == -1 || cols == 0 || cols == 1) {
let s = reshape_fast_path(s.name(), s_ref);
return Ok(s);
} else {
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/functions/as_datatype/test_concat_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,13 @@ def test_concat_list_reverse_struct_fields() -> None:
result1 = df.select(pl.concat_list(["combo", "reverse_combo"]))
result2 = df.select(pl.concat_list(["combo", "combo"]))
assert_frame_equal(result1, result2)


def test_concat_list_empty() -> None:
df = pl.DataFrame({"a": []})
df.select(pl.concat_list("a"))


def test_concat_list_empty_struct() -> None:
df = pl.DataFrame({"a": []}, schema={"a": pl.Struct({"b": pl.Boolean})})
df.select(pl.concat_list("a"))
5 changes: 5 additions & 0 deletions py-polars/tests/unit/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@ def test_empty_shift_over_16676() -> None:
def test_empty_list_cat_16405() -> None:
df = pl.DataFrame(schema={"cat": pl.List(pl.Categorical)})
df.select(pl.col("cat") == pl.col("cat"))


def test_empty_list_concat_16924() -> None:
df = pl.DataFrame(schema={"a": pl.Int16, "b": pl.List(pl.String)})
df.with_columns(pl.col("b").list.concat([pl.col("a").cast(pl.String)]))

0 comments on commit 1df3b0b

Please sign in to comment.