You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mroeschke
changed the title
BUG: rolling.median/quantile does not work with BaseIndexer subclasses
BUG: rolling.median/quantile does not work with (some) BaseIndexer subclasses
Oct 16, 2020
Problem are the non monotonic starting points of the windows. Same problem with non monotonic ending points
use_expanding = [True, False, True, False, True]
df = pd.DataFrame({'values': range(5)})
from pandas.api.indexers import BaseIndexer
class CustomIndexer(BaseIndexer):
def get_window_bounds(self, num_values, min_periods, center, closed):
start = np.empty(num_values, dtype=np.int64)
end = np.empty(num_values, dtype=np.int64)
for i in range(num_values):
if self.use_expanding[i]:
start[i] = i
end[i] = max(i -1, 1)
else:
start[i] = i
end[i] = i + self.window_size
return start, end
indexer = CustomIndexer(window_size=1, use_expanding=use_expanding)
# Each window
for window in df.rolling(indexer):
print(window)
# print(df)
rolled = df.rolling(indexer)
print(rolled.median())
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Using the example from
computation.rst
.The cython aggregations probably assume some sort of property of the windows that may not hold with the custom indexers
The text was updated successfully, but these errors were encountered: