Skip to content
Closed
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: 3 additions & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def maybe_booleans_to_slice(ndarray[uint8_t, ndim=1] mask):

@cython.wraparound(False)
@cython.boundscheck(False)
def array_equivalent_object(ndarray left, ndarray right) -> bool:
def array_equivalent_object(ndarray left, ndarray right, strict=False) -> bool:
"""
Perform an element by element comparison on N-d object arrays
taking into account nan positions.
Expand All @@ -599,14 +599,14 @@ def array_equivalent_object(ndarray left, ndarray right) -> bool:
if x.shape != y.shape:
return False
if x.dtype == y.dtype == object:
if not array_equivalent_object(x, y):
if not array_equivalent_object(x, y, strict):
return False
else:
# Circular import isn't great, but so it goes.
# TODO: could use np.array_equal?
from pandas.core.dtypes.missing import array_equivalent

if not array_equivalent(x, y):
if not array_equivalent(x, y, strict):
return False

elif PyArray_Check(x) or PyArray_Check(y):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ def _array_equivalent_object(

try:
if mask is None:
return lib.array_equivalent_object(left, right)
if not lib.array_equivalent_object(left[~mask], right[~mask]):
return lib.array_equivalent_object(left, right, strict=True)
if not lib.array_equivalent_object(left[~mask], right[~mask], strict=True):
return False
left_remaining = left[mask]
right_remaining = right[mask]
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/extension/base/missing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pytest

from pandas.core.dtypes.missing import _array_equivalent_object

import pandas as pd
import pandas._testing as tm

Expand Down Expand Up @@ -179,3 +181,8 @@ def test_fillna_fill_other(self, data):
expected = pd.DataFrame({"A": data, "B": [0.0] * len(result)})

tm.assert_frame_equal(result, expected)

def test_array_equivalent_object_strict_comparison(self):
arr1 = np.array([1, 2, 3], dtype="int32")
arr2 = np.array([1, 2, 3], dtype="int64")
assert not _array_equivalent_object(arr1, arr2, strict_nan=False)
Loading