Skip to content

Commit

Permalink
Ignore NaN correctly in .quantile
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Dec 13, 2024
1 parent 1a67646 commit b2e5863
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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)

0 comments on commit b2e5863

Please sign in to comment.