Skip to content

Commit 80fbb63

Browse files
committed
WIP, MAINT: upstream timedelta64 changes
* draft changes to allow pandas test suite to pass with upstream NumPy prohibition on integer -> m8 casting
1 parent e31b4f4 commit 80fbb63

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ class Timedelta(_Timedelta):
11811181

11821182
kwargs = {key: _to_py_int_float(kwargs[key]) for key in kwargs}
11831183

1184-
nano = kwargs.pop('nanoseconds', 0)
1184+
nano = np.timedelta64(kwargs.pop('nanoseconds', 0))
11851185
try:
11861186
value = nano + convert_to_timedelta64(timedelta(**kwargs),
11871187
'ns')

pandas/tests/arithmetic/test_datetime64.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,12 @@ def test_timedelta64_equal_timedelta_supported_ops(self, op):
21372137
# 'us': 1}
21382138

21392139
def timedelta64(*args):
2140-
return sum(starmap(np.timedelta64, zip(args, intervals)))
2140+
# integer types -> m8 casting will soon be prohibited
2141+
# in NumPy; avoid built-in sum() here to skip the casting
2142+
# prohibition in ufunc
2143+
# NOTE: extra list() call also added after switching from
2144+
# sum -> np.sum() to expand starmap object for later in test
2145+
return np.sum(list(starmap(np.timedelta64, zip(args, intervals))))
21412146

21422147
for d, h, m, s, us in product(*([range(2)] * 5)):
21432148
nptd = timedelta64(d, h, m, s, us)

0 commit comments

Comments
 (0)