Skip to content

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

Closed
wants to merge 15 commits into from

Conversation

rosygupta
Copy link

@rosygupta rosygupta commented Jun 10, 2017

ENH: to_datetime support iso week year

ENH: to_datetime support iso week year
ENH: to_datetime support iso week year
@rosygupta rosygupta closed this Jun 11, 2017
@rosygupta rosygupta deleted the pandas-rosy branch June 11, 2017 09:13
@rosygupta rosygupta restored the pandas-rosy branch June 11, 2017 09:15
@rosygupta rosygupta reopened this Jun 11, 2017
@rosygupta rosygupta changed the title Pandas rosy ENH: to_datetime support iso week year Jun 11, 2017
@rosygupta rosygupta changed the title ENH: to_datetime support iso week year ENH: to_datetime support iso week year (16607) Jun 11, 2017
@gfyoung
Copy link
Member

gfyoung commented Jun 11, 2017

@rosygupta : Thanks for the contribution! A couple of things:

  1. Instead of putting "yes", an "x" between the brackets will suffice, as it will render as a check-mark.

  2. Your tests will need to be more comprehensive. For starters, you should write additional tests that hit each of those ValueError messages that you added.

@rosygupta
Copy link
Author

@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?

@rosygupta
Copy link
Author

@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?

@gfyoung
Copy link
Member

gfyoung commented Jun 11, 2017

Is it not possible to create a PR without the tests?

Not sure what you mean by this. Could you clarify?

Also, my PR failed the build yesterday. Could you help me figure out the reason?

Why don't we wait until your builds right now finish, and I can look.

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?

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).

@rosygupta
Copy link
Author

rosygupta commented Jun 11, 2017

@gfyoung Thanks for clarifying. I mean this PR will be accepted only if the tests that you recommended me to write are pushed here?

@gfyoung
Copy link
Member

gfyoung commented Jun 11, 2017

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.

@rosygupta
Copy link
Author

@gfyoung that clears the doubt. The build just failed. If you could look into it.

@jreback jreback added Compat pandas objects compatability with Numpy or Python functions Datetime Datetime data dtype labels Jun 11, 2017
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:
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Author

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):
Copy link
Contributor

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.

Copy link
Author

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.?

Copy link
Contributor

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.

ordinal may be negative or 0 now, which means the date is in the previous calendar year

@gfyoung
Copy link
Member

gfyoung commented Jun 11, 2017

The build just failed. If you could look into it.

Not entirely why the clipboard test is failing. Seems like a spurious failure @jreback ?

ENH: added tests for each of the ValueError, improved checks
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):
Copy link
Member

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 = [
Copy link
Member

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
Copy link

codecov bot commented Jun 12, 2017

Codecov Report

Merging #16661 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16661      +/-   ##
==========================================
+ Coverage   90.93%   90.93%   +<.01%     
==========================================
  Files         161      161              
  Lines       49266    49269       +3     
==========================================
+ Hits        44801    44804       +3     
  Misses       4465     4465
Flag Coverage Δ
#multiple 88.69% <ø> (ø) ⬆️
#single 40.22% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 92.27% <0%> (-0.1%) ⬇️
pandas/core/tools/datetimes.py 67.5% <0%> (+0.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ceaf852...89eaf1a. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 12, 2017

Codecov Report

Merging #16661 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.69% <ø> (ø) ⬆️
#single 40.17% <ø> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/io/pytables.py 92.87% <0%> (-0.25%) ⬇️
pandas/plotting/_core.py 81.83% <0%> (-0.1%) ⬇️
pandas/core/generic.py 92.27% <0%> (-0.09%) ⬇️
pandas/io/excel.py 80.55% <0%> (ø) ⬆️
pandas/io/parsers.py 95.43% <0%> (ø) ⬆️
pandas/core/resample.py 96.13% <0%> (+0.03%) ⬆️
pandas/core/tools/datetimes.py 67.5% <0%> (+0.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ceaf852...c249f66. Read the comment docs.

@rosygupta
Copy link
Author

@gfyoung @jreback Any clue why the build is failing?

@gfyoung
Copy link
Member

gfyoung commented Jun 13, 2017

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 flake8 and running the check listed in the PR template.

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.

autoindented Test File
build fail fix
dtype=object)
arr = np.array(
[
us_eastern.localize(
Copy link
Contributor

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

Copy link
Contributor

@jreback jreback left a 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
Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

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

done

@jreback
Copy link
Contributor

jreback commented Jul 19, 2017

can you rebase / update according to comments

@pep8speaks
Copy link

pep8speaks commented Jul 19, 2017

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

@gfyoung
Copy link
Member

gfyoung commented Jul 21, 2017

@rosygupta : These changes LGTM. Just need to resolve the merge conflict, and it should be on its way!

Copy link
Contributor

@jreback jreback left a 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'
Copy link
Contributor

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.

@jreback
Copy link
Contributor

jreback commented Sep 23, 2017

IIRC this was pretty reasonable. can you rebase / update to comments?

@jreback jreback removed this from the 0.21.0 milestone Sep 23, 2017
@jreback
Copy link
Contributor

jreback commented Oct 28, 2017

can you rebase

@jreback
Copy link
Contributor

jreback commented Nov 23, 2017

closing as this is stale.

@jreback jreback closed this Nov 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_datetime should support ISO week year
5 participants