Example #1
0
    def test_intersect2d_a(self):
        a = np.array([('a', 'b'), ('c', 'd'), ('e', 'f')])
        b = np.array([('a', 'g'), ('c', 'd'), ('e', 'f')])

        post = intersect2d(a, b)
        self.assertEqual(post.tolist(), [['c', 'd'], ['e', 'f']])

        post = intersect2d(a.astype(object), b.astype(object))
        self.assertEqual(post.tolist(), [['c', 'd'], ['e', 'f']])

        post = union2d(a, b)
        self.assertEqual(post.tolist(),
                         [['a', 'b'], ['a', 'g'], ['c', 'd'], ['e', 'f']])
        post = union2d(a.astype(object), b.astype(object))
        self.assertEqual(post.tolist(),
                         [['a', 'b'], ['a', 'g'], ['c', 'd'], ['e', 'f']])
Example #2
0
 def test_union2d(self, arrays: tp.Sequence[np.ndarray]) -> None:
     post = util.union2d(arrays[0], arrays[1], assume_unique=False)
     self.assertTrue(post.ndim == 2)
     self.assertTrue(
         len(post) == len(
             set(util.array2d_to_tuples(arrays[0]))
             | set(util.array2d_to_tuples(arrays[1]))))
Example #3
0
    def test_union2d(self, arrays: tp.Sequence[np.ndarray]) -> None:
        if datetime64_not_aligned(arrays[0], arrays[1]):
            return

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

        if post.dtype.kind in ('f', 'c') and np.isnan(post).any():
            return

        self.assertTrue(
            len(post) == len(
                set(util.array2d_to_tuples(arrays[0]))
                | set(util.array2d_to_tuples(arrays[1]))))