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

Short circuit Index.equal if compared Index isn't same type #18067

Merged
merged 5 commits into from
Feb 26, 2025
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
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,15 @@ 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(other, RangeIndex)
and not isinstance(self, type(other))
):
# Can compare Index to CategoricalIndex or RangeIndex
# Other comparisons are invalid
return False

try:
return self._column.equals(
Expand Down
Loading