@@ -969,7 +969,7 @@ class Timedelta(_Timedelta):
969
969
----------
970
970
value : Timedelta, timedelta, np.timedelta64, string, or integer
971
971
unit : string, {'ns', 'us', 'ms', 's', 'm', 'h', 'D'}, optional
972
- Denote the unit of the input, if input is an integer. Default 'ns'.
972
+ Denote the unit of the input, if input is an integer/float . Default 'ns'.
973
973
days, seconds, microseconds,
974
974
milliseconds, minutes, hours, weeks : numeric, optional
975
975
Values for construction in compat with datetime.timedelta.
@@ -1018,8 +1018,15 @@ class Timedelta(_Timedelta):
1018
1018
elif len (value) > 0 and value[0 ] == ' P' :
1019
1019
value = parse_iso_format_string(value)
1020
1020
else :
1021
- value = parse_timedelta_string(value, unit)
1022
- value = np.timedelta64(value)
1021
+ try :
1022
+ value = float (value)
1023
+ except ValueError :
1024
+ value = parse_timedelta_string(value)
1025
+ value = np.timedelta64(value)
1026
+ else :
1027
+ if unit is None :
1028
+ raise ValueError (" Cannot convert float string without unit." )
1029
+ value = convert_to_timedelta64(value, unit)
1023
1030
elif PyDelta_Check(value):
1024
1031
value = convert_to_timedelta64(value, ' ns' )
1025
1032
elif is_timedelta64_object(value):
0 commit comments