summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-02-04 14:16:52 -0600
committerSebastian Berg <sebastian@sipsolutions.net>2021-02-04 14:35:12 -0600
commitbcb168a56d1c47b877568ce51ce90a1ced89f007 (patch)
tree016cf7444437f3e3f1eb90394fd2ef73efe18de0 /numpy/core/numeric.py
parentd3763198673ffc1092539041b8bd23134ae22bee (diff)
downloadnumpy-bcb168a56d1c47b877568ce51ce90a1ced89f007.tar.gz
BUG: Allow unmodified use of isclose, allclose, etc. with timedelta
Disallowing timedelta64+float promotion (to timedelta64) in all cases (previously it was assymetric and "half allowed") meant that isclose, allclose, np.ma.allclose, and assert_arrays_almost_equal (which uses isclose), would stop work for timedelta64. Hardcoding that timedelta64 is passed on unmodified retains the old behaviour. It may make sense to deprecate or change this behaviour in the future, but for the 1.20 release, the behaviour should be as much unmodified as possible. Closes gh-18286
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 086439656..89f56fa09 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -2350,8 +2350,13 @@ def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
# Make sure y is an inexact type to avoid bad behavior on abs(MIN_INT).
# This will cause casting of x later. Also, make sure to allow subclasses
# (e.g., for numpy.ma).
- dt = multiarray.result_type(y, 1.)
- y = array(y, dtype=dt, copy=False, subok=True)
+ # NOTE: We explicitly allow timedelta, which used to work. This could
+ # possibly be deprecated. See also gh-18286.
+ # timedelta works if `atol` is an integer or also a timedelta.
+ # Although, the default tolerances are unlikely to be useful
+ if y.dtype.kind != "m":
+ dt = multiarray.result_type(y, 1.)
+ y = array(y, dtype=dt, copy=False, subok=True)
xfin = isfinite(x)
yfin = isfinite(y)