File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 11
11
lib ,
12
12
missing as libmissing ,
13
13
)
14
+ from pandas ._libs .tslibs import (
15
+ Timedelta ,
16
+ Timestamp ,
17
+ )
14
18
from pandas .util ._validators import check_dtype_backend
15
19
16
20
from pandas .core .dtypes .cast import maybe_downcast_numeric
@@ -189,6 +193,8 @@ def to_numeric(
189
193
return float (arg )
190
194
if is_number (arg ):
191
195
return arg
196
+ if isinstance (arg , (Timedelta , Timestamp )):
197
+ return arg ._value
192
198
is_scalars = True
193
199
values = np .array ([arg ], dtype = "O" )
194
200
elif getattr (arg , "ndim" , 1 ) > 1 :
Original file line number Diff line number Diff line change @@ -384,6 +384,21 @@ def test_timedelta(transform_assert_equal):
384
384
assert_equal (result , expected )
385
385
386
386
387
+ @pytest .mark .parametrize (
388
+ "scalar" ,
389
+ [
390
+ pd .Timedelta (1 , "D" ),
391
+ pd .Timestamp ("2017-01-01T12" ),
392
+ pd .Timestamp ("2017-01-01T12" , tz = "US/Pacific" ),
393
+ ],
394
+ )
395
+ def test_timedelta_timestamp_scalar (scalar ):
396
+ # GH#59944
397
+ result = to_numeric (scalar )
398
+ expected = to_numeric (Series (scalar ))[0 ]
399
+ assert result == expected
400
+
401
+
387
402
def test_period (request , transform_assert_equal ):
388
403
transform , assert_equal = transform_assert_equal
389
404
You can’t perform that action at this time.
0 commit comments