Skip to content

Commit 7c71498

Browse files
authored
CLN: Don't catch TypeError in FrameApply.agg (pandas-dev#40543)
1 parent dd943c8 commit 7c71498

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

pandas/core/apply.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -638,25 +638,18 @@ def agg(self):
638638
obj = self.obj
639639
axis = self.axis
640640

641-
try:
642-
if axis == 1:
643-
result = FrameRowApply(
644-
obj.T,
645-
self.orig_f,
646-
self.raw,
647-
self.result_type,
648-
self.args,
649-
self.kwargs,
650-
).agg()
651-
result = result.T if result is not None else result
652-
else:
653-
result = super().agg()
654-
except TypeError as err:
655-
exc = TypeError(
656-
"DataFrame constructor called with "
657-
f"incompatible data and dtype: {err}"
658-
)
659-
raise exc from err
641+
if axis == 1:
642+
result = FrameRowApply(
643+
obj.T,
644+
self.orig_f,
645+
self.raw,
646+
self.result_type,
647+
self.args,
648+
self.kwargs,
649+
).agg()
650+
result = result.T if result is not None else result
651+
else:
652+
result = super().agg()
660653

661654
if result is None:
662655
result = obj.apply(self.orig_f, axis, args=self.args, **self.kwargs)

pandas/tests/apply/test_invalid_arg.py

+8
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ def test_agg_cython_table_raises_series(series, func, expected):
272272
series.agg(func)
273273

274274

275+
def test_agg_none_to_type():
276+
# GH 40543
277+
df = DataFrame({"a": [None]})
278+
msg = re.escape("int() argument must be a string")
279+
with pytest.raises(TypeError, match=msg):
280+
df.agg({"a": int})
281+
282+
275283
def test_transform_none_to_type():
276284
# GH#34377
277285
df = DataFrame({"a": [None]})

0 commit comments

Comments
 (0)