def test_array_to_duplicated_b(self) -> None: a = np.array([[50, 50, 32, 17, 17], [2, 2, 1, 3, 3]]) # find duplicate rows post = array_to_duplicated(a, axis=0) self.assertEqual(post.tolist(), [False, False]) post = array_to_duplicated(a, axis=1) self.assertEqual(post.tolist(), [True, True, False, True, True]) post = array_to_duplicated(a, axis=1, exclude_first=True) self.assertEqual(post.tolist(), [False, True, False, False, True])
def test_array_to_duplicated_d(self) -> None: c = array_to_duplicated( np.array(['q','q','q', 'a', 'w', 'w'], dtype=object), exclude_first=False, exclude_last=False ) self.assertEqual(c.tolist(), [True, True, True, False, True, True])
def test_array_to_duplicated_a(self) -> None: a = array_to_duplicated( np.array([0,1,2,2,1,4,5,3,4,5,5,6]), exclude_first=False, exclude_last=False ) self.assertEqual(a.tolist(), [False, True, True, True, True, True, True, False, True, True, True, False]) a = array_to_duplicated( np.array([0,1,2,2,1,4,5,3,4,5,5,6]), exclude_first=True, exclude_last=False ) self.assertEqual(a.tolist(), [False, False, False, True, True, False, False, False, True, True, True, False])
def test_array_to_duplicated(self, array: np.ndarray) -> None: if array.ndim == 2: for axis in (0, 1): post = util.array_to_duplicated(array, axis=axis) if axis == 0: unique_count = len(set(tuple(x) for x in array)) else: unique_count = len( set(tuple(array[:, i]) for i in range(array.shape[1]))) if unique_count < array.shape[axis]: self.assertTrue(post.sum() > 0) else: post = util.array_to_duplicated(array) # if not all value are unique, we must have some duplicated if len(set(array)) < len(array): self.assertTrue(post.sum() > 0) self.assertTrue(post.dtype == bool)
def test_array_to_duplicated_c(self) -> None: a = np.array([[50, 50, 32, 17, 17], [2,2,1,3,3]]) with self.assertRaises(NotImplementedError): # axis cannot be None array_to_duplicated(a, axis=None) # type: ignore