diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-11-21 16:07:38 -0800 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2019-11-21 19:07:38 -0500 |
commit | 5923592155fa9301dfbdcc2b2b92972ea796dcc4 (patch) | |
tree | 53603ea715cedae4f1dcef447a1b5b3d743db794 /numpy/testing/_private/utils.py | |
parent | 48e0ded975e0180323677b1c50dee3c891a0989e (diff) | |
download | numpy-5923592155fa9301dfbdcc2b2b92972ea796dcc4.tar.gz |
ENH: add isinf, isnan, fmin, fmax loops for datetime64, timedelta64 (#14841)
`np.datetime('NaT')` should behave more like `float('Nan')`.
Add needed infrastructure so `np.isinf(a)` and `np.isnan(a)`
will run on `datetime64` and `timedelta64` dtypes.
Also added specific loops for `numpy.fmin` and `numpy.fmax`
that mask `NaT`.
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r-- | numpy/testing/_private/utils.py | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 4eb168d18..b14c776d9 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -378,21 +378,6 @@ def assert_equal(actual, desired, err_msg='', verbose=True): if isscalar(desired) != isscalar(actual): raise AssertionError(msg) - # Inf/nan/negative zero handling - try: - isdesnan = gisnan(desired) - isactnan = gisnan(actual) - if isdesnan and isactnan: - return # both nan, so equal - - # handle signed zero specially for floats - if desired == 0 and actual == 0: - if not signbit(desired) == signbit(actual): - raise AssertionError(msg) - - except (TypeError, ValueError, NotImplementedError): - pass - try: isdesnat = isnat(desired) isactnat = isnat(actual) @@ -408,6 +393,33 @@ def assert_equal(actual, desired, err_msg='', verbose=True): except (TypeError, ValueError, NotImplementedError): pass + # Inf/nan/negative zero handling + try: + isdesnan = gisnan(desired) + isactnan = gisnan(actual) + if isdesnan and isactnan: + return # both nan, so equal + + # handle signed zero specially for floats + array_actual = array(actual) + array_desired = array(desired) + if (array_actual.dtype.char in 'Mm' or + array_desired.dtype.char in 'Mm'): + # version 1.18 + # until this version, gisnan failed for datetime64 and timedelta64. + # Now it succeeds but comparison to scalar with a different type + # emits a DeprecationWarning. + # Avoid that by skipping the next check + raise NotImplementedError('cannot compare to a scalar ' + 'with a different type') + + if desired == 0 and actual == 0: + if not signbit(desired) == signbit(actual): + raise AssertionError(msg) + + except (TypeError, ValueError, NotImplementedError): + pass + try: # Explicitly use __eq__ for comparison, gh-2552 if not (desired == actual): |