Skip to content

Commit 246c747

Browse files
authored
PERF: array_equivalent_object (#44832)
1 parent ecbdfd3 commit 246c747

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pandas/core/dtypes/missing.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,17 @@ def _array_equivalent_datetimelike(left, right):
479479
return np.array_equal(left.view("i8"), right.view("i8"))
480480

481481

482-
def _array_equivalent_object(left, right, strict_nan):
482+
def _array_equivalent_object(left: np.ndarray, right: np.ndarray, strict_nan: bool):
483483
if not strict_nan:
484484
# isna considers NaN and None to be equivalent.
485+
486+
if left.flags["F_CONTIGUOUS"] and right.flags["F_CONTIGUOUS"]:
487+
# we can improve performance by doing a copy-free ravel
488+
# e.g. in frame_methods.Equals.time_frame_nonunique_equal
489+
# if we transposed the frames
490+
left = left.ravel("K")
491+
right = right.ravel("K")
492+
485493
return lib.array_equivalent_object(
486494
ensure_object(left.ravel()), ensure_object(right.ravel())
487495
)
@@ -501,10 +509,7 @@ def _array_equivalent_object(left, right, strict_nan):
501509
if np.any(np.asarray(left_value != right_value)):
502510
return False
503511
except TypeError as err:
504-
if "Cannot compare tz-naive" in str(err):
505-
# tzawareness compat failure, see GH#28507
506-
return False
507-
elif "boolean value of NA is ambiguous" in str(err):
512+
if "boolean value of NA is ambiguous" in str(err):
508513
return False
509514
raise
510515
return True

0 commit comments

Comments
 (0)