Skip to content

regression in 0.23.0 on rolling max with DatetimeIndex. #21096

Closed
@lexual

Description

@lexual

Behaviour of .rolling() with datetimeindex appears to have changed or regressed between 0.22 & 0.23 versions of pandas.

See below for cut-down test case exhibiting behaviour.

Also see below for different output produced on same code on same data with 2 different pandas versions.

import numpy as np
import pandas as pd


def main():
    print('pandas', pd.__version__)
    n = 10
    index = pd.date_range(
        start='2018-1-1 01:00:00',
        freq='1min',
        periods=n,
    )
    s = pd.Series(
        data=0,
        index=index,
    )
    s.iloc[1] = np.nan
    s.iloc[-1] = 2
    print(s)
    maxes = s.rolling(window=f'{n}min').max()
    print(maxes.value_counts(dropna=False))


if __name__ == '__main__':
    main()

ACTUAL OUTPUT

pandas 0.22.0      
2018-01-01 01:00:00    0.0             
2018-01-01 01:01:00    NaN             
2018-01-01 01:02:00    0.0             
2018-01-01 01:03:00    0.0             
2018-01-01 01:04:00    0.0             
2018-01-01 01:05:00    0.0             
2018-01-01 01:06:00    0.0             
2018-01-01 01:07:00    0.0             
2018-01-01 01:08:00    0.0             
2018-01-01 01:09:00    2.0             
Freq: T, dtype: float64                
0.0    9           
2.0    1           
dtype: int64       
pandas 0.23.0      
2018-01-01 01:00:00    0.0             
2018-01-01 01:01:00    NaN             
2018-01-01 01:02:00    0.0             
2018-01-01 01:03:00    0.0             
2018-01-01 01:04:00    0.0             
2018-01-01 01:05:00    0.0             
2018-01-01 01:06:00    0.0             
2018-01-01 01:07:00    0.0             
2018-01-01 01:08:00    0.0             
2018-01-01 01:09:00    2.0             
Freq: T, dtype: float64                
0.0    10          
dtype: int64       

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions