Skip to content

to_datetime, inconsistent behavior with invalid dates. #10154

Closed
@vincentdavis

Description

@vincentdavis

Consider Feb 29 1991 (2291991) and March 32 1991 (3321991), Both are invalid dates.

pd.to_datetime(2291991, format="%m%d%Y", coerce=True, exact=True)

Returns a TypeError: ValueError: day is out of range for month

While

pd.to_datetime(3321991, format="%m%d%Y", coerce=True, exact=True)

Returns NaT. Which is what I would expect.

In any case they should return the same error or value

Joris Van den Bossche pointed out on the mailing list:
"It has something to do with the number of the day, only values above 31 convert to NaT, 31 or lower raises the error (eg also 31 April raise error instead of giving NaT)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions