fix Rolling for multi-index and reversed index. by leftys · Pull Request #28297 · pandas-dev/pandas (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that the 2 seconds time window is not respected, but the minimum is taken over the whole dataframe. To my understanding, the excpected results would be [3, 4, 2, 1, 1] (closed interval limits) or [3, 4, 2, 2, 1] (open interval end). Even if you consider the next 2 seconds in time order, i.e. the other way round, you would have [3, 3, 4, 2, 1].

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue found here. By using df.rolling().apply(func), we can print the window inside func and it is the while dataframe till current offset.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the expected result is wrong. I debugged it a bit and found out that VariableWindowIndexer indeed works only if the index is monotonic and increasing. I will create another PR to finally fix this.

EDIT: Here it comes: #32386