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(rust): Qcut all nulls panics #18667

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion crates/polars-ops/src/series/ops/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ pub fn qcut(

if ca.null_count() == ca.len() {
// If we only have nulls we don't have any breakpoints.
return cut(&s, vec![], labels, left_closed, include_breaks);
return cut(
ritchie46 marked this conversation as resolved.
Show resolved Hide resolved
&s,
vec![],
None::<Vec<PlSmallStr>>,
left_closed,
include_breaks,
);
}

let f = |&p| {
Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/unit/operations/test_qcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ def test_qcut_full_null() -> None:
assert_series_equal(result, expected, categorical_as_str=True)


def test_qcut_full_null_with_labels() -> None:
s = pl.Series("a", [None, None, None, None])

result = s.qcut([0.25, 0.50], labels=["1", "2", "3"])

expected = pl.Series("a", [None, None, None, None], dtype=pl.Categorical)
assert_series_equal(result, expected, categorical_as_str=True)


def test_qcut_allow_duplicates() -> None:
s = pl.Series([1, 2, 2, 3])

Expand Down
Loading