def array_equivalent(*args, **kwargs): warnings.warn( "'pandas.core.common.array_equivalent' is deprecated and " "is no longer public API", DeprecationWarning, stacklevel=2) from pandas.types import missing return missing.array_equivalent(*args, **kwargs)
def equals(self, other): """ Determines if two Index objects contain the same elements. """ if self.is_(other): return True return array_equivalent(_values_from_object(self), _values_from_object(other))
def equals(self, other): """ Determines if two CategorialIndex objects contain the same elements. """ if self.is_(other): return True try: other = self._is_dtype_compat(other) return array_equivalent(self._data, other) except (TypeError, ValueError): pass return False
def test_array_equivalent_compat(): # see gh-13388 m = np.array([(1, 2), (3, 4)], dtype=[('a', int), ('b', float)]) n = np.array([(1, 2), (3, 4)], dtype=[('a', int), ('b', float)]) assert (array_equivalent(m, n, strict_nan=True)) assert (array_equivalent(m, n, strict_nan=False)) m = np.array([(1, 2), (3, 4)], dtype=[('a', int), ('b', float)]) n = np.array([(1, 2), (4, 3)], dtype=[('a', int), ('b', float)]) assert (not array_equivalent(m, n, strict_nan=True)) assert (not array_equivalent(m, n, strict_nan=False)) m = np.array([(1, 2), (3, 4)], dtype=[('a', int), ('b', float)]) n = np.array([(1, 2), (3, 4)], dtype=[('b', int), ('a', float)]) assert (not array_equivalent(m, n, strict_nan=True)) assert (not array_equivalent(m, n, strict_nan=False))
def array_equivalent(*args, **kwargs): warnings.warn("'pandas.core.common.array_equivalent' is deprecated and " "is no longer public API", DeprecationWarning, stacklevel=2) from pandas.types import missing return missing.array_equivalent(*args, **kwargs)
def test_array_equivalent_str(): for dtype in ['O', 'S', 'U']: assert array_equivalent(np.array(['A', 'B'], dtype=dtype), np.array(['A', 'B'], dtype=dtype)) assert not array_equivalent(np.array(['A', 'B'], dtype=dtype), np.array(['A', 'X'], dtype=dtype))
def test_array_equivalent(): assert array_equivalent(np.array([np.nan, np.nan]), np.array([np.nan, np.nan])) assert array_equivalent(np.array([np.nan, 1, np.nan]), np.array([np.nan, 1, np.nan])) assert array_equivalent(np.array([np.nan, None], dtype='object'), np.array([np.nan, None], dtype='object')) assert array_equivalent(np.array([np.nan, 1 + 1j], dtype='complex'), np.array([np.nan, 1 + 1j], dtype='complex')) assert not array_equivalent( np.array([np.nan, 1 + 1j], dtype='complex'), np.array( [np.nan, 1 + 2j], dtype='complex')) assert not array_equivalent( np.array([np.nan, 1, np.nan]), np.array([np.nan, 2, np.nan])) assert not array_equivalent( np.array(['a', 'b', 'c', 'd']), np.array(['e', 'e'])) assert array_equivalent(Float64Index([0, np.nan]), Float64Index([0, np.nan])) assert not array_equivalent( Float64Index([0, np.nan]), Float64Index([1, np.nan])) assert array_equivalent(DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan])) assert not array_equivalent( DatetimeIndex([0, np.nan]), DatetimeIndex([1, np.nan])) assert array_equivalent(TimedeltaIndex([0, np.nan]), TimedeltaIndex([0, np.nan])) assert not array_equivalent( TimedeltaIndex([0, np.nan]), TimedeltaIndex([1, np.nan])) assert array_equivalent(DatetimeIndex([0, np.nan], tz='US/Eastern'), DatetimeIndex([0, np.nan], tz='US/Eastern')) assert not array_equivalent( DatetimeIndex([0, np.nan], tz='US/Eastern'), DatetimeIndex( [1, np.nan], tz='US/Eastern')) assert not array_equivalent( DatetimeIndex([0, np.nan]), DatetimeIndex( [0, np.nan], tz='US/Eastern')) assert not array_equivalent( DatetimeIndex([0, np.nan], tz='CET'), DatetimeIndex( [0, np.nan], tz='US/Eastern')) assert not array_equivalent( DatetimeIndex([0, np.nan]), TimedeltaIndex([0, np.nan]))