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

feat(rust, python): Support zero fill null strategy for binary and string columns #13869

Merged
merged 4 commits into from
Jan 20, 2024
Merged
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
1 change: 1 addition & 0 deletions crates/polars-core/src/chunked_array/ops/fill_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ fn fill_null_binary(ca: &BinaryChunked, strategy: FillNullStrategy) -> PolarsRes
FillNullStrategy::Max => {
ca.fill_null_with_values(ca.max_binary().ok_or_else(err_fill_null)?)
},
FillNullStrategy::Zero => ca.fill_null_with_values(&[]),
strat => polars_bail!(InvalidOperation: "fill-null strategy {:?} is not supported", strat),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ def test_sum_max_min() -> None:
assert_series_equal(out["min"], pl.Series("min", [1.0, 2.0, 3.0]))


def test_str_sum_horizontal() -> None:
df = pl.DataFrame(
{"A": ["a", "b", None, "c", None], "B": ["f", "g", "h", None, None]}
)
out = df.select(pl.sum_horizontal("A", "B"))
assert_series_equal(out["A"], pl.Series("A", ["af", "bg", "h", "c", ""]))


def test_cum_sum_horizontal() -> None:
df = pl.DataFrame(
{
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,16 @@ def test_fill_null() -> None:
b = pl.Series("b", ["a", None, "c", None, "e"])
assert b.fill_null(strategy="min").to_list() == ["a", "a", "c", "a", "e"]
assert b.fill_null(strategy="max").to_list() == ["a", "e", "c", "e", "e"]
assert b.fill_null(strategy="zero").to_list() == ["a", "", "c", "", "e"]
assert b.fill_null(strategy="forward").to_list() == ["a", "a", "c", "c", "e"]
assert b.fill_null(strategy="backward").to_list() == ["a", "c", "c", "e", "e"]

c = pl.Series("c", [b"a", None, b"c", None, b"e"])
assert c.fill_null(strategy="min").to_list() == [b"a", b"a", b"c", b"a", b"e"]
assert c.fill_null(strategy="max").to_list() == [b"a", b"e", b"c", b"e", b"e"]
assert c.fill_null(strategy="zero").to_list() == [b"a", b"", b"c", b"", b"e"]
assert c.fill_null(strategy="forward").to_list() == [b"a", b"a", b"c", b"c", b"e"]
assert c.fill_null(strategy="backward").to_list() == [b"a", b"c", b"c", b"e", b"e"]

df = pl.DataFrame(
[
Expand Down