Skip to content

assert_allclose stopped working for timedelta64 in version 1.20 #18286

@hoxbro

Description

@hoxbro

I have an unit test which used np.testing.assert_allclose for testing two timedelta64 arrays, but after i updated numpy to version 1.20 it has stopped working. I don't know if it is intended to work this way or it is a bug.

Reproducing code example:

import numpy as np

a = np.timedelta64(1, "ns")
b = np.timedelta64(1, "ns")

np.testing.assert_allclose(a, b)

Error message:

Traceback (most recent call last):
  File "c:/Users/shh/Development/pressoh/timedelta_assert.py", line 6, in <module>
    np.testing.assert_allclose(a, b)
  File "C:\Users\shh\miniconda3\envs\pressoh_dev\lib\site-packages\numpy\testing\_private\utils.py", line 1529, in assert_allclose
    verbose=verbose, header=header, equal_nan=equal_nan)
  File "C:\Users\shh\miniconda3\envs\pressoh_dev\lib\site-packages\numpy\testing\_private\utils.py", line 790, in assert_array_compare
    val = comparison(x, y)
  File "C:\Users\shh\miniconda3\envs\pressoh_dev\lib\site-packages\numpy\testing\_private\utils.py", line 1524, in compare
    equal_nan=equal_nan)
  File "<__array_function__ internals>", line 6, in isclose
  File "C:\Users\shh\miniconda3\envs\pressoh_dev\lib\site-packages\numpy\core\numeric.py", line 2354, in isclose
    dt = multiarray.result_type(y, 1.)
  File "<__array_function__ internals>", line 6, in result_type
TypeError: The DTypes <class 'numpy.dtype[float64]'> and <class 'numpy.dtype[timedelta64]'> do not have a common DType. For example they cannot be stored in a single array unless the dtype is `object`.

NumPy/Python version information:

1.20.0 3.7.9 | packaged by conda-forge | (default, Dec 9 2020, 20:36:16) [MSC v.1916 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions