Skip to content

BUG: datetime parsing: error message indicating position of conflicting string is wrong for larger data #55345

Open
@jorisvandenbossche

Description

@jorisvandenbossche

Using the latest pandas main (and also happens on released version 2.1.1):

In [1]: pd.to_datetime(["2012-01-01"] * 49 + ["2012-01-02 09"])
...
ValueError: unconverted data remains when parsing with format "%Y-%m-%d": " 09", at position 49. You might want to try:
    - passing `format` if your strings have a consistent format;
    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.

In [2]: pd.to_datetime(["2012-01-01"] * 50 + ["2012-01-02 09"])
...
ValueError: unconverted data remains when parsing with format "%Y-%m-%d": " 09", at position 1. You might want to try:
...

In the first case, it correctly says "position 49", while in the second case (n > 50), it confusingly says "position 1".

Metadata

Metadata

Assignees

Labels

BugDatetimeDatetime data dtypeError ReportingIncorrect or improved errors from pandas

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions