Exemple #1
0
    def test_intersect_empty(self):
        xindex = IntIndex(4, np.array([], dtype=np.int32))
        yindex = IntIndex(4, np.array([2, 3], dtype=np.int32))
        self.assertTrue(xindex.intersect(yindex).equals(xindex))
        self.assertTrue(yindex.intersect(xindex).equals(xindex))

        xindex = xindex.to_block_index()
        yindex = yindex.to_block_index()
        self.assertTrue(xindex.intersect(yindex).equals(xindex))
        self.assertTrue(yindex.intersect(xindex).equals(xindex))
Exemple #2
0
    def test_intersect_identical(self):
        cases = [
            IntIndex(5, np.array([1, 2], dtype=np.int32)),
            IntIndex(5, np.array([0, 2, 4], dtype=np.int32)),
            IntIndex(0, np.array([], dtype=np.int32)),
            IntIndex(5, np.array([], dtype=np.int32))
        ]

        for case in cases:
            self.assertTrue(case.intersect(case).equals(case))
            case = case.to_block_index()
            self.assertTrue(case.intersect(case).equals(case))
Exemple #3
0
    def test_intersect_empty(self):
        xindex = IntIndex(4, np.array([], dtype=np.int32))
        yindex = IntIndex(4, np.array([2, 3], dtype=np.int32))
        self.assertTrue(xindex.intersect(yindex).equals(xindex))
        self.assertTrue(yindex.intersect(xindex).equals(xindex))

        xindex = xindex.to_block_index()
        yindex = yindex.to_block_index()
        self.assertTrue(xindex.intersect(yindex).equals(xindex))
        self.assertTrue(yindex.intersect(xindex).equals(xindex))
Exemple #4
0
    def test_check_integrity(self):

        # Too many indices than specified in self.length
        msg = "Too many indices"

        with tm.assertRaisesRegexp(ValueError, msg):
            IntIndex(length=1, indices=[1, 2, 3])

        # No index can be negative.
        msg = "No index can be less than zero"

        with tm.assertRaisesRegexp(ValueError, msg):
            IntIndex(length=5, indices=[1, -2, 3])

        # No index can be negative.
        msg = "No index can be less than zero"

        with tm.assertRaisesRegexp(ValueError, msg):
            IntIndex(length=5, indices=[1, -2, 3])

        # All indices must be less than the length.
        msg = "All indices must be less than the length"

        with tm.assertRaisesRegexp(ValueError, msg):
            IntIndex(length=5, indices=[1, 2, 5])

        with tm.assertRaisesRegexp(ValueError, msg):
            IntIndex(length=5, indices=[1, 2, 6])

        # Indices must be strictly ascending.
        msg = "Indices must be strictly increasing"

        with tm.assertRaisesRegexp(ValueError, msg):
            IntIndex(length=5, indices=[1, 3, 2])

        with tm.assertRaisesRegexp(ValueError, msg):
            IntIndex(length=5, indices=[1, 3, 3])
Exemple #5
0
 def _read_sparse_intindex(self, group, key):
     length = getattr(group._v_attrs, '%s_length' % key)
     indices = _read_array(group, '%s_indices' % key)
     return IntIndex(length, indices)
Exemple #6
0
 def test_to_int_index(self):
     index = IntIndex(10, [2, 3, 4, 5, 6])
     self.assertIs(index.to_int_index(), index)
Exemple #7
0
 def test_equals(self):
     index = IntIndex(10, [0, 1, 2, 3, 4])
     self.assertTrue(index.equals(index))
     self.assertFalse(index.equals(IntIndex(10, [0, 1, 2, 3])))
Exemple #8
0
    def test_intindex_make_union(self):
        a = IntIndex(5, np.array([0, 3, 4], dtype=np.int32))
        b = IntIndex(5, np.array([0, 2], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([0, 2, 3, 4], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([], dtype=np.int32))
        b = IntIndex(5, np.array([0, 2], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([0, 2], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([], dtype=np.int32))
        b = IntIndex(5, np.array([], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([0, 1, 2, 3, 4], dtype=np.int32))
        b = IntIndex(5, np.array([0, 1, 2, 3, 4], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([0, 1, 2, 3, 4], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([0, 1], dtype=np.int32))
        b = IntIndex(4, np.array([0, 1], dtype=np.int32))
        with tm.assertRaises(ValueError):
            a.make_union(b)
Exemple #9
0
 def test_to_int_index(self):
     index = IntIndex(10, [2, 3, 4, 5, 6])
     self.assertIs(index.to_int_index(), index)
Exemple #10
0
 def test_equals(self):
     index = IntIndex(10, [0, 1, 2, 3, 4])
     self.assertTrue(index.equals(index))
     self.assertFalse(index.equals(IntIndex(10, [0, 1, 2, 3])))
Exemple #11
0
    def test_intindex_make_union(self):
        a = IntIndex(5, np.array([0, 3, 4], dtype=np.int32))
        b = IntIndex(5, np.array([0, 2], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([0, 2, 3, 4], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([], dtype=np.int32))
        b = IntIndex(5, np.array([0, 2], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([0, 2], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([], dtype=np.int32))
        b = IntIndex(5, np.array([], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([0, 1, 2, 3, 4], dtype=np.int32))
        b = IntIndex(5, np.array([0, 1, 2, 3, 4], dtype=np.int32))
        res = a.make_union(b)
        exp = IntIndex(5, np.array([0, 1, 2, 3, 4], np.int32))
        self.assertTrue(res.equals(exp))

        a = IntIndex(5, np.array([0, 1], dtype=np.int32))
        b = IntIndex(4, np.array([0, 1], dtype=np.int32))
        with tm.assertRaises(ValueError):
            a.make_union(b)