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 1111 lib ,
1212 missing as libmissing ,
1313)
14+ from pandas ._libs .tslibs import (
15+ Timedelta ,
16+ Timestamp ,
17+ )
1418from pandas .util ._validators import check_dtype_backend
1519
1620from pandas .core .dtypes .cast import maybe_downcast_numeric
@@ -189,6 +193,8 @@ def to_numeric(
189193 return float (arg )
190194 if is_number (arg ):
191195 return arg
196+ if isinstance (arg , (Timedelta , Timestamp )):
197+ return arg ._value
192198 is_scalars = True
193199 values = np .array ([arg ], dtype = "O" )
194200 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):
384384 assert_equal (result , expected )
385385
386386
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+
387402def test_period (request , transform_assert_equal ):
388403 transform , assert_equal = transform_assert_equal
389404
You can’t perform that action at this time.
0 commit comments