s = '1-5.888938903808594e-05', default = 'seconds'
1864
1865
def parse_timedelta(s, default="seconds"):
1866
"""Parse timedelta string to number of seconds
1867
1868
Examples
1869
--------
1870
>>> from datetime import timedelta
1871
>>> from dask.utils import parse_timedelta
1872
>>> parse_timedelta('3s')
1873
3
1874
>>> parse_timedelta('3.5 seconds')
1875
3.5
1876
>>> parse_timedelta('300ms')
1877
0.3
1878
>>> parse_timedelta(timedelta(seconds=3)) # also supports timedeltas
1879
3
1880
"""
1881
if s is None:
1882
return None
1883
if isinstance(s, timedelta):
1884
s = s.total_seconds()
1885
return int(s) if int(s) == s else s
1886
if isinstance(s, Number):
1887
s = str(s)
1888
s = s.replace(" ", "")
1889
if not s[0].isdigit():
1890
s = "1" + s
1891
1892
for i in range(len(s) - 1, -1, -1):
1893
if not s[i].isalpha():
1894
break
1895
index = i + 1
1896
1897
prefix = s[:index]
1898
suffix = s[index:] or default
1899
1900
> n = float(prefix)
1901
E ValueError: could not convert string to float: '1-5.888938903808594e-05'
1902
1903
../../../miniconda3/envs/dask-distributed/lib/python3.8/site-packages/dask/utils.py:1468: ValueError
https://github.com/dask/distributed/runs/2088606636
https://github.com/dask/distributed/runs/2088606636