def equals(self, other): """ Determines if two Index objects contain the same elements. """ if self.is_(other): return True return com.array_equivalent(com._values_from_object(self), com._values_from_object(other))
def equals(self, other): """ Determines if two Index objects contain the same elements. """ if self.is_(other): return True try: return com.array_equivalent(com._values_from_object(self), com._values_from_object(other)) except TypeError: # e.g. fails in numpy 1.6 with DatetimeIndex #1681 return False
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 com.array_equivalent(self._data, other) except (TypeError, ValueError): pass return False
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']))
def duplicate_columns(frame): groups = frame.columns.to_series().groupby(frame.dtypes).groups dups = [] for t, v in groups.items(): cs = frame[v].columns vs = frame[v] lcs = len(cs) for i in range(lcs): ia = vs.iloc[:, i].values for j in range(i + 1, lcs): ja = vs.iloc[:, j].values if array_equivalent(ia, ja): dups.append(cs[i]) break return dups
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 (com.array_equivalent(m, n, strict_nan=True)) assert (com.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 com.array_equivalent(m, n, strict_nan=True)) assert (not com.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 com.array_equivalent(m, n, strict_nan=True)) assert (not com.array_equivalent(m, n, strict_nan=False))
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]))
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_deprecation_core_common_array_equivalent(self): with tm.assert_produces_warning(DeprecationWarning): com.array_equivalent(np.array([1, 2]), np.array([1, 2]))
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]))