Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fix np.timedelta64('nat').__format__ throwing an exception #17774

Merged
merged 1 commit into from Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion numpy/core/src/multiarray/scalartypes.c.src
Expand Up @@ -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)) {
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/tests/test_datetime.py
Expand Up @@ -429,6 +429,10 @@ def test_timedelta_0_dim_object_array_conversion(self):
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,
Expand Down