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 is_monotonic_* APIs to include nan's #16085

Merged
merged 2 commits into from
Jun 26, 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
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,13 +927,13 @@ def is_unique(self) -> bool:

@property
def is_monotonic_increasing(self) -> bool:
return not self.has_nulls() and libcudf.sort.is_sorted(
return not self.has_nulls(include_nan=True) and libcudf.sort.is_sorted(
[self], [True], None
)

@property
def is_monotonic_decreasing(self) -> bool:
return not self.has_nulls() and libcudf.sort.is_sorted(
return not self.has_nulls(include_nan=True) and libcudf.sort.is_sorted(
[self], [False], None
)

Expand Down
19 changes: 19 additions & 0 deletions python/cudf/cudf/tests/test_monotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ def test_range_index(testrange):
"testlist",
[
[1, 2, 3, 4],
[1, 2, 3, 4, None],
[1, 2, 3, 3, 4],
[10, 9, 8, 7],
[10, 9, 8, 8, 7],
["c", "d", "e", "f"],
["c", "d", "e", "e", "f"],
["c", "d", "e", "f", None],
["z", "y", "x", "r"],
["z", "y", "x", "x", "r"],
],
Expand All @@ -51,6 +53,23 @@ def test_generic_index(testlist):
assert index.is_monotonic_decreasing == index_pd.is_monotonic_decreasing


@pytest.mark.parametrize(
"testlist",
[
[1, 2, 3, 4, np.nan],
[10, 9, 8, np.nan, 7],
[10, 9, 8, 8, 7, np.nan],
],
)
def test_float_index(testlist):
index_pd = pd.Index(testlist)
index = cudf.from_pandas(index_pd, nan_as_null=False)

assert index.is_unique == index_pd.is_unique
assert index.is_monotonic_increasing == index_pd.is_monotonic_increasing
assert index.is_monotonic_decreasing == index_pd.is_monotonic_decreasing


@pytest.mark.parametrize(
"testlist",
[
Expand Down
Loading