summaryrefslogtreecommitdiff
path: root/numpy/core/_methods.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-05-31 12:57:17 -0700
committerSebastian Berg <sebastian@sipsolutions.net>2022-06-15 11:42:02 -0700
commit0bc84203f03eb971a612d9f6c7194ced80291b8a (patch)
tree2d13068a44d9f58ac05858ad114acc197c16a8e1 /numpy/core/_methods.py
parentb148b0f3c38e8d6ef5b714fb5bdd2fad09e7eb10 (diff)
downloadnumpy-0bc84203f03eb971a612d9f6c7194ced80291b8a.tar.gz
MAINT: Ignore warning rather than forcing output dtype
Forcing the output dtype does not work here, since it actually can be integral (not that this is usually a good idea). In practice, the change we are doing here is forcing 64bit (or 32bit depending on platform) of precision for the calculation. This means that the change will only ever increase precision mildly compared to the current situation.
Diffstat (limited to 'numpy/core/_methods.py')
-rw-r--r--numpy/core/_methods.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py
index e8b82bf1c..4ed271902 100644
--- a/numpy/core/_methods.py
+++ b/numpy/core/_methods.py
@@ -11,6 +11,7 @@ from numpy.core import umath as um
from numpy.core.multiarray import asanyarray
from numpy.core import numerictypes as nt
from numpy.core import _exceptions
+from numpy.core._ufunc_config import no_nep50_warning
from numpy._globals import _NoValue
from numpy.compat import pickle, os_fspath
@@ -179,9 +180,9 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
ret = umr_sum(arr, axis, dtype, out, keepdims, where=where)
if isinstance(ret, mu.ndarray):
- ret = um.true_divide(
- ret, rcount, out=ret, casting='unsafe', subok=False,
- dtype=ret.dtype)
+ with no_nep50_warning():
+ ret = um.true_divide(
+ ret, rcount, out=ret, casting='unsafe', subok=False)
if is_float16_result and out is None:
ret = arr.dtype.type(ret)
elif hasattr(ret, 'dtype'):
@@ -221,8 +222,9 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
# matching rcount to arrmean when where is specified as array
div = rcount.reshape(arrmean.shape)
if isinstance(arrmean, mu.ndarray):
- arrmean = um.true_divide(arrmean, div, out=arrmean, casting='unsafe',
- subok=False, dtype=arrmean.dtype)
+ with no_nep50_warning():
+ arrmean = um.true_divide(arrmean, div, out=arrmean,
+ casting='unsafe', subok=False)
elif hasattr(arrmean, "dtype"):
arrmean = arrmean.dtype.type(arrmean / rcount)
else:
@@ -252,9 +254,9 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
# divide by degrees of freedom
if isinstance(ret, mu.ndarray):
- ret = um.true_divide(
- ret, rcount, out=ret, casting='unsafe', subok=False,
- dtype=ret.dtype)
+ with no_nep50_warning():
+ ret = um.true_divide(
+ ret, rcount, out=ret, casting='unsafe', subok=False)
elif hasattr(ret, 'dtype'):
ret = ret.dtype.type(ret / rcount)
else: