summaryrefslogtreecommitdiff
path: root/numpy/core/fromnumeric.py
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2019-03-13 17:19:13 -0400
committerGitHub <noreply@github.com>2019-03-13 17:19:13 -0400
commit25b5273834c73bb278a4741aad5ade4ad705f209 (patch)
tree63d235c5101d7ce30aac6e1dd94aeb92a757f654 /numpy/core/fromnumeric.py
parent84f9576f3d62ffd0aea64f73a02d90dcbc8cc767 (diff)
parent352b7871a072a51f32bcb6bc1541cabbc447d5c4 (diff)
downloadnumpy-25b5273834c73bb278a4741aad5ade4ad705f209.tar.gz
Merge pull request #13109 from anntzer/chaining
Prevent traceback chaining in _wrapfunc.
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r--numpy/core/fromnumeric.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index 04b1e9fae..760577890 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -52,17 +52,20 @@ def _wrapit(obj, method, *args, **kwds):
def _wrapfunc(obj, method, *args, **kwds):
- try:
- return getattr(obj, method)(*args, **kwds)
-
- # An AttributeError occurs if the object does not have
- # such a method in its class.
+ bound = getattr(obj, method, None)
+ if bound is None:
+ return _wrapit(obj, method, *args, **kwds)
- # A TypeError occurs if the object does have such a method
- # in its class, but its signature is not identical to that
- # of NumPy's. This situation has occurred in the case of
- # a downstream library like 'pandas'.
- except (AttributeError, TypeError):
+ try:
+ return bound(*args, **kwds)
+ except TypeError:
+ # A TypeError occurs if the object does have such a method in its
+ # class, but its signature is not identical to that of NumPy's. This
+ # situation has occurred in the case of a downstream library like
+ # 'pandas'.
+ #
+ # Call _wrapit from within the except clause to ensure a potential
+ # exception has a traceback chain.
return _wrapit(obj, method, *args, **kwds)