-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: to_datetime support iso week year (16607) #16661
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 1 commit
274a8e0
7b622ed
437dea9
e349ccc
9f53a99
89eaf1a
aff309c
71a1c13
71bc348
028e978
cf58798
137b724
250e2cc
652bb90
c249f66
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 |
---|---|---|
|
@@ -177,12 +177,40 @@ class TestToDatetime(object): | |
|
||
def test_to_datetime_iso_week_year_format(self): | ||
data = [ | ||
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. Let's parametrize this using @pytest.mark.parametrize(...)
def test_to_datetime_iso_week_year_format(s, _format, dt):
... Also note that I use "_format" instead of "format" because as a personal preference, I prefer not to use keywords when creating local variables. |
||
['2015-53-1', '%G-%V-%u', | ||
datetime(2015, 12, 28, 0, 0)] | ||
['2015-1-1', '%G-%V-%u', | ||
datetime(2014, 12, 29, 0, 0)], #negative ordinal (date in previous year) | ||
['2015-1-4', '%G-%V-%u', | ||
datetime(2015, 1, 1, 0, 0)], | ||
['2015-1-7', '%G-%V-%u', | ||
datetime(2015, 1, 4, 0, 0)] | ||
] | ||
for s, format, dt in data: | ||
assert to_datetime(s, format=format) == dt | ||
|
||
def test_ValueError_iso_week_year(self): | ||
# 1. ISO week (%V) is specified, but the year is specified with %Y | ||
# instead of %G | ||
with pytest.raises(ValueError): | ||
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. Let's use |
||
to_datetime("1999 50", format="%Y %V") | ||
# 2. ISO year (%G) and ISO week (%V) are specified, but weekday is not | ||
with pytest.raises(ValueError): | ||
to_datetime("1999 51", format="%G %V") | ||
# 3. ISO year (%G) and weekday are specified, but ISO week (%V) is not | ||
for w in ('A', 'a', 'w', 'u'): | ||
with pytest.raises(ValueError): | ||
to_datetime("1999 51", format="%G %{}".format(w)) | ||
# 4. ISO year is specified alone | ||
with pytest.raises(ValueError): | ||
to_datetime("2015", format="%G") | ||
# 5. Julian/ordinal day (%j) is specified with %G, but not %Y | ||
with pytest.raises(ValueError): | ||
to_datetime("1999 256", format="%G %j") | ||
#6. ISO week (%V) and weekday are specified, but ISO year (%G) is not | ||
for w in ('A', 'a', 'w', 'u'): | ||
with pytest.raises(ValueError): | ||
to_datetime("51 11", format="%V %{}".format(w)) | ||
|
||
|
||
def test_to_datetime_dt64s(self): | ||
in_bound_dts = [ | ||
np.datetime64('2000-01-01'), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback Can you please clarify this--> as I indicated above, need to exercise the paths in the code.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#16661 (comment)
I mean exactly this. you have an if clause so we need a test for both cases.