Skip to content

Commit e05d508

Browse files
ENH: Keep original traceback in DataFrame.apply
When "raise <exception instance>" 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 <exception instance>". This facilitates debugginb by allowing us to see where (in the provided callable) the exception occured. Added mention of this change in release notes
1 parent ecca28d commit e05d508

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
262262
if code argument out of range (:issue:`4519`, :issue:`4520`)
263263
- Fix reindexing with multiple axes; if an axes match was not replacing the current axes, leading
264264
to a possible lazay frequency inference issue (:issue:`3317`)
265+
- Fixed issue where ``DataFrame.apply`` was reraising exceptions incorrectly
266+
(causing the original stack trace to be truncated).
265267

266268
pandas 0.12
267269
===========

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3632,7 +3632,7 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True):
36323632
except (NameError, UnboundLocalError): # pragma: no cover
36333633
# no k defined yet
36343634
pass
3635-
raise e
3635+
raise
36363636

36373637
if len(results) > 0 and _is_sequence(results[0]):
36383638
if not isinstance(results[0], Series):

0 commit comments

Comments
 (0)