I am on pandas version 1.1.3.
Suppose I have the following index
import pandas as pd
from pandas.tseries.offsets import CDay
idx = pd.bdate_range("2010-02-03","2010-02-12") + pd.Timedelta('22H')
If I then add:
shifted_idx = idx + 0*CDay(offset=pd.Timedelta('4H'))
I would expect the timestamp in idx
of 2010-05-05 22:00
to move to 2010-05-08 02:00
since CDay()
has weekmask = ‘Mon Tue Wed Thu Fri’
by default.
However, we see in shifted_idx
a timestamp 2010-02-06 02:00:00
which is on a Saturday and violates the weekmask?
The
offset
parameter is applied after the day shift is applied, that's why you are getting these results.You can see that by taking a look at the source code of the
apply
method of theCustomBusinessDay
class. Note thatCDay
is just an alias ofCustomBusinessDay
.Not sure if this counts as a bug, because you can argue that this is the intended behavior. I couldn't find any documentation to support nor oppose this.
For now, you can work around this by manually applying the offset first, then applying the mask. Something like this: