Skip to content

Commit 9ecb1da

Browse files
yuanx749pmhatre1
authored andcommitted
BUG: guess_datetime_format fails to infer timeformat (pandas-dev#57471)
1 parent dfae702 commit 9ecb1da

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ Styler
286286

287287
Other
288288
^^^^^
289+
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
289290
- 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`)
290291
- 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`)
291292

pandas/_libs/tslibs/parsing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
915915
(("year", "month", "day", "hour"), "%Y%m%d%H", 0),
916916
(("year", "month", "day"), "%Y%m%d", 0),
917917
(("hour", "minute", "second"), "%H%M%S", 0),
918-
(("hour", "minute"), "%H%M", 0),
919918
(("year",), "%Y", 0),
919+
(("hour", "minute"), "%H%M", 0),
920920
(("month",), "%B", 0),
921921
(("month",), "%b", 0),
922922
(("month",), "%m", 2),

pandas/tests/tslibs/test_parsing.py

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def test_parsers_month_freq(date_str, expected):
218218
("Tue 24 Aug 2021 01:30:48 AM", "%a %d %b %Y %I:%M:%S %p"),
219219
("Tuesday 24 Aug 2021 01:30:48 AM", "%A %d %b %Y %I:%M:%S %p"),
220220
("27.03.2003 14:55:00.000", "%d.%m.%Y %H:%M:%S.%f"), # GH50317
221+
("2023-11-09T20:23:46Z", "%Y-%m-%dT%H:%M:%S%z"), # GH57452
221222
],
222223
)
223224
def test_guess_datetime_format_with_parseable_formats(string, fmt):

0 commit comments

Comments
 (0)