@@ -293,11 +293,11 @@ def test_getitem_label_list_with_missing(self):
293293 s = Series (range (3 ), index = ["a" , "b" , "c" ])
294294
295295 # consistency
296- with pytest .raises (KeyError , match = "with any missing labels " ):
296+ with pytest .raises (KeyError , match = "not in index " ):
297297 s [["a" , "d" ]]
298298
299299 s = Series (range (3 ))
300- with pytest .raises (KeyError , match = "with any missing labels " ):
300+ with pytest .raises (KeyError , match = "not in index " ):
301301 s [[0 , 3 ]]
302302
303303 @pytest .mark .parametrize ("index" , [[True , False ], [True , False , True , False ]])
@@ -349,7 +349,7 @@ def test_loc_to_fail(self):
349349 s .loc [["4" ]]
350350
351351 s .loc [- 1 ] = 3
352- with pytest .raises (KeyError , match = "with any missing labels " ):
352+ with pytest .raises (KeyError , match = "not in index " ):
353353 s .loc [[- 1 , - 2 ]]
354354
355355 s ["a" ] = 2
@@ -396,7 +396,7 @@ def test_loc_getitem_list_with_fail(self):
396396 s .loc [[3 ]]
397397
398398 # a non-match and a match
399- with pytest .raises (KeyError , match = "with any missing labels " ):
399+ with pytest .raises (KeyError , match = "not in index " ):
400400 s .loc [[2 , 3 ]]
401401
402402 def test_loc_index (self ):
@@ -2249,12 +2249,7 @@ def test_loc_getitem_list_of_labels_categoricalindex_with_na(self, box):
22492249 ser2 = ser [:- 1 ]
22502250 ci2 = ci [1 :]
22512251 # but if there are no NAs present, this should raise KeyError
2252- msg = (
2253- r"Passing list-likes to .loc or \[\] with any missing labels is no "
2254- "longer supported. The following labels were missing: "
2255- r"(Categorical)?Index\(\[nan\], .*\). "
2256- "See https"
2257- )
2252+ msg = "not in index"
22582253 with pytest .raises (KeyError , match = msg ):
22592254 ser2 .loc [box (ci2 )]
22602255
@@ -2264,41 +2259,13 @@ def test_loc_getitem_list_of_labels_categoricalindex_with_na(self, box):
22642259 with pytest .raises (KeyError , match = msg ):
22652260 ser2 .to_frame ().loc [box (ci2 )]
22662261
2267- def test_loc_getitem_many_missing_labels_inside_error_message_limited (self ):
2268- # GH#34272
2269- n = 10000
2270- missing_labels = [f"missing_{ label } " for label in range (n )]
2271- ser = Series ({"a" : 1 , "b" : 2 , "c" : 3 })
2272- # regex checks labels between 4 and 9995 are replaced with ellipses
2273- error_message_regex = "missing_4.*\\ .\\ .\\ ..*missing_9995"
2274- with pytest .raises (KeyError , match = error_message_regex ):
2275- ser .loc [["a" , "c" ] + missing_labels ]
2276-
2277- def test_loc_getitem_missing_labels_inside_matched_in_error_message (self ):
2278- # GH#34272
2279- ser = Series ({"a" : 1 , "b" : 2 , "c" : 3 })
2280- error_message_regex = "missing_0.*missing_1.*missing_2"
2281- with pytest .raises (KeyError , match = error_message_regex ):
2282- ser .loc [["a" , "b" , "missing_0" , "c" , "missing_1" , "missing_2" ]]
2283-
2284- def test_loc_getitem_long_text_missing_labels_inside_error_message_limited (self ):
2285- # GH#34272
2286- ser = Series ({"a" : 1 , "b" : 2 , "c" : 3 })
2287- missing_labels = [f"long_missing_label_text_{ i } " * 5 for i in range (3 )]
2288- # regex checks for very long labels there are new lines between each
2289- error_message_regex = (
2290- "long_missing_label_text_0.*\\ \\ n.*long_missing_label_text_1"
2291- )
2292- with pytest .raises (KeyError , match = error_message_regex ):
2293- ser .loc [["a" , "c" ] + missing_labels ]
2294-
22952262 def test_loc_getitem_series_label_list_missing_values (self ):
22962263 # gh-11428
22972264 key = np .array (
22982265 ["2001-01-04" , "2001-01-02" , "2001-01-04" , "2001-01-14" ], dtype = "datetime64"
22992266 )
23002267 ser = Series ([2 , 5 , 8 , 11 ], date_range ("2001-01-01" , freq = "D" , periods = 4 ))
2301- with pytest .raises (KeyError , match = "with any missing labels " ):
2268+ with pytest .raises (KeyError , match = "not in index " ):
23022269 ser .loc [key ]
23032270
23042271 def test_loc_getitem_series_label_list_missing_integer_values (self ):
@@ -2307,7 +2274,7 @@ def test_loc_getitem_series_label_list_missing_integer_values(self):
23072274 index = np .array ([9730701000001104 , 10049011000001109 ]),
23082275 data = np .array ([999000011000001104 , 999000011000001104 ]),
23092276 )
2310- with pytest .raises (KeyError , match = "with any missing labels " ):
2277+ with pytest .raises (KeyError , match = "not in index " ):
23112278 ser .loc [np .array ([9730701000001104 , 10047311000001102 ])]
23122279
23132280 @pytest .mark .parametrize ("to_period" , [True , False ])
@@ -2349,7 +2316,7 @@ def test_loc_getitem_listlike_of_datetimelike_keys(self, to_period):
23492316 if to_period :
23502317 keys = [x .to_period ("D" ) for x in keys ]
23512318
2352- with pytest .raises (KeyError , match = "with any missing labels " ):
2319+ with pytest .raises (KeyError , match = "not in index " ):
23532320 ser .loc [keys ]
23542321
23552322
0 commit comments