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

jbrockmendel opened this Issue Dec 20, 2017 · 0 comments


None yet
2 participants
Copy link

commented Dec 20, 2017

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)
>>> (ts + offset) - offset ==  ts   # should be the same as offset.onOffset(ts)
>>> 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.

@jreback jreback added this to the 0.23.0 milestone Dec 21, 2017

@jreback jreback added Clean Bug and removed Bug labels Dec 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.