File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -573,7 +573,7 @@ def maybe_booleans_to_slice(ndarray[uint8_t, ndim=1] mask):
573573
574574@ cython.wraparound (False )
575575@ cython.boundscheck (False )
576- def array_equivalent_object (ndarray left , ndarray right ) -> bool:
576+ def array_equivalent_object (ndarray left , ndarray right , strict = False ) -> bool:
577577 """
578578 Perform an element by element comparison on N-d object arrays
579579 taking into account nan positions.
@@ -599,14 +599,14 @@ def array_equivalent_object(ndarray left, ndarray right) -> bool:
599599 if x.shape != y.shape:
600600 return False
601601 if x.dtype == y.dtype == object :
602- if not array_equivalent_object(x, y):
602+ if not array_equivalent_object(x, y, strict ):
603603 return False
604604 else :
605605 # Circular import isn't great, but so it goes.
606606 # TODO: could use np.array_equal?
607607 from pandas.core.dtypes.missing import array_equivalent
608608
609- if not array_equivalent(x, y):
609+ if not array_equivalent(x, y, strict ):
610610 return False
611611
612612 elif PyArray_Check(x) or PyArray_Check(y):
Original file line number Diff line number Diff line change 4444)
4545from pandas .core .dtypes .inference import is_list_like
4646
47+ import pandas as pd
48+
4749if TYPE_CHECKING :
4850 from re import Pattern
4951
@@ -502,9 +504,15 @@ def _array_equivalent_object(
502504 mask = None
503505
504506 try :
507+ warnings .warn (
508+ "array_equivalent_object now uses strict=True for comparison. "
509+ "This may break code that relied on non-strict comparison." ,
510+ pd .errors .FutureWarning ,
511+ stacklevel = 2 ,
512+ )
505513 if mask is None :
506- return lib .array_equivalent_object (left , right )
507- if not lib .array_equivalent_object (left [~ mask ], right [~ mask ]):
514+ return lib .array_equivalent_object (left , right , strict = True )
515+ if not lib .array_equivalent_object (left [~ mask ], right [~ mask ], strict = True ):
508516 return False
509517 left_remaining = left [mask ]
510518 right_remaining = right [mask ]
Original file line number Diff line number Diff line change 11import numpy as np
22import pytest
33
4+ from pandas .core .dtypes .missing import _array_equivalent_object
5+
46import pandas as pd
57import pandas ._testing as tm
68
@@ -179,3 +181,8 @@ def test_fillna_fill_other(self, data):
179181 expected = pd .DataFrame ({"A" : data , "B" : [0.0 ] * len (result )})
180182
181183 tm .assert_frame_equal (result , expected )
184+
185+ def test_array_equivalent_object_strict_comparison (self ):
186+ arr1 = np .array ([1 , 2 , 3 ], dtype = "int32" )
187+ arr2 = np .array ([1 , 2 , 3 ], dtype = "int64" )
188+ assert not _array_equivalent_object (arr1 , arr2 , strict_nan = False )
You can’t perform that action at this time.
0 commit comments