BUG: Rolling functions doesn't work on decreasing variable index · Issue #32385 · pandas-dev/pandas (original) (raw)

Code Sample

def test_rolling_on_decreasing_index(self):
    # GH-19248
    index = [
        Timestamp("20190101 09:00:00"),
        Timestamp("20190101 09:00:02"),
        Timestamp("20190101 09:00:03"),
        Timestamp("20190101 09:00:05"),
        Timestamp("20190101 09:00:06"),
    ]

    df = DataFrame({"column": [3, 4, 4, 2, 1]}, index=reversed(index))
    result = df.rolling("2s").min()
    expected = DataFrame(
        {"column": [3.0, 4.0, 4.0, 2.0, 1.0]}, index=reversed(index)
    )
    # actual incorrect output is [3, 3, 3, 2, 1]
    tm.assert_frame_equal(result, expected)

Problem description

Rolling window operations on variable decreasing index don't work even after #28297. The reason for this is that the calculate_variable_window_bounds function doesn't work with decreasing index. Tested with latest master (~version 1.0.1).