-
-
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
Conversation
@rosygupta : Thanks for the contribution! A couple of things:
|
@gfyoung thanks for reviewing the PR. Is it not possible to create a PR without the tests? Also, my PR failed the build yesterday. Could you help me figure out the reason? |
@gfyoung how can I squash all my commits post creating the PR. I realise its better to have a single commit in the PR instead of multiple? Should I close this PR and open a new one with another branch? |
Not sure what you mean by this. Could you clarify?
Why don't we wait until your builds right now finish, and I can look.
Aesthetically, that is true. However, I wouldn't worry too much. When maintainers merge, they will squash for you. However, if you're interested, this SO link should help. And NO, do not close this PR (in general, it is always better to clean up what you've already created than it is to start from scratch). |
@gfyoung Thanks for clarifying. I mean this PR will be accepted only if the tests that you recommended me to write are pushed here? |
"only if" is a little strong, but at this point, those would certainly be tests I would add in order to get it closer to merge-ability. |
@gfyoung that clears the doubt. The build just failed. If you could look into it. |
ordinal = (iso_week * 7) + iso_weekday - correction | ||
# ordinal may be negative or 0 now, which means the date is in the previous | ||
# calendar year | ||
if ordinal < 1: |
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.
so want to have a test case that exercises both of these clauses
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.
can you mark which test case this is below with a comment
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.
@pytest.mark.parametrize("s, _format, dt", [
-
['2015-1-1', '%G-%V-%u', datetime(2014, 12, 29, 0, 0)],
-
['2015-1-4', '%G-%V-%u', datetime(2015, 1, 1, 0, 0)],
-
['2015-1-7', '%G-%V-%u', datetime(2015, 1, 4, 0, 0)]
-
])----- out of these;
-
['2015-1-4', '%G-%V-%u', datetime(2015, 1, 1, 0, 0)],
this one tests this case!
@@ -175,6 +175,14 @@ def test_to_datetime_format_weeks(self): | |||
|
|||
class TestToDatetime(object): | |||
|
|||
def test_to_datetime_iso_week_year_format(self): |
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.
- do these cases separately.
- need tests for each of the ValueErrors that you are raising
- 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.
@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.
I mean exactly this. you have an if clause so we need a test for both cases.
ordinal may be negative or 0 now, which means the date is in the previous calendar year
Not entirely why the clipboard test is failing. Seems like a spurious failure @jreback ? |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use tm.assert_raises_regex
instead. It is stronger to test not only the Exception raised but also the message that comes along with it.
@@ -175,6 +175,42 @@ def test_to_datetime_format_weeks(self): | |||
|
|||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's parametrize this using pytest
:
@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.
Codecov Report
@@ Coverage Diff @@
## master #16661 +/- ##
==========================================
+ Coverage 90.93% 90.93% +<.01%
==========================================
Files 161 161
Lines 49266 49269 +3
==========================================
+ Hits 44801 44804 +3
Misses 4465 4465
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16661 +/- ##
==========================================
- Coverage 90.93% 90.92% -0.02%
==========================================
Files 161 161
Lines 49266 49284 +18
==========================================
+ Hits 44801 44811 +10
- Misses 4465 4473 +8
Continue to review full report at Codecov.
|
On Travis, you have style-check errors. Code will not be merged unless it conforms with the Python style guide as per PEP8 style guidelines. You can check yourself by install On Circle, it appears that your error messages don't match the ones being raised, which is a little weird given that they passed on Appveyor and Travis. However, you should still try to figure out, if possible, why the test you're testing for doesn't work. |
dtype=object) | ||
arr = np.array( | ||
[ | ||
us_eastern.localize( |
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.
don't change unrelated things
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.
pls add a release note. 0.21.0 in enhancements.
@@ -3701,13 +3704,14 @@ def array_strptime(ndarray[object] values, object fmt, | |||
raise ValueError("time data %r does not match format " | |||
"%r (search)" % (values[i], fmt)) | |||
|
|||
iso_year = -1 |
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.
these need to be defined above in the cdef (iso_year/iso_week)
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.
done
can you rebase / update according to comments |
Hello @rosygupta! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on July 19, 2017 at 20:15 Hours UTC |
@rosygupta : These changes LGTM. Just need to resolve the merge conflict, and it should be on its way! |
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.
small comment on the whatsnew note. too bad this: #16669 is not done, otherwise would have a place to add a version added note.
@@ -24,6 +24,9 @@ New features | |||
<https://www.python.org/dev/peps/pep-0519/>`_ on most readers and writers (:issue:`13823`) | |||
- Added `__fspath__` method to :class`:pandas.HDFStore`, :class:`pandas.ExcelFile`, | |||
and :class:`pandas.ExcelWriter` to work properly with the file system path protocol (:issue:`13823`) | |||
- Added 'iso week year support to to_datetime', added method '_calc_julian_from_V' |
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.
this is not clear. more like, added support for %G
strptime directive in parsing datetimes; no need to mention the second part which is purely internal.
IIRC this was pretty reasonable. can you rebase / update to comments? |
can you rebase |
closing as this is stale. |
ENH: to_datetime support iso week year
git diff upstream/master --name-only -- '*.py' | flake8 --diff