Skip to content

Commit 5168a57

Browse files
committed
Merge pull request #5046 from jtratner/fix-unbound-local
BUG: Fix unbound local in exception handling in core/index
2 parents 1d11d8a + f7b330a commit 5168a57

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pandas/core/frame.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,6 +3342,7 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True):
33423342
else: # pragma : no cover
33433343
raise AssertionError('Axis must be 0 or 1, got %s' % str(axis))
33443344

3345+
i = None
33453346
keys = []
33463347
results = {}
33473348
if ignore_failures:
@@ -3362,14 +3363,12 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True):
33623363
results[i] = func(v)
33633364
keys.append(v.name)
33643365
except Exception as e:
3365-
try:
3366-
if hasattr(e, 'args'):
3366+
if hasattr(e, 'args'):
3367+
# make sure i is defined
3368+
if i is not None:
33673369
k = res_index[i]
33683370
e.args = e.args + ('occurred at index %s' %
3369-
com.pprint_thing(k),)
3370-
except (NameError, UnboundLocalError): # pragma: no cover
3371-
# no k defined yet
3372-
pass
3371+
com.pprint_thing(k),)
33733372
raise
33743373

33753374
if len(results) > 0 and _is_sequence(results[0]):

0 commit comments

Comments
 (0)