From d876991f6b27553289e0139f51a830f1c01f9778 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 21 Feb 2025 12:23:09 -0800 Subject: [PATCH 1/3] Short circuit Index.equal if compared Index isn't same type --- python/cudf/cudf/core/column/column.py | 2 +- python/cudf/cudf/core/index.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index 06dc4058115..67a0aa7a781 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -713,7 +713,7 @@ def all(self, skipna: bool = True) -> bool: # is empty. if self.null_count == self.size: return True - return self.reduce("all") + return bool(self.reduce("all")) def any(self, skipna: bool = True) -> bool: # Early exit for fast cases. diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index 8587bff2e32..b984079bf48 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -1273,7 +1273,7 @@ def is_unique(self) -> bool: @_performance_tracking def equals(self, other) -> bool: - if not isinstance(other, BaseIndex) or len(self) != len(other): + if not (isinstance(other, type(self)) and len(self) == len(other)): return False check_dtypes = False From a157b60167266e8828fb4f101a24fead5591f5d9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 21 Feb 2025 15:46:01 -0800 Subject: [PATCH 2/3] make exception for categorical --- python/cudf/cudf/core/index.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index b984079bf48..f52bd0697bf 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -1273,7 +1273,7 @@ def is_unique(self) -> bool: @_performance_tracking def equals(self, other) -> bool: - if not (isinstance(other, type(self)) and len(self) == len(other)): + if not isinstance(other, BaseIndex) or len(self) != len(other): return False check_dtypes = False @@ -1286,6 +1286,12 @@ def equals(self, other) -> bool: elif other_is_categorical and not self_is_categorical: self = self.astype(other.dtype) check_dtypes = True + elif ( + not self_is_categorical + and not other_is_categorical + and not isinstance(self, type(other)) + ): + return False try: return self._column.equals( From e8544f28bc33ba05447e4d128f4381261440ceda Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 21 Feb 2025 15:54:18 -0800 Subject: [PATCH 3/3] Add exception for RangeINdex --- python/cudf/cudf/core/index.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index f52bd0697bf..a77c4816450 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -1289,8 +1289,11 @@ def equals(self, other) -> bool: elif ( not self_is_categorical and not other_is_categorical + and not isinstance(other, RangeIndex) and not isinstance(self, type(other)) ): + # Can compare Index to CategoricalIndex or RangeIndex + # Other comparisons are invalid return False try: