Skip to content

Commit

Permalink
CLN: unnecessary exception catching (pandas-dev#29298)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and WillAyd committed Nov 7, 2019
1 parent d3461c1 commit 66cb166
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
4 changes: 0 additions & 4 deletions pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ cdef class Reducer:
PyArray_SETITEM(result, PyArray_ITER_DATA(it), res)
chunk.data = chunk.data + self.increment
PyArray_ITER_NEXT(it)
except Exception as err:
if hasattr(err, 'args'):
err.args = err.args + (i,)
raise
finally:
# so we don't free the wrong memory
chunk.data = dummy_buf
Expand Down
19 changes: 3 additions & 16 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
)
from pandas.core.dtypes.generic import ABCSeries

from pandas.io.formats.printing import pprint_thing


def frame_apply(
obj,
Expand Down Expand Up @@ -293,20 +291,9 @@ def apply_series_generator(self):
res_index = res_index.take(successes)

else:
try:
for i, v in enumerate(series_gen):
results[i] = self.f(v)
keys.append(v.name)
except Exception as err:
if hasattr(err, "args"):

# make sure i is defined
if i is not None:
k = res_index[i]
err.args = err.args + (
"occurred at index %s" % pprint_thing(k),
)
raise
for i, v in enumerate(series_gen):
results[i] = self.f(v)
keys.append(v.name)

self.results = results
self.res_index = res_index
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,9 @@ def transform2(row):
row["D"] = 7
return row

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

def test_apply_bug(self):

Expand Down

0 comments on commit 66cb166

Please sign in to comment.