Skip to content

BUG: Add AM/PM token support on guess_datetime_format #53244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Conversion
- Bug in :meth:`DataFrame.__repr__` incorrectly raising a ``TypeError`` when the dtype of a column is ``np.record`` (:issue:`48526`)
- Bug in :meth:`DataFrame.info` raising ``ValueError`` when ``use_numba`` is set (:issue:`51922`)
- Bug in :meth:`DataFrame.insert` raising ``TypeError`` if ``loc`` is ``np.int64`` (:issue:`53193`)
-
- Bug in :meth:`datetimes._guess_datetime_format` if contains "AM" / "PM" tokens (:issue:`53147`)

Strings
^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,6 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
(("tzinfo",), "%Z", 0),
(("day_of_week",), "%a", 0),
(("day_of_week",), "%A", 0),
(("meridiem",), "%p", 0),
]

if dayfirst:
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2942,6 +2942,7 @@ class TestDatetimeParsingWrappers:
("2005-11-09 10:15", datetime(2005, 11, 9, 10, 15)),
("2005-11-09 08H", datetime(2005, 11, 9, 8, 0)),
("2005/11/09 10:15", datetime(2005, 11, 9, 10, 15)),
("2005/11/09 10:15:32", datetime(2005, 11, 9, 10, 15, 32)),
("2005/11/09 08H", datetime(2005, 11, 9, 8, 0)),
("Thu Sep 25 10:36:28 2003", datetime(2003, 9, 25, 10, 36, 28)),
("Thu Sep 25 2003", datetime(2003, 9, 25)),
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/tslibs/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ def test_parsers_month_freq(date_str, expected):
("2011-12-30T00:00:00.000000+9:0", "%Y-%m-%dT%H:%M:%S.%f%z"),
("2011-12-30T00:00:00.000000+09:", None),
("2011-12-30 00:00:00.000000", "%Y-%m-%d %H:%M:%S.%f"),
("Tue 24 Aug 2021 01:30:48 AM", "%a %d %b %Y %H:%M:%S %p"),
("Tuesday 24 Aug 2021 01:30:48 AM", "%A %d %b %Y %H:%M:%S %p"),
("Tue 24 Aug 2021 01:30:48", "%a %d %b %Y %H:%M:%S"),
("Tuesday 24 Aug 2021 01:30:48", "%A %d %b %Y %H:%M:%S"),
("Tue 24 Aug 2021 01:30:48 AM", None),
("Tuesday 24 Aug 2021 01:30:48 AM", None),
("27.03.2003 14:55:00.000", "%d.%m.%Y %H:%M:%S.%f"), # GH50317
],
)
Expand Down