4
4
from __future__ import annotations
5
5
6
6
from collections import abc
7
+ from datetime import timedelta
7
8
from decimal import Decimal
8
9
import operator
9
10
from typing import Any
27
28
Int64Index ,
28
29
UInt64Index ,
29
30
)
31
+ from pandas .core .arrays import TimedeltaArray
30
32
from pandas .core .computation import expressions as expr
31
33
from pandas .tests .arithmetic .common import (
32
34
assert_invalid_addsub_type ,
@@ -209,6 +211,11 @@ def test_numeric_arr_mul_tdscalar(self, scalar_td, numeric_idx, box_with_array):
209
211
tda = expected ._data
210
212
dtype = scalar_td .dtype
211
213
expected = type (tda )._simple_new (tda ._ndarray .astype (dtype ), dtype = dtype )
214
+ elif type (scalar_td ) is timedelta and box not in [Index , Series ]:
215
+ # TODO(2.0): once TDA.astype converts to m8, just do expected.astype
216
+ tda = expected ._data
217
+ dtype = np .dtype ("m8[us]" )
218
+ expected = type (tda )._simple_new (tda ._ndarray .astype (dtype ), dtype = dtype )
212
219
213
220
index = tm .box_expected (index , box )
214
221
expected = tm .box_expected (expected , box )
@@ -240,6 +247,13 @@ def test_numeric_arr_mul_tdscalar_numexpr_path(
240
247
obj = tm .box_expected (arr , box , transpose = False )
241
248
242
249
expected = arr_i8 .view ("timedelta64[D]" ).astype ("timedelta64[ns]" )
250
+ if type (scalar_td ) is timedelta and box is array :
251
+ # TODO(2.0): this shouldn't depend on 'box'
252
+ expected = expected .astype ("timedelta64[us]" )
253
+ # TODO(2.0): won't be necessary to construct TimedeltaArray
254
+ # explicitly.
255
+ expected = TimedeltaArray ._simple_new (expected , dtype = expected .dtype )
256
+
243
257
expected = tm .box_expected (expected , box , transpose = False )
244
258
245
259
result = obj * scalar_td
@@ -262,6 +276,11 @@ def test_numeric_arr_rdiv_tdscalar(self, three_days, numeric_idx, box_with_array
262
276
# i.e. resolution is lower -> use lowest supported resolution
263
277
dtype = np .dtype ("m8[s]" )
264
278
expected = type (tda )._simple_new (tda ._ndarray .astype (dtype ), dtype = dtype )
279
+ elif type (three_days ) is timedelta and box not in [Index , Series ]:
280
+ # TODO(2.0): just use expected.astype
281
+ tda = expected ._data
282
+ dtype = np .dtype ("m8[us]" )
283
+ expected = type (tda )._simple_new (tda ._ndarray .astype (dtype ), dtype = dtype )
265
284
266
285
index = tm .box_expected (index , box )
267
286
expected = tm .box_expected (expected , box )
0 commit comments