-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: misleading message when using to_datetime with format='%V %a' #50309
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,38 @@ def array_strptime( | |
raise ValueError("Cannot use '%W' or '%U' without day and year") | ||
elif "%Z" in fmt and "%z" in fmt: | ||
raise ValueError("Cannot parse both %Z and %z") | ||
elif "%j" in fmt and "%G" in fmt: | ||
raise ValueError("Day of the year directive '%j' is not " | ||
"compatible with ISO year directive '%G'. " | ||
"Use '%Y' instead.") | ||
elif "%G" in fmt and ( | ||
"%V" not in fmt | ||
or not ( | ||
"%A" in fmt | ||
or "%a" in fmt | ||
or "%w" in fmt | ||
or "%u" in fmt | ||
) | ||
): | ||
raise ValueError("ISO year directive '%G' must be used with " | ||
"the ISO week directive '%V' and a weekday " | ||
"directive '%A', '%a', '%w', or '%u'.") | ||
elif "%V" in fmt and "%Y" in fmt: | ||
raise ValueError("ISO week directive '%V' is incompatible with " | ||
"the year directive '%Y'. Use the ISO year " | ||
"'%G' instead.") | ||
elif "%V" in fmt and ( | ||
"%G" not in fmt | ||
or not ( | ||
"%A" in fmt | ||
or "%a" in fmt | ||
or "%w" in fmt | ||
or "%u" in fmt | ||
) | ||
): | ||
raise ValueError("ISO week directive '%V' must be used with " | ||
"the ISO year directive '%G' and a weekday " | ||
"directive '%A', '%a', '%w', or '%u'.") | ||
|
||
global _TimeRE_cache, _regex_cache | ||
with _cache_lock: | ||
|
@@ -328,26 +360,6 @@ def array_strptime( | |
weekday = int(found_dict["u"]) | ||
weekday -= 1 | ||
|
||
# don't assume default values for ISO week/year | ||
if iso_year != -1: | ||
if iso_week == -1 or weekday == -1: | ||
raise ValueError("ISO year directive '%G' must be used with " | ||
"the ISO week directive '%V' and a weekday " | ||
"directive '%A', '%a', '%w', or '%u'.") | ||
if julian != -1: | ||
raise ValueError("Day of the year directive '%j' is not " | ||
"compatible with ISO year directive '%G'. " | ||
"Use '%Y' instead.") | ||
Comment on lines
-338
to
-340
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one was never tested to begin with - have added a test to cover it |
||
elif year != -1 and week_of_year == -1 and iso_week != -1: | ||
if weekday == -1: | ||
raise ValueError("ISO week directive '%V' must be used with " | ||
"the ISO year directive '%G' and a weekday " | ||
"directive '%A', '%a', '%w', or '%u'.") | ||
else: | ||
raise ValueError("ISO week directive '%V' is incompatible with " | ||
"the year directive '%Y'. Use the ISO year " | ||
"'%G' instead.") | ||
|
||
# If we know the wk of the year and what day of that wk, we can figure | ||
# out the Julian day of the year. | ||
if julian == -1 and weekday != -1: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -629,8 +629,8 @@ def test_to_datetime_iso_week_year_format(self, s, _format, dt): | |
"msg, s, _format", | ||
[ | ||
[ | ||
"ISO week directive '%V' must be used with the ISO year directive " | ||
"'%G' and a weekday directive '%A', '%a', '%w', or '%u'.", | ||
"ISO week directive '%V' is incompatible with the year directive " | ||
"'%Y'. Use the ISO year '%G' instead.", | ||
Comment on lines
-632
to
+633
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've put the "%Y and %V used together" check before the "%V used without both %G and weekday directive", as I think it produces a more useful error message in this case |
||
"1999 50", | ||
"%Y %V", | ||
], | ||
|
@@ -706,10 +706,46 @@ def test_to_datetime_iso_week_year_format(self, s, _format, dt): | |
"20", | ||
"%V", | ||
], | ||
[ | ||
"ISO week directive '%V' must be used with the ISO year directive " | ||
"'%G' and a weekday directive '%A', '%a', '%w', or '%u'.", | ||
"1999 51 Sunday", | ||
"%V %A", | ||
], | ||
[ | ||
"ISO week directive '%V' must be used with the ISO year directive " | ||
"'%G' and a weekday directive '%A', '%a', '%w', or '%u'.", | ||
"1999 51 Sun", | ||
"%V %a", | ||
], | ||
[ | ||
"ISO week directive '%V' must be used with the ISO year directive " | ||
"'%G' and a weekday directive '%A', '%a', '%w', or '%u'.", | ||
"1999 51 1", | ||
"%V %w", | ||
], | ||
[ | ||
"ISO week directive '%V' must be used with the ISO year directive " | ||
"'%G' and a weekday directive '%A', '%a', '%w', or '%u'.", | ||
"1999 51 1", | ||
"%V %u", | ||
], | ||
[ | ||
"Day of the year directive '%j' is not compatible with ISO year " | ||
"directive '%G'. Use '%Y' instead.", | ||
"1999 50", | ||
"%G %j", | ||
], | ||
[ | ||
"ISO week directive '%V' must be used with the ISO year directive " | ||
"'%G' and a weekday directive '%A', '%a', '%w', or '%u'.", | ||
"20 Monday", | ||
"%V %A", | ||
], | ||
Comment on lines
+739
to
+744
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on upstream/main, this one would show |
||
], | ||
) | ||
def test_error_iso_week_year(self, msg, s, _format): | ||
# See GH#16607 | ||
# See GH#16607, #50308 | ||
# This test checks for errors thrown when giving the wrong format | ||
# However, as discussed on PR#25541, overriding the locale | ||
# causes a different error to be thrown due to the format being | ||
|
Uh oh!
There was an error while loading. Please reload this page.