Esempio n. 1
0
    def test_union1d_a(self) -> None:
        a1 = np.array([3, 2, 1])
        a2 = np.array(['3', '2', '1'])

        # need to avoid this
        # ipdb> np.union1d(a1, a2)                                                             # array(['1', '2', '3'], dtype='<U21')
        self.assertEqual(set(union1d(a1, a2)),
                {1, 2, 3, '2', '1', '3'}
                )

        self.assertEqual(
                union1d(np.array(['a', 'b', 'c']), np.array(['aaa', 'bbb', 'ccc'])).tolist(),
                ['a', 'aaa', 'b', 'bbb', 'c', 'ccc']
                )

        self.assertEqual(
                set(union1d(np.array([1, 2, 3]), np.array([None, False]))),
                {False, 2, 3, None, 1}
                )

        self.assertEqual(
                set(union1d(np.array([False, True]), np.array([None, 'a']))),
                {False, True, None, 'a'}
                )

        self.assertEqual(set(union1d(np.array([None, 1, 'd']), np.array([None, 3, 'ff']))),
                {'d', 1, 3, None, 'ff'}
                )
Esempio n. 2
0
    def test_union1d(self, arrays: tp.Sequence[np.ndarray]) -> None:
        post = util.union1d(arrays[0], arrays[1], assume_unique=False)
        self.assertTrue(post.ndim == 1)
        # nan values in complex numbers make direct comparison tricky
        self.assertTrue(len(post) == len(set(arrays[0]) | set(arrays[1])))

        # complex results are tricky to compare after forming sets
        if (post.dtype.kind not in ('O', 'M', 'm', 'c', 'f')
                and not np.isnan(post).any()):
            self.assertTrue(set(post) == (set(arrays[0]) | set(arrays[1])))
Esempio n. 3
0
    def test_union1d(self, arrays: tp.Sequence[np.ndarray]) -> None:
        post = util.union1d(arrays[0], arrays[1], assume_unique=False)
        self.assertTrue(post.ndim == 1)

        # this includes cases where there are more than one NaN
        self.assertTrue(len(post) == len(set(arrays[0]) | set(arrays[1])))
        # complex results are tricky to compare after forming sets
        if (post.dtype.kind not in ('O', 'M', 'm', 'c', 'f')
                and not np.isnan(post).any()):
            self.assertSetEqual(set(post), (set(arrays[0]) | set(arrays[1])))
Esempio n. 4
0
    def test_union1d(self, arrays: tp.Sequence[np.ndarray]) -> None:
        if datetime64_not_aligned(arrays[0], arrays[1]):
            return

        post = util.union1d(arrays[0], arrays[1], assume_unique=False)
        self.assertTrue(post.ndim == 1)

        # the unqiueness of NaNs has changed in newer NP versions, so only compare if non-nans are found
        if post.dtype.kind in ('c', 'f') and not np.isnan(post).any():
            self.assertTrue(len(post) == len(set(arrays[0]) | set(arrays[1])))
        # complex results are tricky to compare after forming sets
        if (post.dtype.kind not in ('O', 'M', 'm', 'c', 'f')
                and not np.isnan(post).any()):
            self.assertSetEqual(set(post), (set(arrays[0]) | set(arrays[1])))