Skip to content

BUG: Avoid intercepting TypeError in DataFrame.agg #49969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,6 @@ def agg(self):
result = None
try:
result = super().agg()
except TypeError as err:
exc = TypeError(
"DataFrame constructor called with "
f"incompatible data and dtype: {err}"
)
raise exc from err
finally:
self.obj = obj
self.axis = axis
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,7 @@ def test_agg_multiple_mixed_raises():
)

# sorted index
# TODO: GH#49399 will fix error message
msg = "DataFrame constructor called with"
msg = "does not support reduction"
with pytest.raises(TypeError, match=msg):
mdf.agg(["min", "sum"])

Expand Down Expand Up @@ -1283,16 +1282,15 @@ def test_nuiscance_columns():
)
tm.assert_frame_equal(result, expected)

msg = "DataFrame constructor called with incompatible data and dtype"
msg = "does not support reduction"
with pytest.raises(TypeError, match=msg):
df.agg("sum")

result = df[["A", "B", "C"]].agg("sum")
expected = Series([6, 6.0, "foobarbaz"], index=["A", "B", "C"])
tm.assert_series_equal(result, expected)

# TODO: GH#49399 will fix error message
msg = "DataFrame constructor called with"
msg = "does not support reduction"
with pytest.raises(TypeError, match=msg):
df.agg(["sum"])

Expand Down