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