From e05d508ed9c37772282d8504bff1ae3f156e6ec6 Mon Sep 17 00:00:00 2001 From: Brad Buran Date: Tue, 13 Aug 2013 08:18:29 -0400 Subject: [PATCH] ENH: Keep original traceback in DataFrame.apply When "raise " is used inside a try/except block, the original stacktrace (containing the code path that raised the original exception). This makes debugging difficult since all we know is that an error occured when `frame._apply_standard` attempted to call the provided function. Preserve the original stacktrace by using "raise" instead of "raise ". This facilitates debugginb by allowing us to see where (in the provided callable) the exception occured. Added mention of this change in release notes --- doc/source/release.rst | 2 ++ pandas/core/frame.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index bb82a055dcd8d..8fba8618fd860 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -262,6 +262,8 @@ See :ref:`Internal Refactoring` if code argument out of range (:issue:`4519`, :issue:`4520`) - Fix reindexing with multiple axes; if an axes match was not replacing the current axes, leading to a possible lazay frequency inference issue (:issue:`3317`) + - Fixed issue where ``DataFrame.apply`` was reraising exceptions incorrectly + (causing the original stack trace to be truncated). pandas 0.12 =========== diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d032bbf66f95e..413cb0b6ef3d0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3632,7 +3632,7 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True): except (NameError, UnboundLocalError): # pragma: no cover # no k defined yet pass - raise e + raise if len(results) > 0 and _is_sequence(results[0]): if not isinstance(results[0], Series):