diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2020-11-14 17:47:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-14 17:47:49 -0700 |
commit | 672a6c8488c7396a6b499b88b2c3fa865bd490f6 (patch) | |
tree | 81fe6ad9d480ec553dc73b148ad3450ec90e3e4b | |
parent | 760449c8426e3877f86b19dce689cc57eb197cac (diff) | |
parent | e3546d3769e63bec6ee6ccb75279fc1832601739 (diff) | |
download | numpy-672a6c8488c7396a6b499b88b2c3fa865bd490f6.tar.gz |
Merge pull request #17774 from charris/bacport-17645
BUG: fix np.timedelta64('nat').__format__ throwing an exception
-rw-r--r-- | numpy/core/src/multiarray/scalartypes.c.src | 3 | ||||
-rw-r--r-- | numpy/core/tests/test_datetime.py | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index b48fdf0c6..d6271ba34 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -275,7 +275,8 @@ gentype_format(PyObject *self, PyObject *args) if (Py_TYPE(self) == &PyBoolArrType_Type) { obj = PyBool_FromLong(PyArrayScalar_VAL(self, Bool)); } - else if (PyArray_IsScalar(self, Integer)) { + else if (PyArray_IsScalar(self, Integer) + && !PyArray_IsScalar(self, Timedelta)) { obj = Py_TYPE(self)->tp_as_number->nb_int(self); } else if (PyArray_IsScalar(self, Floating)) { diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py index 438d52f97..129dd47c6 100644 --- a/numpy/core/tests/test_datetime.py +++ b/numpy/core/tests/test_datetime.py @@ -429,6 +429,10 @@ class TestDateTime: np.timedelta64) assert_equal(actual, expected) + def test_timedelta_nat_format(self): + # gh-17552 + assert_equal('NaT', '{0}'.format(np.timedelta64('nat'))) + def test_timedelta_scalar_construction_units(self): # String construction detecting units assert_equal(np.datetime64('2010').dtype, |