diff options
author | Allan Haldane <allan.haldane@gmail.com> | 2016-03-19 15:29:59 -0400 |
---|---|---|
committer | Allan Haldane <allan.haldane@gmail.com> | 2016-06-14 00:46:42 -0400 |
commit | 59173726d78e5d9a2ab117bc57961e941769424b (patch) | |
tree | b0fc226e8e2a0a197a8bcfefc3cca0063c95071c /numpy/lib | |
parent | a94fd6122aa30b2cf24757c3e3e826d532c7fe6c (diff) | |
download | numpy-59173726d78e5d9a2ab117bc57961e941769424b.tar.gz |
MAINT: FutureWarning for changes to np.average subclass handling
Fixes #7403
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 93f4f2634..6d06eb4f5 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1002,7 +1002,19 @@ def average(a, axis=None, weights=None, returned=False): TypeError: Axis must be specified when shapes of a and weights differ. """ - a = np.asanyarray(a) + # 3/19/2016 1.12.0: + # replace the next few lines with "a = np.asanyarray(a)" + if (type(a) not in (np.ndarray, np.matrix) and + issubclass(type(a), np.ndarray)): + warnings.warn("np.average currently does not preserve subclasses, but " + "will do so in the future to match the behavior of most " + "other numpy functions such as np.mean. In particular, " + "this means calls which returned a scalar may return a " + "0-d subclass object instead.", + FutureWarning, stacklevel=2) + + if not isinstance(a, np.matrix): + a = np.asarray(a) if weights is None: avg = a.mean(axis) |