Skip to content

Commit bf19958

Browse files
jbrockmendelclaude
andcommitted
TST: add targeted tests for numpygh-16352 and numpygh-22346
Add exact reproducers from the issue reports as test cases: - numpygh-16352: datetime64[h] -> datetime64[ns] upconversion overflow - numpygh-22346: datetime64[s] -> M8[m] downconversion overflow near INT64_MIN Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 77b48f9 commit bf19958

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎numpy/_core/tests/test_datetime.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -963,15 +963,20 @@ def test_cast_overflow_safe_unit_conversion(self):
963963
# INT64_MAX / 1e9 ≈ 9.2e9 seconds ≈ 292 years from epoch,
964964
# so dates beyond ~2262 overflow when cast to ns.
965965

966-
# scalar
966+
# gh-16352: upconversion to finer units overflows
967+
arr = np.array(["2367-12-31 12:00:00"], dtype="datetime64[h]")
968+
with pytest.raises(OverflowError, match="Overflow"):
969+
arr.astype("datetime64[ns]")
970+
971+
# gh-16352: scalar case
967972
val = np.datetime64("3000-01-01", "s")
968973
with pytest.raises(OverflowError, match="Overflow"):
969974
val.astype("datetime64[ns]")
970975

971-
# array
972-
arr = np.array(["3000-01-01", "4000-01-01"], dtype="datetime64[s]")
976+
# gh-22346: downconversion to coarser units overflows near INT64_MIN
977+
dt = np.datetime64(np.iinfo(np.int64).min + 1, "s")
973978
with pytest.raises(OverflowError, match="Overflow"):
974-
arr.astype("datetime64[ns]")
979+
dt.astype("M8[m]")
975980

976981
# negative overflow (far in the past)
977982
val_neg = np.datetime64("0001-01-01", "s")

0 commit comments

Comments
 (0)