14
14
make_sparse_index ,
15
15
)
16
16
17
- TEST_LENGTH = 20
18
-
19
- plain_case = [
20
- [0 , 7 , 15 ],
21
- [3 , 5 , 5 ],
22
- [2 , 9 , 14 ],
23
- [2 , 3 , 5 ],
24
- [2 , 9 , 15 ],
25
- [1 , 3 , 4 ],
26
- ]
27
- delete_blocks = [
28
- [0 , 5 ],
29
- [4 , 4 ],
30
- [1 ],
31
- [4 ],
32
- [1 ],
33
- [3 ],
34
- ]
35
- split_blocks = [
36
- [0 ],
37
- [10 ],
38
- [0 , 5 ],
39
- [3 , 7 ],
40
- [0 , 5 ],
41
- [3 , 5 ],
42
- ]
43
- skip_block = [
44
- [10 ],
45
- [5 ],
46
- [0 , 12 ],
47
- [5 , 3 ],
48
- [12 ],
49
- [3 ],
50
- ]
51
-
52
- no_intersect = [
53
- [0 , 10 ],
54
- [4 , 6 ],
55
- [5 , 17 ],
56
- [4 , 2 ],
57
- [],
58
- [],
59
- ]
60
-
61
- one_empty = [
62
- [0 ],
63
- [5 ],
64
- [],
65
- [],
66
- [],
67
- [],
68
- ]
69
-
70
- both_empty = [ # type: ignore[var-annotated]
71
- [],
72
- [],
73
- [],
74
- [],
75
- [],
76
- [],
77
- ]
78
-
79
- CASES = [plain_case , delete_blocks , split_blocks , skip_block , no_intersect , one_empty ]
80
- IDS = [
81
- "plain_case" ,
82
- "delete_blocks" ,
83
- "split_blocks" ,
84
- "skip_block" ,
85
- "no_intersect" ,
86
- "one_empty" ,
87
- ]
17
+
18
+ @pytest .fixture
19
+ def test_length ():
20
+ return 20
21
+
22
+
23
+ @pytest .fixture (
24
+ params = [
25
+ [
26
+ [0 , 7 , 15 ],
27
+ [3 , 5 , 5 ],
28
+ [2 , 9 , 14 ],
29
+ [2 , 3 , 5 ],
30
+ [2 , 9 , 15 ],
31
+ [1 , 3 , 4 ],
32
+ ],
33
+ [
34
+ [0 , 5 ],
35
+ [4 , 4 ],
36
+ [1 ],
37
+ [4 ],
38
+ [1 ],
39
+ [3 ],
40
+ ],
41
+ [
42
+ [0 ],
43
+ [10 ],
44
+ [0 , 5 ],
45
+ [3 , 7 ],
46
+ [0 , 5 ],
47
+ [3 , 5 ],
48
+ ],
49
+ [
50
+ [10 ],
51
+ [5 ],
52
+ [0 , 12 ],
53
+ [5 , 3 ],
54
+ [12 ],
55
+ [3 ],
56
+ ],
57
+ [
58
+ [0 , 10 ],
59
+ [4 , 6 ],
60
+ [5 , 17 ],
61
+ [4 , 2 ],
62
+ [],
63
+ [],
64
+ ],
65
+ [
66
+ [0 ],
67
+ [5 ],
68
+ [],
69
+ [],
70
+ [],
71
+ [],
72
+ ],
73
+ ],
74
+ ids = [
75
+ "plain_case" ,
76
+ "delete_blocks" ,
77
+ "split_blocks" ,
78
+ "skip_block" ,
79
+ "no_intersect" ,
80
+ "one_empty" ,
81
+ ],
82
+ )
83
+ def cases (request ):
84
+ return request .param
88
85
89
86
90
87
class TestSparseIndexUnion :
@@ -101,7 +98,7 @@ class TestSparseIndexUnion:
101
98
[[0 , 10 ], [3 , 3 ], [5 , 15 ], [2 , 2 ], [0 , 5 , 10 , 15 ], [3 , 2 , 3 , 2 ]],
102
99
],
103
100
)
104
- def test_index_make_union (self , xloc , xlen , yloc , ylen , eloc , elen ):
101
+ def test_index_make_union (self , xloc , xlen , yloc , ylen , eloc , elen , test_length ):
105
102
# Case 1
106
103
# x: ----
107
104
# y: ----
@@ -132,8 +129,8 @@ def test_index_make_union(self, xloc, xlen, yloc, ylen, eloc, elen):
132
129
# Case 8
133
130
# x: ---- ---
134
131
# y: --- ---
135
- xindex = BlockIndex (TEST_LENGTH , xloc , xlen )
136
- yindex = BlockIndex (TEST_LENGTH , yloc , ylen )
132
+ xindex = BlockIndex (test_length , xloc , xlen )
133
+ yindex = BlockIndex (test_length , yloc , ylen )
137
134
bresult = xindex .make_union (yindex )
138
135
assert isinstance (bresult , BlockIndex )
139
136
tm .assert_numpy_array_equal (bresult .blocs , np .array (eloc , dtype = np .int32 ))
@@ -180,12 +177,12 @@ def test_int_index_make_union(self):
180
177
181
178
class TestSparseIndexIntersect :
182
179
@td .skip_if_windows
183
- @ pytest . mark . parametrize ( "xloc, xlen, yloc, ylen, eloc, elen" , CASES , ids = IDS )
184
- def test_intersect ( self , xloc , xlen , yloc , ylen , eloc , elen ):
185
- xindex = BlockIndex (TEST_LENGTH , xloc , xlen )
186
- yindex = BlockIndex (TEST_LENGTH , yloc , ylen )
187
- expected = BlockIndex (TEST_LENGTH , eloc , elen )
188
- longer_index = BlockIndex (TEST_LENGTH + 1 , yloc , ylen )
180
+ def test_intersect ( self , cases , test_length ):
181
+ xloc , xlen , yloc , ylen , eloc , elen = cases
182
+ xindex = BlockIndex (test_length , xloc , xlen )
183
+ yindex = BlockIndex (test_length , yloc , ylen )
184
+ expected = BlockIndex (test_length , eloc , elen )
185
+ longer_index = BlockIndex (test_length + 1 , yloc , ylen )
189
186
190
187
result = xindex .intersect (yindex )
191
188
assert result .equals (expected )
@@ -493,10 +490,10 @@ def test_equals(self):
493
490
assert index .equals (index )
494
491
assert not index .equals (IntIndex (10 , [0 , 1 , 2 , 3 ]))
495
492
496
- @ pytest . mark . parametrize ( "xloc, xlen, yloc, ylen, eloc, elen" , CASES , ids = IDS )
497
- def test_to_block_index ( self , xloc , xlen , yloc , ylen , eloc , elen ):
498
- xindex = BlockIndex (TEST_LENGTH , xloc , xlen )
499
- yindex = BlockIndex (TEST_LENGTH , yloc , ylen )
493
+ def test_to_block_index ( self , cases , test_length ):
494
+ xloc , xlen , yloc , ylen , _ , _ = cases
495
+ xindex = BlockIndex (test_length , xloc , xlen )
496
+ yindex = BlockIndex (test_length , yloc , ylen )
500
497
501
498
# see if survive the round trip
502
499
xbindex = xindex .to_int_index ().to_block_index ()
@@ -512,13 +509,13 @@ def test_to_int_index(self):
512
509
513
510
class TestSparseOperators :
514
511
@pytest .mark .parametrize ("opname" , ["add" , "sub" , "mul" , "truediv" , "floordiv" ])
515
- @ pytest . mark . parametrize ( "xloc, xlen, yloc, ylen, eloc, elen" , CASES , ids = IDS )
516
- def test_op ( self , opname , xloc , xlen , yloc , ylen , eloc , elen ):
512
+ def test_op ( self , opname , cases , test_length ):
513
+ xloc , xlen , yloc , ylen , _ , _ = cases
517
514
sparse_op = getattr (splib , f"sparse_{ opname } _float64" )
518
515
python_op = getattr (operator , opname )
519
516
520
- xindex = BlockIndex (TEST_LENGTH , xloc , xlen )
521
- yindex = BlockIndex (TEST_LENGTH , yloc , ylen )
517
+ xindex = BlockIndex (test_length , xloc , xlen )
518
+ yindex = BlockIndex (test_length , yloc , ylen )
522
519
523
520
xdindex = xindex .to_int_index ()
524
521
ydindex = yindex .to_int_index ()
@@ -542,10 +539,10 @@ def test_op(self, opname, xloc, xlen, yloc, ylen, eloc, elen):
542
539
543
540
# check versus Series...
544
541
xseries = Series (x , xdindex .indices )
545
- xseries = xseries .reindex (np .arange (TEST_LENGTH )).fillna (xfill )
542
+ xseries = xseries .reindex (np .arange (test_length )).fillna (xfill )
546
543
547
544
yseries = Series (y , ydindex .indices )
548
- yseries = yseries .reindex (np .arange (TEST_LENGTH )).fillna (yfill )
545
+ yseries = yseries .reindex (np .arange (test_length )).fillna (yfill )
549
546
550
547
series_result = python_op (xseries , yseries )
551
548
series_result = series_result .reindex (ri_index .indices )
0 commit comments