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

fix(python): panic in list.concat with another column on empty DataFrame #17741

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/polars-ops/src/chunked_array/list/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn cast_rhs(
if !matches!(s.dtype(), DataType::List(_)) {
*s = s.cast(inner_type)?
}
if !matches!(s.dtype(), DataType::List(_)) && s.dtype() == inner_type {
if !matches!(s.dtype(), DataType::List(_)) && s.dtype() == inner_type && s.len() != 0 {
// coerce to list JIT
*s = s.reshape_list(&[-1, 1]).unwrap();
}
Expand Down
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)]))
Loading