Skip to content

Commit f7ee822

Browse files
is_timedelta64_object behaves differently on older versions?
1 parent 3c21c7b commit f7ee822

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

pandas/_libs/tslibs/timedeltas.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,9 @@ cdef object create_timedelta(object value, str in_unit, NPY_DATETIMEUNIT out_res
907907
if util.is_nan(value):
908908
return NaT
909909
out_value = <int64_t>value
910-
elif is_timedelta64_object(value):
910+
# is_timedelta_64_object may not give correct results w/ some versions?
911+
# see e.g. https://github.com/pandas-dev/pandas/runs/6397652653?check_suite_focus=true#step:11:435
912+
elif isinstance(value, np.timedelta64):
911913
out_value = ensure_td64ns(value).view(np.int64)
912914
elif isinstance(value, str):
913915
if value.startswith(("P", "-P")):

pandas/tests/scalar/timedelta/test_constructors.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,15 @@ def test_overflow_on_construction(td_overflow_msg: str):
225225
(9223372037, "s", " seconds"), # 44 seconds
226226
],
227227
)
228-
def test_construction_out_of_bounds_td64(val, unit, name):
228+
def test_construction_out_of_bounds_td64(val, unit, name, td_overflow_msg: str):
229229
# TODO: parametrize over units just above/below the implementation bounds
230230
# once GH#38964 is resolved
231231

232232
# Timedelta.max is just under 106752 days
233233
td64 = np.timedelta64(val, unit)
234234
assert td64.astype("m8[ns]").view("i8") < 0 # i.e. naive astype will be wrong
235235

236-
msg = str(val) + name
237-
with pytest.raises(OutOfBoundsTimedelta, match=msg):
236+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
238237
Timedelta(td64)
239238

240239
# But just back in bounds and we are OK
@@ -243,7 +242,7 @@ def test_construction_out_of_bounds_td64(val, unit, name):
243242
td64 *= -1
244243
assert td64.astype("m8[ns]").view("i8") > 0 # i.e. naive astype will be wrong
245244

246-
with pytest.raises(OutOfBoundsTimedelta, match="-" + msg):
245+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
247246
Timedelta(td64)
248247

249248
# But just back in bounds and we are OK

0 commit comments

Comments
 (0)