Skip to content

Change in behavior of DatetimeIndex + Offset #22465

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
TomAugspurger opened this issue Aug 22, 2018 · 4 comments · Fixed by #22695
Closed

Change in behavior of DatetimeIndex + Offset #22465

TomAugspurger opened this issue Aug 22, 2018 · 4 comments · Fixed by #22695
Labels
Bug Datetime Datetime data dtype Timedelta Timedelta data type

Comments

@TomAugspurger
Copy link
Contributor

import pandas as pd

offset = pd.tseries.offsets.Week(weekday=6)
idx = pd.DatetimeIndex(['1999-12-26', '2000-05-14']) 

assert (idx[0] + offset) == (idx + offset)[0]

bisected to #18952

Before that the assertion was true, after it's false

# before
>>> idx + offset
DatetimeIndex(['2000-01-02', '2000-05-21'], dtype='datetime64[ns]', freq=None)

# after
>>> idx + offset
DatetimeIndex(['1999-12-26', '2000-05-14'], dtype='datetime64[ns]', freq=None)

cc @reidy-p is this an expected change due to #18952, or a new bug? If it's intentional, we should document that.

@TomAugspurger
Copy link
Contributor Author

Hmm if I had to guess, https://github.com/pandas-dev/pandas/pull/18952/files#diff-63e1050a658278e30a3e7a744c4d6435R1324 is the line directly to blame, which seems pretty intentional :)

@reidy-p
Copy link
Contributor

reidy-p commented Aug 22, 2018

@TomAugspurger thanks for spotting this. It seems like the problem is a bit deeper than the line you're pointing to - I'll take a closer look and see if I can fix it.

@TomAugspurger
Copy link
Contributor Author

Fails for me on master.

In [1]: import pandas as pd
   ...:
   ...: offset = pd.tseries.offsets.Week(weekday=6)
   ...: idx = pd.DatetimeIndex(['1999-12-26', '2000-05-14'])
   ...:
   ...: assert (idx[0] + offset) == (idx + offset)[0]
   ...:
   ...:
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-1-8c110b991a5b> in <module>()
      4 idx = pd.DatetimeIndex(['1999-12-26', '2000-05-14'])
      5
----> 6 assert (idx[0] + offset) == (idx + offset)[0]

AssertionError:

are your C-extensions up to date?

@reidy-p
Copy link
Contributor

reidy-p commented Sep 11, 2018

@TomAugspurger Sorry that was a mistake on my part. Forgot that I had made some changes that I didn't stash before testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants