Skip to content

BUG: fix for datetime parse error for more than 50 rows #55411

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 4 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: 2 additions & 0 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def _maybe_cache(

unique_dates = unique(arg)
if len(unique_dates) < len(arg):
# GH-55345 checking for parse errors
convert_listlike(arg, format)
cache_dates = convert_listlike(unique_dates, format)
# GH#45319
try:
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3686,3 +3686,11 @@ def test_to_datetime_with_empty_str_utc_false_offsets_and_format_mixed():
to_datetime(
["2020-01-01 00:00+00:00", "2020-01-01 00:00+02:00", ""], format="mixed"
)


def test_to_datetime_parse_error_for_more_than_50rows():
# GH-55345
msg = 'when parsing with format "%Y-%m-%d": " 09", at position 50.'

with pytest.raises(ValueError, match=msg):
to_datetime(["2012-01-01"] * 50 + ["2012-01-02 09"])