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

Ignore NaN correctly in .quantile #17593

Merged
merged 1 commit into from
Dec 13, 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
7 changes: 4 additions & 3 deletions python/cudf/cudf/core/column/numerical_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ def quantile(
),
)
else:
no_nans = self.nans_to_nulls()
# get sorted indices and exclude nulls
indices = sorting.order_by(
[self], [True], "first", stable=True
).slice(self.null_count, len(self))
[no_nans], [True], "first", stable=True
).slice(no_nans.null_count, len(no_nans))
with acquire_spill_lock():
plc_column = plc.quantiles.quantile(
self.to_pylibcudf(mode="read"),
no_nans.to_pylibcudf(mode="read"),
q,
plc.types.Interpolation[interpolation.upper()],
indices.to_pylibcudf(mode="read"),
Expand Down
16 changes: 16 additions & 0 deletions python/cudf/cudf/tests/test_quantiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,19 @@ def test_quantile_type_int_float(interpolation):

assert expected == actual
assert type(expected) is type(actual)


@pytest.mark.parametrize(
"data",
[
[float("nan"), float("nan"), 0.9],
[float("nan"), float("nan"), float("nan")],
],
)
def test_ignore_nans(data):
psr = pd.Series(data)
gsr = cudf.Series(data, nan_as_null=False)

expected = gsr.quantile(0.9)
result = psr.quantile(0.9)
assert_eq(result, expected)
Loading