I need to offset a DateTimeIndex index by a CustomBusinessDay, a trading day offset, which I instantiate like so:
import pandas_market_calendars as mcal
TCal = mcal.get_calendar('NYSE')
from pandas.tseries.offsets import CustomBusinessDay
TDay = CustomBusinessDay(calendar=TCal, holidays = TCal.holidays().holidays)
Applying this offset to a 'date' level of a MultiIndex:
df.index.set_levels(df.index.levels[0] + TDay, level=0)
yields the non-vectorized DateOffset being applied warning:
python3.8/site-packages/pandas/core/arrays/datetimes.py:692: PerformanceWarning: Non-vectorized DateOffset being applied to Series or DatetimeIndex
Is there a way to vectorize my CustomBusinessDay, or produce an analogous date offset that is vectorized? Thanks!
UPDATE: Here's the code that exemplifies the dataframe I am working with:
import numpy as np
import pandas as pd
dates = list(map(pd.to_datetime, ['2020-07-16', '2020-07-17']))
strings = ['A', 'B', 'C', 'D']
df = pd.DataFrame(
index=pd.MultiIndex.from_product([dates, strings], names=['date', 'string']),
data=np.random.uniform(size=(len(dates) * len(strings), 2))
)