From 10112aa69bef02d5c249e0362ddb5cc0b9558645 Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Tue, 25 Jun 2024 18:08:27 +0000 Subject: [PATCH] fix monotonic API to include nan's --- python/cudf/cudf/core/column/column.py | 4 ++-- python/cudf/cudf/tests/test_monotonic.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index dfcdfbb9d91..5db6fd904a9 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -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 ) diff --git a/python/cudf/cudf/tests/test_monotonic.py b/python/cudf/cudf/tests/test_monotonic.py index 0896d91570e..790e84559a9 100644 --- a/python/cudf/cudf/tests/test_monotonic.py +++ b/python/cudf/cudf/tests/test_monotonic.py @@ -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"], ], @@ -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", [