From 3786f8b1cb31afa3e6cd0923e86fa0996158c40a Mon Sep 17 00:00:00 2001 From: Michael Marino Date: Fri, 16 Oct 2020 14:11:33 +0200 Subject: [PATCH] Remove limitation that seconds has two or fewer digits - ISO 8601 doesn't seem to express that explicit limitations here are necessary. --- pandas/_libs/tslibs/timedeltas.pyx | 7 ++----- pandas/tests/scalar/timedelta/test_constructors.py | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index c369ed75a550b..c6b47d09cf0bd 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -662,11 +662,8 @@ cdef inline int64_t parse_iso_format_string(str ts) except? -1: r = timedelta_from_spec(number, '0', dec_unit) result += timedelta_as_neg(r, neg) else: # seconds - if len(number) <= 2: - r = timedelta_from_spec(number, '0', 'S') - result += timedelta_as_neg(r, neg) - else: - raise ValueError(err_msg) + r = timedelta_from_spec(number, '0', 'S') + result += timedelta_as_neg(r, neg) else: raise ValueError(err_msg) diff --git a/pandas/tests/scalar/timedelta/test_constructors.py b/pandas/tests/scalar/timedelta/test_constructors.py index 70ddff35d6e2a..06bdb8a6cf0a2 100644 --- a/pandas/tests/scalar/timedelta/test_constructors.py +++ b/pandas/tests/scalar/timedelta/test_constructors.py @@ -234,6 +234,8 @@ def test_overflow_on_construction(): ("P1D", Timedelta(days=1)), ("P1DT1H", Timedelta(days=1, hours=1)), ("P1W", Timedelta(days=7)), + ("PT300S", Timedelta(seconds=300)), + ("P1DT0H0M00000000000S", Timedelta(days=1)), ], ) def test_iso_constructor(fmt, exp): @@ -247,7 +249,6 @@ def test_iso_constructor(fmt, exp): "PDTHMS", "P0DT999H999M999S", "P1DT0H0M0.0000000000000S", - "P1DT0H0M00000000000S", "P1DT0H0M0.S", ], )