-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Conversation
I'm not sure if a new test is needed here. I added the failing case to parametrize. |
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 + 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 |
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 add some of the working cases from the original issue (that work)
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
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)
@@ -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]]], |
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.
is there another implementation somewhere (maybe stdlib calendar) we can use to compare against?
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 guess datetime.isocalendar would make sense
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.
@jbrockmendel I didn't want to change the current implementation too much, but I tested with datetime.isocalendar
locally.
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 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
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.
@jbrockmendel Unsure how to resolve the CI failures. should I just add warn=False
in the to_pydatetime
call?
https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=41452&view=ms.vss-test-web.build-test-results-tab&runId=2135520&resultId=100016&paneView=debug
LGTM |
thanks @asishm |
…ndar for certain dates
…ertain dates (#36127) Co-authored-by: Asish Mahapatra <asishkm@gmail.com>
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff