Skip to content

ERR: "day out of range" doesn't show position of error #50464

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

Merged
merged 2 commits into from
Dec 28, 2022

Conversation

MarcoGorelli
Copy link
Member

Haven't added a whatsnew note, as this can be considered a follow-up to #50366

@MarcoGorelli MarcoGorelli marked this pull request as ready for review December 28, 2022 12:22
raise ValueError(f"time data \"{val}\" at position {i} doesn't "
raise ValueError(f"time data \"{val}\" doesn't "
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than trying to set as position {i} in each place where an error can occur, it's more reliable to just preprend at position {i} when an error is caught (see below)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done the same in tslib.pyx because when format is provided, that code is going to be called here anyway in #50242
So for now I've just made sure the error messages match for the two paths

Comment on lines +2579 to +2589
(
"2015-04-31",
"%Y-%m-%d",
'^time data "2015-04-31" doesn\'t match format "%Y-%m-%d", '
"at position 0$",
),
(
"2015-31-04",
"%Y-%d-%m",
"^day is out of range for month, at position 0$",
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note how the ISO and non-ISO messages don't quite match yet - this PR just ensures that they both show the position of the error

#50242 will ensure that the messages match

@mroeschke mroeschke added Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas labels Dec 28, 2022
@mroeschke mroeschke added this to the 2.0 milestone Dec 28, 2022
@mroeschke mroeschke merged commit 445bed9 into pandas-dev:main Dec 28, 2022
@mroeschke
Copy link
Member

Thanks @MarcoGorelli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ERR: "day out of range" doesn't show position of error
2 participants