From a8bb352c79135896c483d379b8ae7417c05f9693 Mon Sep 17 00:00:00 2001 From: Vijay Sarathy Date: Thu, 16 Oct 2025 18:37:06 -0400 Subject: [PATCH 1/2] Added test for Timedelta constructor to acceptWeek 'W' as a parsed string suffix --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/tests/scalar/timedelta/test_timedelta.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 0045fc7b9c221..e446b6e27bdd8 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -979,6 +979,7 @@ Timedelta ^^^^^^^^^ - Accuracy improvement in :meth:`Timedelta.to_pytimedelta` to round microseconds consistently for large nanosecond based Timedelta (:issue:`57841`) - Bug in :class:`Timedelta` constructor failing to raise when passed an invalid keyword (:issue:`53801`) +- Bug in :class:`Timedelta` constructor failing to recognize Week ('W') as a parsed string suffix (:issue:`12691`) - Bug in :meth:`DataFrame.cumsum` which was raising ``IndexError`` if dtype is ``timedelta64[ns]`` (:issue:`57956`) - Bug in multiplication operations with ``timedelta64`` dtype failing to raise ``TypeError`` when multiplying by ``bool`` objects or dtypes (:issue:`58054`) diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index da22e49b24e54..d9e42bbaf910d 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -727,3 +727,13 @@ def test_to_pytimedelta_large_values(): result = td.to_pytimedelta() expected = timedelta(days=13343, seconds=86304, microseconds=609987) assert result == expected + + +def test_timedelta_week_suffix(): + # GH#12691 ensure 'W' suffix works as a string passed to Timedelta + expected = Timedelta("7 days") + result = Timedelta(1, unit="W") + assert result == expected + + result = Timedelta("1W") + assert result == expected From 550959dcee273fcbc078a294a6a38dead3a9a21a Mon Sep 17 00:00:00 2001 From: Vijay Sarathy Date: Thu, 16 Oct 2025 21:06:48 -0400 Subject: [PATCH 2/2] Update doc/source/whatsnew/v3.0.0.rst Removing unit test from what's new Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- doc/source/whatsnew/v3.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index e446b6e27bdd8..0045fc7b9c221 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -979,7 +979,6 @@ Timedelta ^^^^^^^^^ - Accuracy improvement in :meth:`Timedelta.to_pytimedelta` to round microseconds consistently for large nanosecond based Timedelta (:issue:`57841`) - Bug in :class:`Timedelta` constructor failing to raise when passed an invalid keyword (:issue:`53801`) -- Bug in :class:`Timedelta` constructor failing to recognize Week ('W') as a parsed string suffix (:issue:`12691`) - Bug in :meth:`DataFrame.cumsum` which was raising ``IndexError`` if dtype is ``timedelta64[ns]`` (:issue:`57956`) - Bug in multiplication operations with ``timedelta64`` dtype failing to raise ``TypeError`` when multiplying by ``bool`` objects or dtypes (:issue:`58054`)