diff options
author | Thomas A Caswell <tcaswell@gmail.com> | 2016-02-05 12:10:26 -0500 |
---|---|---|
committer | Thomas A Caswell <tcaswell@gmail.com> | 2016-02-07 14:26:55 -0500 |
commit | 08fb5807118423e314f324b9bcafdbaab9316f4d (patch) | |
tree | 1e905ccb1d1388a747595ce558a3799af88a337b /numpy/core/fromnumeric.py | |
parent | 010d17ee8167196ea90c24c57b4ea34badfc11ae (diff) | |
download | numpy-08fb5807118423e314f324b9bcafdbaab9316f4d.tar.gz |
MNT: move std, var, mean calls out of try block
Move the calls to user-provided versions of std, var, and mean on non
mu.ndarray objects out of the `try` block so that numpy will not mask
AttributeError raised during the execution of the function rather than
due to the object not having the required method.
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 1c97b7c4f..00b2dbae0 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -2934,12 +2934,13 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=np._NoValue): if type(a) is not mu.ndarray: try: mean = a.mean - return mean(axis=axis, dtype=dtype, out=out, **kwargs) except AttributeError: pass + else: + return mean(axis=axis, dtype=dtype, out=out, **kwargs) return _methods._mean(a, axis=axis, dtype=dtype, - out=out, **kwargs) + out=out, **kwargs) def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue): @@ -3051,12 +3052,13 @@ def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue): if type(a) is not mu.ndarray: try: std = a.std - return std(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs) except AttributeError: pass + else: + return std(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs) return _methods._std(a, axis=axis, dtype=dtype, out=out, ddof=ddof, - **kwargs) + **kwargs) def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue): @@ -3168,9 +3170,11 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue): if type(a) is not mu.ndarray: try: var = a.var - return var(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs) + except AttributeError: pass + else: + return var(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs) return _methods._var(a, axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs) |