From f7b330ad25c49f18966579046599ae8ec9de0610 Mon Sep 17 00:00:00 2001 From: Jeffrey Tratner Date: Sun, 29 Sep 2013 16:35:51 -0400 Subject: [PATCH] BUG: Fix unbound local in exception handling in core/index Only would occur if both enumerations failed. better way to handle than try/except. --- pandas/core/frame.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 935dff44ad49e..f7d2b161759ed 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3342,6 +3342,7 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True): else: # pragma : no cover raise AssertionError('Axis must be 0 or 1, got %s' % str(axis)) + i = None keys = [] results = {} if ignore_failures: @@ -3362,14 +3363,12 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True): results[i] = func(v) keys.append(v.name) except Exception as e: - try: - if hasattr(e, 'args'): + if hasattr(e, 'args'): + # make sure i is defined + if i is not None: k = res_index[i] e.args = e.args + ('occurred at index %s' % - com.pprint_thing(k),) - except (NameError, UnboundLocalError): # pragma: no cover - # no k defined yet - pass + com.pprint_thing(k),) raise if len(results) > 0 and _is_sequence(results[0]):