Skip to content

Commit 3871a6b

Browse files
committed
Avoid catching exceptions unnecessarily in DF.apply
1 parent f235902 commit 3871a6b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pandas/core/frame.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -3921,16 +3921,16 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True):
39213921
# e.g. if we want to apply to a SparseFrame, then can't directly reduce
39223922
if reduce:
39233923

3924-
try:
3925-
# the is the fast-path
3926-
values = self.values
3927-
# Create a dummy Series from an empty array
3928-
# Unlike filling with NA, this works for any dtype
3929-
index = self._get_axis(axis)
3930-
empty_arr = np.empty(len(index), dtype=values.dtype)
3931-
dummy = Series(empty_arr, index=self._get_axis(axis),
3932-
dtype=values.dtype)
3924+
# the is the fast-path
3925+
values = self.values
3926+
# Create a dummy Series from an empty array
3927+
# Unlike filling with NA, this works for any dtype
3928+
index = self._get_axis(axis)
3929+
empty_arr = np.empty(len(index), dtype=values.dtype)
3930+
dummy = Series(empty_arr, index=self._get_axis(axis),
3931+
dtype=values.dtype)
39333932

3933+
try:
39343934
labels = self._get_agg_axis(axis)
39353935
result = lib.reduce(values, func, axis=axis, dummy=dummy,
39363936
labels=labels)

0 commit comments

Comments
 (0)