pd.to_timedelta not parsing iso-formatted strings · Issue #21877 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
delta = pd.Timedelta(1e9).isoformat() pd.to_timedelta(delta) Traceback (most recent call last): File "pandas/_libs/tslibs/timedeltas.pyx", line 480, in pandas._libs.tslibs.timedeltas.timedelta_from_spec unit = timedelta_abbrevs[unit.lower()] KeyError: 'p'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "", line 1, in File "/home/sergey/projects/pandas/pandas/core/tools/timedeltas.py", line 99, in to_timedelta box=box, errors=errors) File "/home/sergey/projects/pandas/pandas/core/tools/timedeltas.py", line 145, in _coerce_scalar_to_timedelta_type result = convert_to_timedelta64(r, unit) File "pandas/_libs/tslibs/timedeltas.pyx", line 139, in pandas._libs.tslibs.timedeltas.convert_to_timedelta64 cpdef convert_to_timedelta64(object ts, object unit): File "pandas/_libs/tslibs/timedeltas.pyx", line 186, in pandas._libs.tslibs.timedeltas.convert_to_timedelta64 ts = np.timedelta64(parse_timedelta_string(ts)) File "pandas/_libs/tslibs/timedeltas.pyx", line 345, in pandas._libs.tslibs.timedeltas.parse_timedelta_string r = timedelta_from_spec(number, frac, unit) File "pandas/_libs/tslibs/timedeltas.pyx", line 482, in pandas._libs.tslibs.timedeltas.timedelta_from_spec raise ValueError("invalid abbreviation: {0}".format(unit)) ValueError: invalid abbreviation: P
Problem description
#19191 added support for iso-formatted strings to pd.Timedelta
constructor but pd.to_timedelta
cannot parse such strings yet.
Expected Output
Output of pd.show_versions()
INSTALLED VERSIONS
commit: bdb6168
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-45-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.24.0.dev0+305.gbdb61688a
pytest: 3.6.2
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.3
numpy: 1.14.5
scipy: 1.1.0
pyarrow: 0.9.0
xarray: 0.10.7
IPython: 6.4.0
sphinx: 1.7.5
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.5
feather: 0.4.0
matplotlib: 2.2.2
openpyxl: 2.5.4
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.5
lxml: 4.2.2
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.8
pymysql: 0.8.1
psycopg2: None
jinja2: 2.10
s3fs: 0.1.5
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None
gcsfs: 0.1.0