Skip to content

BUG: Timedelta does not accept ISO 8601 duration strings with 3 digit hours or minutes #51820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
rosstitmarsh opened this issue Mar 7, 2023 · 3 comments
Closed
2 of 3 tasks
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@rosstitmarsh
Copy link

rosstitmarsh commented Mar 7, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
pd.Timedelta('PT100H')

Issue Description

An ISO 8601 duration string raises a ValueError when the hours or minutes part is longer than 2 digits.

There is an explicit check for the length of the hours and minute parts in the parser

if c in ["H", "M"] and len(number) > 2:

A duration of 100 hours is obviously valid, pd.Timedelta(100, unit='hours') works like expected.

Expected Behavior

import pandas as pd
assert pd.Timedelta('PT100H') == pd.Timedelta(100, unit='hours')
assert pd.Timedelta('PT100M') == pd.Timedelta(100, unit='minutes')

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.11.1.final.0
python-bits : 64

pandas : 1.5.3
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@rosstitmarsh rosstitmarsh added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 7, 2023
@jbrockmendel
Copy link
Member

PR would be welcome.

What is "PT" in this context?

@rosstitmarsh
Copy link
Author

P prefixes all ISO 8601 durations
T separates the years/months/day parts from the hour/minute/second parts. As P1M is one month but PT1M is 1 minute.

@rosstitmarsh
Copy link
Author

Closing in favour of #51882

@rosstitmarsh rosstitmarsh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants