Skip to content

Commit 4c06173

Browse files
committed
Remove warning handling
1 parent 9f47591 commit 4c06173

File tree

2 files changed

+4
-43
lines changed

2 files changed

+4
-43
lines changed

pandas/core/apply.py

+4-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections import defaultdict
55
from functools import partial
66
import inspect
7-
import re
87
from 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
)

pandas/tests/apply/test_frame_apply.py

-17
Original file line numberDiff line numberDiff line change
@@ -1462,20 +1462,3 @@ def test_apply_getitem_axis_1():
14621462
result = df[["a", "a"]].apply(lambda x: x[0] + x[1], axis=1)
14631463
expected = Series([0, 2, 4])
14641464
tm.assert_series_equal(result, expected)
1465-
1466-
1467-
def test_nuisance_depr_passes_through_warnings():
1468-
# GH 43740
1469-
# DataFrame.agg with list-likes may emit warnings for both individual
1470-
# args and for entire columns, but we only want to emit once. We
1471-
# catch and suppress the warnings for individual args, but need to make
1472-
# sure if some other warnings were raised, they get passed through to
1473-
# the user.
1474-
1475-
def foo(x):
1476-
warnings.warn("Hello, World!")
1477-
return x.sum()
1478-
1479-
df = DataFrame({"a": [1, 2, 3]})
1480-
with tm.assert_produces_warning(UserWarning, match="Hello, World!"):
1481-
df.agg([foo])

0 commit comments

Comments
 (0)