44from collections import defaultdict
55from functools import partial
66import inspect
7- import re
87from typing import (
98 TYPE_CHECKING ,
109 Any ,
@@ -339,12 +338,6 @@ def agg_list_like(self) -> DataFrame | Series:
339338 keys = []
340339 failed_names = []
341340
342- depr_nuisance_columns_msg = (
343- "{} did not aggregate successfully. If any error is "
344- "raised this will raise in a future version of pandas. "
345- "Drop these columns/ops to avoid this warning."
346- )
347-
348341 # degenerate case
349342 if selected_obj .ndim == 1 :
350343 for a in arg :
@@ -367,24 +360,7 @@ def agg_list_like(self) -> DataFrame | Series:
367360 for index , col in enumerate (selected_obj ):
368361 colg = obj ._gotitem (col , ndim = 1 , subset = selected_obj .iloc [:, index ])
369362 try :
370- # Capture and suppress any warnings emitted by us in the call
371- # to agg below, but pass through any warnings that were
372- # generated otherwise.
373- with warnings .catch_warnings (record = True ) as record :
374- new_res = colg .aggregate (arg )
375- if len (record ) > 0 :
376- match = re .compile (depr_nuisance_columns_msg .format (".*" ))
377- for warning in record :
378- if re .match (match , str (warning .message )):
379- failed_names .append (col )
380- else :
381- warnings .warn_explicit (
382- message = warning .message ,
383- category = warning .category ,
384- filename = warning .filename ,
385- lineno = warning .lineno ,
386- )
387-
363+ new_res = colg .aggregate (arg )
388364 except (TypeError , DataError ):
389365 failed_names .append (col )
390366 except ValueError as err :
@@ -412,7 +388,9 @@ def agg_list_like(self) -> DataFrame | Series:
412388
413389 if len (failed_names ) > 0 :
414390 warnings .warn (
415- depr_nuisance_columns_msg .format (failed_names ),
391+ f"{ failed_names } did not aggregate successfully. If any error is "
392+ "raised this will raise in a future version of pandas. "
393+ "Drop these columns/ops to avoid this warning." ,
416394 FutureWarning ,
417395 stacklevel = find_stack_level (),
418396 )
0 commit comments