diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2019-03-16 10:06:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-16 10:06:39 -0700 |
commit | 9a35ab439809270dfb582ed1ddf0376512ec4005 (patch) | |
tree | 763e0904dd9e2c370596a40c049e82b3298560a3 /numpy/core/fromnumeric.py | |
parent | 0764929543c85decde9d664367dbf7d8f137fe1f (diff) | |
parent | df286d00bf6236f0158fc2cedd91dd3905fc05ca (diff) | |
download | numpy-9a35ab439809270dfb582ed1ddf0376512ec4005.tar.gz |
Merge branch 'master' into deprecate-float-order
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 23 |
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) |