@@ -299,32 +299,13 @@ def test_dups_fancy_indexing(self):
299299 tm .assert_frame_equal (result , expected )
300300
301301 rows = ["C" , "B" , "E" ]
302- expected = DataFrame (
303- {
304- "test" : [11 , 9 , np .nan ],
305- "test1" : [7.0 , 6 , np .nan ],
306- "other" : ["d" , "c" , np .nan ],
307- },
308- index = rows ,
309- )
310-
311- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
312- result = df .loc [rows ]
313- tm .assert_frame_equal (result , expected )
302+ with pytest .raises (KeyError , match = "with any missing labels" ):
303+ df .loc [rows ]
314304
315305 # see GH5553, make sure we use the right indexer
316306 rows = ["F" , "G" , "H" , "C" , "B" , "E" ]
317- expected = DataFrame (
318- {
319- "test" : [np .nan , np .nan , np .nan , 11 , 9 , np .nan ],
320- "test1" : [np .nan , np .nan , np .nan , 7.0 , 6 , np .nan ],
321- "other" : [np .nan , np .nan , np .nan , "d" , "c" , np .nan ],
322- },
323- index = rows ,
324- )
325- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
326- result = df .loc [rows ]
327- tm .assert_frame_equal (result , expected )
307+ with pytest .raises (KeyError , match = "with any missing labels" ):
308+ df .loc [rows ]
328309
329310 # List containing only missing label
330311 dfnu = DataFrame (np .random .randn (5 , 3 ), index = list ("AABCD" ))
@@ -340,38 +321,25 @@ def test_dups_fancy_indexing(self):
340321
341322 # GH 4619; duplicate indexer with missing label
342323 df = DataFrame ({"A" : [0 , 1 , 2 ]})
343- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
344- result = df .loc [[0 , 8 , 0 ]]
345- expected = DataFrame ({"A" : [0 , np .nan , 0 ]}, index = [0 , 8 , 0 ])
346- tm .assert_frame_equal (result , expected , check_index_type = False )
324+ with pytest .raises (KeyError , match = "with any missing labels" ):
325+ df .loc [[0 , 8 , 0 ]]
347326
348327 df = DataFrame ({"A" : list ("abc" )})
349- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
350- result = df .loc [[0 , 8 , 0 ]]
351- expected = DataFrame ({"A" : ["a" , np .nan , "a" ]}, index = [0 , 8 , 0 ])
352- tm .assert_frame_equal (result , expected , check_index_type = False )
328+ with pytest .raises (KeyError , match = "with any missing labels" ):
329+ df .loc [[0 , 8 , 0 ]]
353330
354331 # non unique with non unique selector
355332 df = DataFrame ({"test" : [5 , 7 , 9 , 11 ]}, index = ["A" , "A" , "B" , "C" ])
356- expected = DataFrame (
357- {"test" : [5 , 7 , 5 , 7 , np .nan ]}, index = ["A" , "A" , "A" , "A" , "E" ]
358- )
359- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
360- result = df .loc [["A" , "A" , "E" ]]
361- tm .assert_frame_equal (result , expected )
333+ with pytest .raises (KeyError , match = "with any missing labels" ):
334+ df .loc [["A" , "A" , "E" ]]
362335
363336 def test_dups_fancy_indexing2 (self ):
364337 # GH 5835
365338 # dups on index and missing values
366339 df = DataFrame (np .random .randn (5 , 5 ), columns = ["A" , "B" , "B" , "B" , "A" ])
367340
368- expected = pd .concat (
369- [df .loc [:, ["A" , "B" ]], DataFrame (np .nan , columns = ["C" ], index = df .index )],
370- axis = 1 ,
371- )
372- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
373- result = df .loc [:, ["A" , "B" , "C" ]]
374- tm .assert_frame_equal (result , expected )
341+ with pytest .raises (KeyError , match = "with any missing labels" ):
342+ df .loc [:, ["A" , "B" , "C" ]]
375343
376344 # GH 6504, multi-axis indexing
377345 df = DataFrame (
0 commit comments