diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index a77e93c4ab4be..edcf83953a14e 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -287,6 +287,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`) 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), 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):