From 72589878d65ad1cc85fde4d394c84805e1cdc6e9 Mon Sep 17 00:00:00 2001 From: yuanx749 Date: Sat, 17 Feb 2024 20:58:53 +0800 Subject: [PATCH 1/3] Add test --- pandas/tests/tslibs/test_parsing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/tslibs/test_parsing.py b/pandas/tests/tslibs/test_parsing.py index d8f23156bd4d4..4dd9d7b20be69 100644 --- a/pandas/tests/tslibs/test_parsing.py +++ b/pandas/tests/tslibs/test_parsing.py @@ -218,6 +218,7 @@ def test_parsers_month_freq(date_str, expected): ("Tue 24 Aug 2021 01:30:48 AM", "%a %d %b %Y %I:%M:%S %p"), ("Tuesday 24 Aug 2021 01:30:48 AM", "%A %d %b %Y %I:%M:%S %p"), ("27.03.2003 14:55:00.000", "%d.%m.%Y %H:%M:%S.%f"), # GH50317 + ("2023-11-09T20:23:46Z", "%Y-%m-%dT%H:%M:%S%z"), # GH57452 ], ) def test_guess_datetime_format_with_parseable_formats(string, fmt): From e0c141d493dee8f1a2898ba40fb7503d591a0a86 Mon Sep 17 00:00:00 2001 From: yuanx749 Date: Sat, 17 Feb 2024 21:18:34 +0800 Subject: [PATCH 2/3] Fix guess_datetime_format --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 483cf659080ea..4851dc9102d29 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -279,6 +279,7 @@ Styler Other ^^^^^ +- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`) - Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`) - Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`) From 1463cfd50822b6cf9848a3884895edcd8a8c5194 Mon Sep 17 00:00:00 2001 From: yuanx749 Date: Sat, 17 Feb 2024 21:48:23 +0800 Subject: [PATCH 3/3] fix --- pandas/_libs/tslibs/parsing.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 1e544a9927086..ad723df485ba6 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -915,8 +915,8 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None: (("year", "month", "day", "hour"), "%Y%m%d%H", 0), (("year", "month", "day"), "%Y%m%d", 0), (("hour", "minute", "second"), "%H%M%S", 0), - (("hour", "minute"), "%H%M", 0), (("year",), "%Y", 0), + (("hour", "minute"), "%H%M", 0), (("month",), "%B", 0), (("month",), "%b", 0), (("month",), "%m", 2),