def test_duplicated_with_nas(): keys = np.array([0, 1, nan, 0, 2, nan], dtype=object) result = lib.duplicated(keys) expected = [False, False, False, True, False, True] assert (np.array_equal(result, expected)) result = lib.duplicated(keys, take_last=True) expected = [True, False, True, False, False, False] assert (np.array_equal(result, expected)) keys = np.empty(8, dtype=object) for i, t in enumerate(list(zip([0, 0, nan, nan] * 2, [0, nan, 0, nan] * 2))): keys[i] = t result = lib.duplicated(keys) falses = [False] * 4 trues = [True] * 4 expected = falses + trues assert (np.array_equal(result, expected)) result = lib.duplicated(keys, take_last=True) expected = trues + falses assert (np.array_equal(result, expected))
def duplicated(self, keep="first"): keys = com._values_from_object(com._ensure_object(self.values)) duplicated = lib.duplicated(keys, keep=keep) try: return self._constructor(duplicated, index=self.index).__finalize__(self) except AttributeError: return np.array(duplicated, dtype=bool)
def duplicated(self, take_last=False): keys = com._ensure_object(self.values) duplicated = lib.duplicated(keys, take_last=take_last) try: return self._constructor(duplicated, index=self.index).__finalize__(self) except AttributeError: return np.array(duplicated, dtype=bool)
def duplicated(self, keep='first'): keys = com._values_from_object(com._ensure_object(self.values)) duplicated = lib.duplicated(keys, keep=keep) try: return self._constructor(duplicated, index=self.index).__finalize__(self) except AttributeError: return np.array(duplicated, dtype=bool)
def duplicated(self, take_last=False): keys = com._ensure_object(self.values) duplicated = lib.duplicated(keys, take_last=take_last) try: return self._constructor(duplicated, index=self.index).__finalize__(self) except AttributeError: from pandas.core.index import Index return Index(duplicated)
def test_duplicated_with_nas(): keys = np.array([0, 1, nan, 0, 2, nan], dtype=object) result = lib.duplicated(keys) expected = [False, False, False, True, False, True] assert(np.array_equal(result, expected)) result = lib.duplicated(keys, take_last=True) expected = [True, False, True, False, False, False] assert(np.array_equal(result, expected)) keys = np.empty(8, dtype=object) for i, t in enumerate(zip([0, 0, nan, nan] * 2, [0, nan, 0, nan] * 2)): keys[i] = t result = lib.duplicated(keys) falses = [False] * 4 trues = [True] * 4 expected = falses + trues assert(np.array_equal(result, expected)) result = lib.duplicated(keys, take_last=True) expected = trues + falses assert(np.array_equal(result, expected))