Skip to content

PERF: avoid object-dtype comparisons #24792

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

Merged
merged 1 commit into from
Jan 16, 2019
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
6 changes: 6 additions & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,12 @@ def setitem(self, indexer, value):
klass=ObjectBlock,)
return newb.setitem(indexer, value)

def equals(self, other):
# override for significant performance improvement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would u do this here and not in array_equivalent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because array_equivalent's docstring specifically says it assumes it is dealing with numpy arrays

if self.dtype != other.dtype or self.shape != other.shape:
return False
return (self.values.view('i8') == other.values.view('i8')).all()


class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
__slots__ = ()
Expand Down
5 changes: 5 additions & 0 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,11 @@ def assert_extension_array_equal(left, right, check_dtype=True,
if check_dtype:
assert_attr_equal('dtype', left, right, obj='ExtensionArray')

if hasattr(left, "asi8") and type(right) == type(left):
# Avoid slow object-dtype comparisons
assert_numpy_array_equal(left.asi8, right.asi8)
return

left_na = np.asarray(left.isna())
right_na = np.asarray(right.isna())
assert_numpy_array_equal(left_na, right_na, obj='ExtensionArray NA mask')
Expand Down