@@ -146,83 +146,6 @@ def test_append_mixed_dtypes():
146146 tm .assert_index_equal (res , exp )
147147
148148
149- def test_take (idx ):
150- indexer = [4 , 3 , 0 , 2 ]
151- result = idx .take (indexer )
152- expected = idx [indexer ]
153- assert result .equals (expected )
154-
155- # TODO: Remove Commented Code
156- # if not isinstance(idx,
157- # (DatetimeIndex, PeriodIndex, TimedeltaIndex)):
158- # GH 10791
159- msg = "'MultiIndex' object has no attribute 'freq'"
160- with pytest .raises (AttributeError , match = msg ):
161- idx .freq
162-
163-
164- def test_take_invalid_kwargs (idx ):
165- idx = idx
166- indices = [1 , 2 ]
167-
168- msg = r"take\(\) got an unexpected keyword argument 'foo'"
169- with pytest .raises (TypeError , match = msg ):
170- idx .take (indices , foo = 2 )
171-
172- msg = "the 'out' parameter is not supported"
173- with pytest .raises (ValueError , match = msg ):
174- idx .take (indices , out = indices )
175-
176- msg = "the 'mode' parameter is not supported"
177- with pytest .raises (ValueError , match = msg ):
178- idx .take (indices , mode = "clip" )
179-
180-
181- def test_take_fill_value ():
182- # GH 12631
183- vals = [["A" , "B" ], [pd .Timestamp ("2011-01-01" ), pd .Timestamp ("2011-01-02" )]]
184- idx = pd .MultiIndex .from_product (vals , names = ["str" , "dt" ])
185-
186- result = idx .take (np .array ([1 , 0 , - 1 ]))
187- exp_vals = [
188- ("A" , pd .Timestamp ("2011-01-02" )),
189- ("A" , pd .Timestamp ("2011-01-01" )),
190- ("B" , pd .Timestamp ("2011-01-02" )),
191- ]
192- expected = pd .MultiIndex .from_tuples (exp_vals , names = ["str" , "dt" ])
193- tm .assert_index_equal (result , expected )
194-
195- # fill_value
196- result = idx .take (np .array ([1 , 0 , - 1 ]), fill_value = True )
197- exp_vals = [
198- ("A" , pd .Timestamp ("2011-01-02" )),
199- ("A" , pd .Timestamp ("2011-01-01" )),
200- (np .nan , pd .NaT ),
201- ]
202- expected = pd .MultiIndex .from_tuples (exp_vals , names = ["str" , "dt" ])
203- tm .assert_index_equal (result , expected )
204-
205- # allow_fill=False
206- result = idx .take (np .array ([1 , 0 , - 1 ]), allow_fill = False , fill_value = True )
207- exp_vals = [
208- ("A" , pd .Timestamp ("2011-01-02" )),
209- ("A" , pd .Timestamp ("2011-01-01" )),
210- ("B" , pd .Timestamp ("2011-01-02" )),
211- ]
212- expected = pd .MultiIndex .from_tuples (exp_vals , names = ["str" , "dt" ])
213- tm .assert_index_equal (result , expected )
214-
215- msg = "When allow_fill=True and fill_value is not None, all indices must be >= -1"
216- with pytest .raises (ValueError , match = msg ):
217- idx .take (np .array ([1 , 0 , - 2 ]), fill_value = True )
218- with pytest .raises (ValueError , match = msg ):
219- idx .take (np .array ([1 , 0 , - 5 ]), fill_value = True )
220-
221- msg = "index -5 is out of bounds for( axis 0 with)? size 4"
222- with pytest .raises (IndexError , match = msg ):
223- idx .take (np .array ([1 , - 5 ]))
224-
225-
226149def test_iter (idx ):
227150 result = list (idx )
228151 expected = [
0 commit comments