@@ -1081,7 +1081,7 @@ class Timedelta(_Timedelta):
1081
1081
----------
1082
1082
value : Timedelta, timedelta, np.timedelta64, string, or integer
1083
1083
unit : string, {'ns', 'us', 'ms', 's', 'm', 'h', 'D'}, optional
1084
- Denote the unit of the input, if input is an integer. Default 'ns'.
1084
+ Denote the unit of the input, if input is an integer/float . Default 'ns'.
1085
1085
days, seconds, microseconds,
1086
1086
milliseconds, minutes, hours, weeks : numeric, optional
1087
1087
Values for construction in compat with datetime.timedelta.
@@ -1119,8 +1119,15 @@ class Timedelta(_Timedelta):
1119
1119
if len (value) > 0 and value[0 ] == ' P' :
1120
1120
value = parse_iso_format_string(value)
1121
1121
else :
1122
- value = parse_timedelta_string(value)
1123
- value = np.timedelta64(value)
1122
+ try :
1123
+ value = float (value)
1124
+ except ValueError :
1125
+ value = parse_timedelta_string(value)
1126
+ value = np.timedelta64(value)
1127
+ else :
1128
+ if unit is None :
1129
+ raise ValueError (" Cannot convert float string without unit." )
1130
+ value = convert_to_timedelta64(value, unit)
1124
1131
elif PyDelta_Check(value):
1125
1132
value = convert_to_timedelta64(value, ' ns' )
1126
1133
elif is_timedelta64_object(value):
0 commit comments