This is not centered. If I want to set the window labels as the center of the window index (like in pandas):
a = s.rolling(f'{window_size}D', center=True).mean()
then I get a NotImplementedError.
I wish I could do this in cudf.
Right now, I can just compute the rolling mean, shift it by half the window size and fill in the NaN values by using a loop over a variable window but it's a little ugly.
shift = -(window_size-1)//2
b = s.rolling(f'{window_size}D').mean().shift(shift)
b.iloc[shift:] = [s.loc[i:].mean() for i in s.index[-window_size+1:-window_size-shift+1]]
Pandas' DataFrame.rolling uses a cython optimized function to implement center (and closed) parameters. Its function to get variable window indexers is pandas._libs.window.indexers.calculate_variable_window_bounds. My suggestion is to implement this function in cudf.
Suppose I have a Series as follows:
If I want to perform 3-day rolling window mean, I can do:
This is not centered. If I want to set the window labels as the center of the window index (like in pandas):
then I get a NotImplementedError.
I wish I could do this in cudf.
Right now, I can just compute the rolling mean, shift it by half the window size and fill in the NaN values by using a loop over a variable window but it's a little ugly.
Pandas'
DataFrame.rolling
uses a cython optimized function to implementcenter
(andclosed
) parameters. Its function to get variable window indexers ispandas._libs.window.indexers.calculate_variable_window_bounds
. My suggestion is to implement this function in cudf.