@@ -293,11 +293,11 @@ def test_getitem_label_list_with_missing(self):
293
293
s = Series (range (3 ), index = ["a" , "b" , "c" ])
294
294
295
295
# consistency
296
- with pytest .raises (KeyError , match = "with any missing labels " ):
296
+ with pytest .raises (KeyError , match = "not in index " ):
297
297
s [["a" , "d" ]]
298
298
299
299
s = Series (range (3 ))
300
- with pytest .raises (KeyError , match = "with any missing labels " ):
300
+ with pytest .raises (KeyError , match = "not in index " ):
301
301
s [[0 , 3 ]]
302
302
303
303
@pytest .mark .parametrize ("index" , [[True , False ], [True , False , True , False ]])
@@ -349,7 +349,7 @@ def test_loc_to_fail(self):
349
349
s .loc [["4" ]]
350
350
351
351
s .loc [- 1 ] = 3
352
- with pytest .raises (KeyError , match = "with any missing labels " ):
352
+ with pytest .raises (KeyError , match = "not in index " ):
353
353
s .loc [[- 1 , - 2 ]]
354
354
355
355
s ["a" ] = 2
@@ -396,7 +396,7 @@ def test_loc_getitem_list_with_fail(self):
396
396
s .loc [[3 ]]
397
397
398
398
# 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 " ):
400
400
s .loc [[2 , 3 ]]
401
401
402
402
def test_loc_index (self ):
@@ -2249,12 +2249,7 @@ def test_loc_getitem_list_of_labels_categoricalindex_with_na(self, box):
2249
2249
ser2 = ser [:- 1 ]
2250
2250
ci2 = ci [1 :]
2251
2251
# 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"
2258
2253
with pytest .raises (KeyError , match = msg ):
2259
2254
ser2 .loc [box (ci2 )]
2260
2255
@@ -2264,41 +2259,13 @@ def test_loc_getitem_list_of_labels_categoricalindex_with_na(self, box):
2264
2259
with pytest .raises (KeyError , match = msg ):
2265
2260
ser2 .to_frame ().loc [box (ci2 )]
2266
2261
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
-
2295
2262
def test_loc_getitem_series_label_list_missing_values (self ):
2296
2263
# gh-11428
2297
2264
key = np .array (
2298
2265
["2001-01-04" , "2001-01-02" , "2001-01-04" , "2001-01-14" ], dtype = "datetime64"
2299
2266
)
2300
2267
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 " ):
2302
2269
ser .loc [key ]
2303
2270
2304
2271
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):
2307
2274
index = np .array ([9730701000001104 , 10049011000001109 ]),
2308
2275
data = np .array ([999000011000001104 , 999000011000001104 ]),
2309
2276
)
2310
- with pytest .raises (KeyError , match = "with any missing labels " ):
2277
+ with pytest .raises (KeyError , match = "not in index " ):
2311
2278
ser .loc [np .array ([9730701000001104 , 10047311000001102 ])]
2312
2279
2313
2280
@pytest .mark .parametrize ("to_period" , [True , False ])
@@ -2349,7 +2316,7 @@ def test_loc_getitem_listlike_of_datetimelike_keys(self, to_period):
2349
2316
if to_period :
2350
2317
keys = [x .to_period ("D" ) for x in keys ]
2351
2318
2352
- with pytest .raises (KeyError , match = "with any missing labels " ):
2319
+ with pytest .raises (KeyError , match = "not in index " ):
2353
2320
ser .loc [keys ]
2354
2321
2355
2322
0 commit comments