Skip to content

Commit

Permalink
fix: fix seg fault in concat_str of empty series (#11704)
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa authored Oct 13, 2023
1 parent d12dadb commit 7134442
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/polars-ops/src/chunked_array/strings/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ pub fn hor_str_concat(cas: &[&Utf8Chunked], delimiter: &str) -> PolarsResult<Utf
ComputeError: "all series in `hor_str_concat` should have equal or unit length"
);

let has_empty_ca = cas.iter().any(|ca| ca.is_empty());
if has_empty_ca {
return Ok(Utf8Chunked::full_null(cas[0].name(), 0));
}

// Calculate total capacity needed.
let tot_strings_bytes: usize = cas
.iter()
Expand Down
7 changes: 7 additions & 0 deletions py-polars/tests/unit/functions/test_concat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

import polars as pl
from polars.testing import assert_frame_equal


@pytest.mark.slow()
Expand All @@ -20,3 +21,9 @@ def test_concat_lf_stack_overflow() -> None:
for i in range(n):
bar = pl.concat([bar, pl.DataFrame({"a": i}).lazy()])
assert bar.collect().shape == (1001, 1)


def test_empty_df_concat_str_11701() -> None:
df = pl.DataFrame({"a": []})
out = df.select(pl.concat_str([pl.col("a").cast(pl.Utf8), pl.lit("x")]))
assert_frame_equal(out, pl.DataFrame({"a": []}, schema={"a": pl.Utf8}))

0 comments on commit 7134442

Please sign in to comment.