Skip to content

Commit 66cb166

Browse files
jbrockmendelWillAyd
authored andcommitted
CLN: unnecessary exception catching (#29298)
1 parent d3461c1 commit 66cb166

File tree

3 files changed

+5
-25
lines changed

3 files changed

+5
-25
lines changed

pandas/_libs/reduction.pyx

-4
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ cdef class Reducer:
170170
PyArray_SETITEM(result, PyArray_ITER_DATA(it), res)
171171
chunk.data = chunk.data + self.increment
172172
PyArray_ITER_NEXT(it)
173-
except Exception as err:
174-
if hasattr(err, 'args'):
175-
err.args = err.args + (i,)
176-
raise
177173
finally:
178174
# so we don't free the wrong memory
179175
chunk.data = dummy_buf

pandas/core/apply.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
)
1414
from pandas.core.dtypes.generic import ABCSeries
1515

16-
from pandas.io.formats.printing import pprint_thing
17-
1816

1917
def frame_apply(
2018
obj,
@@ -293,20 +291,9 @@ def apply_series_generator(self):
293291
res_index = res_index.take(successes)
294292

295293
else:
296-
try:
297-
for i, v in enumerate(series_gen):
298-
results[i] = self.f(v)
299-
keys.append(v.name)
300-
except Exception as err:
301-
if hasattr(err, "args"):
302-
303-
# make sure i is defined
304-
if i is not None:
305-
k = res_index[i]
306-
err.args = err.args + (
307-
"occurred at index %s" % pprint_thing(k),
308-
)
309-
raise
294+
for i, v in enumerate(series_gen):
295+
results[i] = self.f(v)
296+
keys.append(v.name)
310297

311298
self.results = results
312299
self.res_index = res_index

pandas/tests/frame/test_apply.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,9 @@ def transform2(row):
423423
row["D"] = 7
424424
return row
425425

426-
try:
426+
msg = "'float' object has no attribute 'startswith'"
427+
with pytest.raises(AttributeError, match=msg):
427428
data.apply(transform, axis=1)
428-
except AttributeError as e:
429-
assert len(e.args) == 2
430-
assert e.args[1] == "occurred at index 4"
431-
assert e.args[0] == "'float' object has no attribute 'startswith'"
432429

433430
def test_apply_bug(self):
434431

0 commit comments

Comments
 (0)