Skip to content

BUG: incorrect year returned in isocalendar for certain dates #36050

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

Merged
merged 13 commits into from
Sep 4, 2020

Conversation

asishm
Copy link
Contributor

@asishm asishm commented Sep 1, 2020

@asishm asishm changed the title Isocalendar BUG: incorrect year returned in isocalendar for certain dates Sep 1, 2020
@asishm
Copy link
Contributor Author

asishm commented Sep 1, 2020

I'm not sure if a new test is needed here. I added the failing case to parametrize.

@jreback jreback added Bug Datetime Datetime data dtype labels Sep 1, 2020
@jreback jreback added this to the 1.1.2 milestone Sep 1, 2020
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 + can you add a whatsnew note in 1.1.2 bug fix section

@@ -682,6 +682,7 @@ def test_setitem_with_different_tz(self):
[[pd.NaT], [[np.NaN, np.NaN, np.NaN]]],
[["2019-12-31", "2019-12-29"], [[2020, 1, 2], [2019, 52, 7]]],
[["2010-01-01", pd.NaT], [[2009, 53, 5], [np.NaN, np.NaN, np.NaN]]],
[["2016-01-08"], [[2016, 1, 5]]], # see GH#36032
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 add some of the working cases from the original issue (that work)

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

also tested with this locally

import pandas as pd
dates = pd.date_range('1677-09-22', '2262-04-10', freq='D')
pd_iso = dates.isocalendar()
py_dates_iso = [date.isocalendar() for date in dates.to_pydatetime()]
py_iso = pd.DataFrame(py_dates_iso, columns=['year', 'week', 'day'], index=dates, dtype='UInt32')
assert pd_iso.equals(py_iso)

@asishm asishm requested a review from jreback September 2, 2020 15:13
@jreback
Copy link
Contributor

jreback commented Sep 2, 2020

cc @jbrockmendel

@@ -682,6 +682,9 @@ def test_setitem_with_different_tz(self):
[[pd.NaT], [[np.NaN, np.NaN, np.NaN]]],
[["2019-12-31", "2019-12-29"], [[2020, 1, 2], [2019, 52, 7]]],
[["2010-01-01", pd.NaT], [[2009, 53, 5], [np.NaN, np.NaN, np.NaN]]],
# see GH#36032
[["2016-01-08", "2016-01-04"], [[2016, 1, 5], [2016, 1, 1]]],
[["2016-01-07", "2016-01-01"], [[2016, 1, 4], [2015, 53, 5]]],
Copy link
Member

Choose a reason for hiding this comment

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

is there another implementation somewhere (maybe stdlib calendar) we can use to compare against?

Copy link
Member

Choose a reason for hiding this comment

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

i guess datetime.isocalendar would make sense

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbrockmendel I didn't want to change the current implementation too much, but I tested with datetime.isocalendar locally.

#36050 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Can you add in tests.tslibs.test_ccalendar (OK for follow-up):

from hypothesis import given, strategies as st

@given(st.datetimes(min_value=pd.Timestamp.min.to_pydatetime(), max_value=pd.Timestamp.max.to_pydatetime())
def test_isocalendar(dt):
    expected = dt.isocalendar()
    result = ccalendar.get_iso_calendar(dt.year, dt.month, dt.day)
    assert result == expected

Copy link
Contributor Author

@asishm asishm Sep 3, 2020

Choose a reason for hiding this comment

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

@jbrockmendel
Copy link
Member

LGTM

@jreback jreback merged commit 9dc1fd7 into pandas-dev:master Sep 4, 2020
@jreback
Copy link
Contributor

jreback commented Sep 4, 2020

thanks @asishm

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Sep 4, 2020
jreback pushed a commit that referenced this pull request Sep 4, 2020
…ertain dates (#36127)

Co-authored-by: Asish Mahapatra <asishkm@gmail.com>
@asishm asishm deleted the isocalendar branch September 7, 2020 05:14
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: .dt.isocalendar().year
3 participants