Skip to content
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

BUG: WeekOfMonth.apply, LastWeekOfMonth.apply #18864

Closed
jbrockmendel opened this issue Dec 20, 2017 · 0 comments · Fixed by #18875
Closed

BUG: WeekOfMonth.apply, LastWeekOfMonth.apply #18864

jbrockmendel opened this issue Dec 20, 2017 · 0 comments · Fixed by #18875
Labels
Milestone

Comments

@jbrockmendel
Copy link
Member

Related: #18672

I am now reasonably confident that WeekOfMonth.apply and LastWeekOfMonth.apply both have a bug caused by using self.getOffsetOfMonth(dt) instead of `self._get_offset_day(dt)

>>> offset = pd.offsets.WeekOfMonth(n=-2, week=2, weekday=3)
>>> ts = pd.Timestamp('2017-12-21 19:32:49.533991002')
>>> offset.onOffset(ts)
True
>>> (ts + offset) - offset ==  ts   # should be the same as offset.onOffset(ts)
False
>>> ts + offset
Timestamp('2017-11-16 19:32:49.533991002')

But given that offset.onOffset(ts) is True, we would expect ts + offset to move back by 2 months, not 1.

Surfacing this bug requires timestamps with non-zero nanos and n<0. I expect there are other cases that would surface with tzaware timestamps.

Not that hard to fix; I'd like to get #18762 in first to avoid merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants