@@ -43,117 +43,147 @@ def _check_case_dict(case):
43
43
_check_case ([], [], [], [], [], [])
44
44
45
45
46
- def test_index_make_union ():
47
- def _check_case (xloc , xlen , yloc , ylen , eloc , elen ):
48
- xindex = BlockIndex (TEST_LENGTH , xloc , xlen )
49
- yindex = BlockIndex (TEST_LENGTH , yloc , ylen )
50
- bresult = xindex .make_union (yindex )
51
- assert (isinstance (bresult , BlockIndex ))
52
- assert_equal (bresult .blocs , eloc )
53
- assert_equal (bresult .blengths , elen )
54
-
55
- ixindex = xindex .to_int_index ()
56
- iyindex = yindex .to_int_index ()
57
- iresult = ixindex .make_union (iyindex )
58
- assert (isinstance (iresult , IntIndex ))
59
- assert_equal (iresult .indices , bresult .to_int_index ().indices )
60
-
61
- """
62
- x: ----
63
- y: ----
64
- r: --------
65
- """
66
- xloc = [0 ]
67
- xlen = [5 ]
68
- yloc = [5 ]
69
- ylen = [4 ]
70
- eloc = [0 ]
71
- elen = [9 ]
72
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
73
- """
74
- x: ----- -----
75
- y: ----- --
76
- """
77
- xloc = [0 , 10 ]
78
- xlen = [5 , 5 ]
79
- yloc = [2 , 17 ]
80
- ylen = [5 , 2 ]
81
- eloc = [0 , 10 , 17 ]
82
- elen = [7 , 5 , 2 ]
83
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
84
- """
85
- x: ------
86
- y: -------
87
- r: ----------
88
- """
89
- xloc = [1 ]
90
- xlen = [5 ]
91
- yloc = [3 ]
92
- ylen = [5 ]
93
- eloc = [1 ]
94
- elen = [7 ]
95
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
96
- """
97
- x: ------ -----
98
- y: -------
99
- r: -------------
100
- """
101
- xloc = [2 , 10 ]
102
- xlen = [4 , 4 ]
103
- yloc = [4 ]
104
- ylen = [8 ]
105
- eloc = [2 ]
106
- elen = [12 ]
107
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
108
- """
109
- x: --- -----
110
- y: -------
111
- r: -------------
112
- """
113
- xloc = [0 , 5 ]
114
- xlen = [3 , 5 ]
115
- yloc = [0 ]
116
- ylen = [7 ]
117
- eloc = [0 ]
118
- elen = [10 ]
119
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
120
- """
121
- x: ------ -----
122
- y: ------- ---
123
- r: -------------
124
- """
125
- xloc = [2 , 10 ]
126
- xlen = [4 , 4 ]
127
- yloc = [4 , 13 ]
128
- ylen = [8 , 4 ]
129
- eloc = [2 ]
130
- elen = [15 ]
131
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
132
- """
133
- x: ----------------------
134
- y: ---- ---- ---
135
- r: ----------------------
136
- """
137
- xloc = [2 ]
138
- xlen = [15 ]
139
- yloc = [4 , 9 , 14 ]
140
- ylen = [3 , 2 , 2 ]
141
- eloc = [2 ]
142
- elen = [15 ]
143
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
144
- """
145
- x: ---- ---
146
- y: --- ---
147
- """
148
- xloc = [0 , 10 ]
149
- xlen = [3 , 3 ]
150
- yloc = [5 , 15 ]
151
- ylen = [2 , 2 ]
152
- eloc = [0 , 5 , 10 , 15 ]
153
- elen = [3 , 2 , 3 , 2 ]
154
- _check_case (xloc , xlen , yloc , ylen , eloc , elen )
155
-
156
- # TODO: different-length index objects
46
+ class TestSparseIndexUnion (tm .TestCase ):
47
+
48
+ def test_index_make_union (self ):
49
+ def _check_case (xloc , xlen , yloc , ylen , eloc , elen ):
50
+ xindex = BlockIndex (TEST_LENGTH , xloc , xlen )
51
+ yindex = BlockIndex (TEST_LENGTH , yloc , ylen )
52
+ bresult = xindex .make_union (yindex )
53
+ assert (isinstance (bresult , BlockIndex ))
54
+ assert_equal (bresult .blocs , eloc )
55
+ assert_equal (bresult .blengths , elen )
56
+
57
+ ixindex = xindex .to_int_index ()
58
+ iyindex = yindex .to_int_index ()
59
+ iresult = ixindex .make_union (iyindex )
60
+ assert (isinstance (iresult , IntIndex ))
61
+ assert_equal (iresult .indices , bresult .to_int_index ().indices )
62
+
63
+ """
64
+ x: ----
65
+ y: ----
66
+ r: --------
67
+ """
68
+ xloc = [0 ]
69
+ xlen = [5 ]
70
+ yloc = [5 ]
71
+ ylen = [4 ]
72
+ eloc = [0 ]
73
+ elen = [9 ]
74
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
75
+ """
76
+ x: ----- -----
77
+ y: ----- --
78
+ """
79
+ xloc = [0 , 10 ]
80
+ xlen = [5 , 5 ]
81
+ yloc = [2 , 17 ]
82
+ ylen = [5 , 2 ]
83
+ eloc = [0 , 10 , 17 ]
84
+ elen = [7 , 5 , 2 ]
85
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
86
+ """
87
+ x: ------
88
+ y: -------
89
+ r: ----------
90
+ """
91
+ xloc = [1 ]
92
+ xlen = [5 ]
93
+ yloc = [3 ]
94
+ ylen = [5 ]
95
+ eloc = [1 ]
96
+ elen = [7 ]
97
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
98
+ """
99
+ x: ------ -----
100
+ y: -------
101
+ r: -------------
102
+ """
103
+ xloc = [2 , 10 ]
104
+ xlen = [4 , 4 ]
105
+ yloc = [4 ]
106
+ ylen = [8 ]
107
+ eloc = [2 ]
108
+ elen = [12 ]
109
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
110
+ """
111
+ x: --- -----
112
+ y: -------
113
+ r: -------------
114
+ """
115
+ xloc = [0 , 5 ]
116
+ xlen = [3 , 5 ]
117
+ yloc = [0 ]
118
+ ylen = [7 ]
119
+ eloc = [0 ]
120
+ elen = [10 ]
121
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
122
+ """
123
+ x: ------ -----
124
+ y: ------- ---
125
+ r: -------------
126
+ """
127
+ xloc = [2 , 10 ]
128
+ xlen = [4 , 4 ]
129
+ yloc = [4 , 13 ]
130
+ ylen = [8 , 4 ]
131
+ eloc = [2 ]
132
+ elen = [15 ]
133
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
134
+ """
135
+ x: ----------------------
136
+ y: ---- ---- ---
137
+ r: ----------------------
138
+ """
139
+ xloc = [2 ]
140
+ xlen = [15 ]
141
+ yloc = [4 , 9 , 14 ]
142
+ ylen = [3 , 2 , 2 ]
143
+ eloc = [2 ]
144
+ elen = [15 ]
145
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
146
+ """
147
+ x: ---- ---
148
+ y: --- ---
149
+ """
150
+ xloc = [0 , 10 ]
151
+ xlen = [3 , 3 ]
152
+ yloc = [5 , 15 ]
153
+ ylen = [2 , 2 ]
154
+ eloc = [0 , 5 , 10 , 15 ]
155
+ elen = [3 , 2 , 3 , 2 ]
156
+ _check_case (xloc , xlen , yloc , ylen , eloc , elen )
157
+
158
+ def test_intindex_make_union (self ):
159
+ a = IntIndex (5 , np .array ([0 , 3 , 4 ], dtype = np .int32 ))
160
+ b = IntIndex (5 , np .array ([0 , 2 ], dtype = np .int32 ))
161
+ res = a .make_union (b )
162
+ exp = IntIndex (5 , np .array ([0 , 2 , 3 , 4 ], np .int32 ))
163
+ self .assertTrue (res .equals (exp ))
164
+
165
+ a = IntIndex (5 , np .array ([], dtype = np .int32 ))
166
+ b = IntIndex (5 , np .array ([0 , 2 ], dtype = np .int32 ))
167
+ res = a .make_union (b )
168
+ exp = IntIndex (5 , np .array ([0 , 2 ], np .int32 ))
169
+ self .assertTrue (res .equals (exp ))
170
+
171
+ a = IntIndex (5 , np .array ([], dtype = np .int32 ))
172
+ b = IntIndex (5 , np .array ([], dtype = np .int32 ))
173
+ res = a .make_union (b )
174
+ exp = IntIndex (5 , np .array ([], np .int32 ))
175
+ self .assertTrue (res .equals (exp ))
176
+
177
+ a = IntIndex (5 , np .array ([0 , 1 , 2 , 3 , 4 ], dtype = np .int32 ))
178
+ b = IntIndex (5 , np .array ([0 , 1 , 2 , 3 , 4 ], dtype = np .int32 ))
179
+ res = a .make_union (b )
180
+ exp = IntIndex (5 , np .array ([0 , 1 , 2 , 3 , 4 ], np .int32 ))
181
+ self .assertTrue (res .equals (exp ))
182
+
183
+ a = IntIndex (5 , np .array ([0 , 1 ], dtype = np .int32 ))
184
+ b = IntIndex (4 , np .array ([0 , 1 ], dtype = np .int32 ))
185
+ with tm .assertRaises (ValueError ):
186
+ a .make_union (b )
157
187
158
188
159
189
class TestSparseIndexCommon (tm .TestCase ):
0 commit comments