Skip to content

Commit 57a6f44

Browse files
jbrockmendeljreback
authored andcommitted
PERF avoid object-dtype comparisons (#24792)
1 parent 02b5d9f commit 57a6f44

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pandas/core/internals/blocks.py

+6
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,12 @@ def setitem(self, indexer, value):
24652465
klass=ObjectBlock,)
24662466
return newb.setitem(indexer, value)
24672467

2468+
def equals(self, other):
2469+
# override for significant performance improvement
2470+
if self.dtype != other.dtype or self.shape != other.shape:
2471+
return False
2472+
return (self.values.view('i8') == other.values.view('i8')).all()
2473+
24682474

24692475
class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
24702476
__slots__ = ()

pandas/util/testing.py

+5
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,11 @@ def assert_extension_array_equal(left, right, check_dtype=True,
11991199
if check_dtype:
12001200
assert_attr_equal('dtype', left, right, obj='ExtensionArray')
12011201

1202+
if hasattr(left, "asi8") and type(right) == type(left):
1203+
# Avoid slow object-dtype comparisons
1204+
assert_numpy_array_equal(left.asi8, right.asi8)
1205+
return
1206+
12021207
left_na = np.asarray(left.isna())
12031208
right_na = np.asarray(right.isna())
12041209
assert_numpy_array_equal(left_na, right_na, obj='ExtensionArray NA mask')

0 commit comments

Comments
 (0)