44from __future__ import annotations
55
66from collections import abc
7+ from datetime import timedelta
78from decimal import Decimal
89import operator
910from typing import Any
2728 Int64Index ,
2829 UInt64Index ,
2930)
31+ from pandas .core .arrays import TimedeltaArray
3032from pandas .core .computation import expressions as expr
3133from pandas .tests .arithmetic .common import (
3234 assert_invalid_addsub_type ,
@@ -209,6 +211,11 @@ def test_numeric_arr_mul_tdscalar(self, scalar_td, numeric_idx, box_with_array):
209211 tda = expected ._data
210212 dtype = scalar_td .dtype
211213 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 )
212219
213220 index = tm .box_expected (index , box )
214221 expected = tm .box_expected (expected , box )
@@ -240,6 +247,13 @@ def test_numeric_arr_mul_tdscalar_numexpr_path(
240247 obj = tm .box_expected (arr , box , transpose = False )
241248
242249 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+
243257 expected = tm .box_expected (expected , box , transpose = False )
244258
245259 result = obj * scalar_td
@@ -262,6 +276,11 @@ def test_numeric_arr_rdiv_tdscalar(self, three_days, numeric_idx, box_with_array
262276 # i.e. resolution is lower -> use lowest supported resolution
263277 dtype = np .dtype ("m8[s]" )
264278 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 )
265284
266285 index = tm .box_expected (index , box )
267286 expected = tm .box_expected (expected , box )
0 commit comments