8000 BUG: raise error trying to coerce object arrays containing timedelta64('NaT') to StringDType by charris · Pull Request #26049 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: raise error trying to coerce object arrays containing timedelta64('NaT') to StringDType #26049

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

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations < 10000 /summary>
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
BUG: raise error trying to coerce timedelta64('NaT')
  • Loading branch information
ngoldbaum authored and charris committed Mar 16, 2024
commit aca35f74b0ff0798508af6bab47810cc96ce33c6
3 changes: 3 additions & 0 deletions numpy/_core/src/multiarray/stringdtype/dtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ stringdtype_is_known_scalar_type(PyArray_DTypeMeta *NPY_UNUSED(cls),
if (pytype == &PyDatetimeArrType_Type) {
return 1;
}
if (pytype == &PyTimedeltaArrType_Type) {
return 1;
}
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions numpy/_core/tests/test_stringdtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,12 @@ def test_nat_casts():
np.array([output_object]*arr.size, dtype=dtype))


def test_nat_conversion():
for nat in [np.datetime64("NaT", "s"), np.timedelta64("NaT", "s")]:
with pytest.raises(ValueError, match="string coercion is disabled"):
np.array(["a", nat], dtype=StringDType(coerce=False))


def test_growing_strings(dtype):
# growing a string leads to a heap allocation, this tests to make sure
# we do that bookkeeping correctly for all possible starting cases
Expand Down
0