Skip to content

Conversation

@kirit93
Copy link
Contributor

@kirit93 kirit93 commented Dec 8, 2017

Fixes #546


if pos >= len_str:
return components, pos
raise ValueError('YYYYMM or YYYY-MM is an invalid ISO 8601 format')
Copy link
Member

Choose a reason for hiding this comment

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

YYYY-MM is very valid. It is only YYYYMM that is not valid (because it creates an ambiguity between ISO-8601 dates and non-ISO8601 YYMMDD triplets.

Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

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

I think you've misunderstood the problem. If you'd like I can write the xfail tests and you can just code against them.

return list(o)


@pytest.mark.parametrize('d,dt_fmt', __make_date_examples())
Copy link
Member

Choose a reason for hiding this comment

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

Why was this test removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this test because it's testing date strings in the format "YYYY-MM" and I thought that format was invalid as well. I'll add it back.
Just to make sure I've understood the problem correctly, date strings in the format "YYYYMM" should raise a ValueError right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

('2013-02-29', ValueError), # Not a leap year
('2014/12/03', ValueError), # Wrong separators
('2014-04-19T', ValueError), # Unknown components
('2012-02', ValueError) # Invalid ISO 8601 format
Copy link
Member

Choose a reason for hiding this comment

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

This is valid, only 201202 is invalid.

Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

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

This looks mostly fine. If you want to clean up the one test that is running twice that would be ideal, but I can also just do that myself if you'd prefer.

Thanks for the PR!

@pytest.mark.parametrize('dt', tuple(DATES))
@pytest.mark.parametrize('fmt',
['%Y%m', '%Y-%m'])
['%Y-%m', '%Y-%m'])
Copy link
Member

Choose a reason for hiding this comment

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

I think this just repeats the same test twice. Since there's only one valid year-month format, I think you can actually move fmt into the function definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

dates_no_day.append(date(1000, 11, 1))

date_no_day_fmts = ('%Y%m', '%Y-%m')
date_no_day_fmts = ['%Y-%m']
Copy link
Member

Choose a reason for hiding this comment

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

Why the change from tuple to list? I'm not married to using a tuple, just curious. (Though also this might be a situation where we can drop this parameter entirely, I'd have to read the tests more thoroughly to see).

Copy link
Contributor Author

@kirit93 kirit93 Dec 9, 2017

Choose a reason for hiding this comment

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

In the __make_data_examples() function o = it.product(dates_no_day, date_no_day_fmts) is used to create the examples, and date_no_day_fmts is a tuple with the two formats we want the date to be in. However, now we need only one format so a list with a singular element is used. This is similar to line 383.

Copy link
Member

Choose a reason for hiding this comment

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

@kirit93 I don't understand why this would make you switch to a list, though.

>>>import itertools as it
>>>from datetime import date
>>>dates_no_day = [date(1999, 12, 1), date(2016, 2, 1)]
>>>dates_no_date_fmts = ('%Y-%m',)
>>>o = it.product(dates_no_day, dates_no_date_fmts)
>>>print(list(o))
[(datetime.date(1999, 12, 1), '%Y-%m'), (datetime.date(2016, 2, 1), '%Y-%m')]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I could have left it as a tuple. I just changed it to be a list because that's how it was done in the test on line 383, no other reason.

@pganssle
Copy link
Member

pganssle commented Dec 9, 2017

@kirit93 I just re-wrote that test anyway, since product is not really the appropriate itertool in this case, so tuple vs. list doesn't matter.

I've squashed a bunch of your intermediate commits and added you to the authors file. Please review the AUTHORS.md file before I merge and let me know if you'd prefer to change how you are credited.

@pganssle pganssle added this to the 2.7.0 milestone Dec 9, 2017
@kirit93
Copy link
Contributor Author

kirit93 commented Dec 10, 2017

AUTHORS.md looks good. Thanks!

@pganssle pganssle merged commit 13799fc into dateutil:master Dec 10, 2017
@pganssle pganssle mentioned this pull request Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants