@@ -54,50 +54,58 @@ def test_maybe_indices_to_slice_left_edge(self):
5454 assert isinstance (maybe_slice , slice )
5555 tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
5656
57- for end in [1 , 2 , 5 , 20 , 99 ]:
58- for step in [1 , 2 , 4 ]:
59- indices = np .arange (0 , end , step , dtype = np .intp )
60- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
57+ @pytest .mark .parametrize ("end" , [1 , 2 , 5 , 20 , 99 ])
58+ @pytest .mark .parametrize ("step" , [1 , 2 , 4 ])
59+ def test_maybe_indices_to_slice_left_edge_not_slice_end_steps (self , end , step ):
60+ target = np .arange (100 )
61+ indices = np .arange (0 , end , step , dtype = np .intp )
62+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
6163
62- assert isinstance (maybe_slice , slice )
63- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
64+ assert isinstance (maybe_slice , slice )
65+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
6466
65- # reverse
66- indices = indices [::- 1 ]
67- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
67+ # reverse
68+ indices = indices [::- 1 ]
69+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
6870
69- assert isinstance (maybe_slice , slice )
70- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
71+ assert isinstance (maybe_slice , slice )
72+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
7173
74+ @pytest .mark .parametrize (
75+ "case" , [[2 , 1 , 2 , 0 ], [2 , 2 , 1 , 0 ], [0 , 1 , 2 , 1 ], [- 2 , 0 , 2 ], [2 , 0 , - 2 ]]
76+ )
77+ def test_maybe_indices_to_slice_left_edge_not_slice (self , case ):
7278 # not slice
73- for case in [[ 2 , 1 , 2 , 0 ], [ 2 , 2 , 1 , 0 ], [ 0 , 1 , 2 , 1 ], [ - 2 , 0 , 2 ], [ 2 , 0 , - 2 ]]:
74- indices = np .array (case , dtype = np .intp )
75- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
79+ target = np . arange ( 100 )
80+ indices = np .array (case , dtype = np .intp )
81+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
7682
77- assert not isinstance (maybe_slice , slice )
78- tm .assert_numpy_array_equal (maybe_slice , indices )
79- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
83+ assert not isinstance (maybe_slice , slice )
84+ tm .assert_numpy_array_equal (maybe_slice , indices )
85+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
8086
81- def test_maybe_indices_to_slice_right_edge (self ):
87+ @pytest .mark .parametrize ("start" , [0 , 2 , 5 , 20 , 97 , 98 ])
88+ @pytest .mark .parametrize ("step" , [1 , 2 , 4 ])
89+ def test_maybe_indices_to_slice_right_edge (self , start , step ):
8290 target = np .arange (100 )
8391
8492 # slice
85- for start in [0 , 2 , 5 , 20 , 97 , 98 ]:
86- for step in [1 , 2 , 4 ]:
87- indices = np .arange (start , 99 , step , dtype = np .intp )
88- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
93+ indices = np .arange (start , 99 , step , dtype = np .intp )
94+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
8995
90- assert isinstance (maybe_slice , slice )
91- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
96+ assert isinstance (maybe_slice , slice )
97+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
9298
93- # reverse
94- indices = indices [::- 1 ]
95- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
99+ # reverse
100+ indices = indices [::- 1 ]
101+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
96102
97- assert isinstance (maybe_slice , slice )
98- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
103+ assert isinstance (maybe_slice , slice )
104+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
99105
106+ def test_maybe_indices_to_slice_right_edge_not_slice (self ):
100107 # not slice
108+ target = np .arange (100 )
101109 indices = np .array ([97 , 98 , 99 , 100 ], dtype = np .intp )
102110 maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
103111
@@ -122,65 +130,75 @@ def test_maybe_indices_to_slice_right_edge(self):
122130 with pytest .raises (IndexError , match = msg ):
123131 target [maybe_slice ]
124132
125- for case in [[99 , 97 , 99 , 96 ], [99 , 99 , 98 , 97 ], [98 , 98 , 97 , 96 ]]:
126- indices = np .array (case , dtype = np .intp )
127- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
133+ @pytest .mark .parametrize (
134+ "case" , [[99 , 97 , 99 , 96 ], [99 , 99 , 98 , 97 ], [98 , 98 , 97 , 96 ]]
135+ )
136+ def test_maybe_indices_to_slice_right_edge_cases (self , case ):
137+ target = np .arange (100 )
138+ indices = np .array (case , dtype = np .intp )
139+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
128140
129- assert not isinstance (maybe_slice , slice )
130- tm .assert_numpy_array_equal (maybe_slice , indices )
131- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
141+ assert not isinstance (maybe_slice , slice )
142+ tm .assert_numpy_array_equal (maybe_slice , indices )
143+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
132144
133- def test_maybe_indices_to_slice_both_edges (self ):
145+ @pytest .mark .parametrize ("step" , [1 , 2 , 4 , 5 , 8 , 9 ])
146+ def test_maybe_indices_to_slice_both_edges (self , step ):
134147 target = np .arange (10 )
135148
136149 # slice
137- for step in [1 , 2 , 4 , 5 , 8 , 9 ]:
138- indices = np .arange (0 , 9 , step , dtype = np .intp )
139- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
140- assert isinstance (maybe_slice , slice )
141- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
142-
143- # reverse
144- indices = indices [::- 1 ]
145- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
146- assert isinstance (maybe_slice , slice )
147- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
150+ indices = np .arange (0 , 9 , step , dtype = np .intp )
151+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
152+ assert isinstance (maybe_slice , slice )
153+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
154+
155+ # reverse
156+ indices = indices [::- 1 ]
157+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
158+ assert isinstance (maybe_slice , slice )
159+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
148160
161+ @pytest .mark .parametrize ("case" , [[4 , 2 , 0 , - 2 ], [2 , 2 , 1 , 0 ], [0 , 1 , 2 , 1 ]])
162+ def test_maybe_indices_to_slice_both_edges_not_slice (self , case ):
149163 # not slice
150- for case in [[4 , 2 , 0 , - 2 ], [2 , 2 , 1 , 0 ], [0 , 1 , 2 , 1 ]]:
151- indices = np .array (case , dtype = np .intp )
152- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
153- assert not isinstance (maybe_slice , slice )
154- tm .assert_numpy_array_equal (maybe_slice , indices )
155- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
156-
157- def test_maybe_indices_to_slice_middle (self ):
164+ target = np .arange (10 )
165+ indices = np .array (case , dtype = np .intp )
166+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
167+ assert not isinstance (maybe_slice , slice )
168+ tm .assert_numpy_array_equal (maybe_slice , indices )
169+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
170+
171+ @pytest .mark .parametrize ("start, end" , [(2 , 10 ), (5 , 25 ), (65 , 97 )])
172+ @pytest .mark .parametrize ("step" , [1 , 2 , 4 , 20 ])
173+ def test_maybe_indices_to_slice_middle (self , start , end , step ):
158174 target = np .arange (100 )
159175
160176 # slice
161- for start , end in [(2 , 10 ), (5 , 25 ), (65 , 97 )]:
162- for step in [1 , 2 , 4 , 20 ]:
163- indices = np .arange (start , end , step , dtype = np .intp )
164- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
177+ indices = np .arange (start , end , step , dtype = np .intp )
178+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
165179
166- assert isinstance (maybe_slice , slice )
167- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
180+ assert isinstance (maybe_slice , slice )
181+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
168182
169- # reverse
170- indices = indices [::- 1 ]
171- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
183+ # reverse
184+ indices = indices [::- 1 ]
185+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
172186
173- assert isinstance (maybe_slice , slice )
174- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
187+ assert isinstance (maybe_slice , slice )
188+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
175189
190+ @pytest .mark .parametrize (
191+ "case" , [[14 , 12 , 10 , 12 ], [12 , 12 , 11 , 10 ], [10 , 11 , 12 , 11 ]]
192+ )
193+ def test_maybe_indices_to_slice_middle_not_slice (self , case ):
176194 # not slice
177- for case in [[ 14 , 12 , 10 , 12 ], [ 12 , 12 , 11 , 10 ], [ 10 , 11 , 12 , 11 ]]:
178- indices = np .array (case , dtype = np .intp )
179- maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
195+ target = np . arange ( 100 )
196+ indices = np .array (case , dtype = np .intp )
197+ maybe_slice = lib .maybe_indices_to_slice (indices , len (target ))
180198
181- assert not isinstance (maybe_slice , slice )
182- tm .assert_numpy_array_equal (maybe_slice , indices )
183- tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
199+ assert not isinstance (maybe_slice , slice )
200+ tm .assert_numpy_array_equal (maybe_slice , indices )
201+ tm .assert_numpy_array_equal (target [indices ], target [maybe_slice ])
184202
185203 def test_maybe_booleans_to_slice (self ):
186204 arr = np .array ([0 , 0 , 1 , 1 , 1 , 0 , 1 ], dtype = np .uint8 )
0 commit comments