rolling( window='10D') does not work for df with MultiIndex · Issue #15584 · pandas-dev/pandas (original) (raw)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-49-707b0ff61efc> in <module>()
     10 tdf = df.groupby(level=1).get_group( 64413 )
     11 
---> 12 tdf.rolling( '10D' ).mean()
     13 
     14 tdf.reset_index().set_index('time').rolling( '10D' ).mean()

/home/firdaus/.conda/envs/tsconda/lib/python3.5/site-packages/pandas/core/generic.py in rolling(self, window, min_periods, freq, center, win_type, on, axis)
   5502                                    min_periods=min_periods, freq=freq,
   5503                                    center=center, win_type=win_type,
-> 5504                                    on=on, axis=axis)
   5505 
   5506         cls.rolling = rolling

/home/firdaus/.conda/envs/tsconda/lib/python3.5/site-packages/pandas/core/window.py in rolling(obj, win_type, **kwds)
   1797         return Window(obj, win_type=win_type, **kwds)
   1798 
-> 1799     return Rolling(obj, **kwds)
   1800 
   1801 

/home/firdaus/.conda/envs/tsconda/lib/python3.5/site-packages/pandas/core/window.py in __init__(self, obj, window, min_periods, freq, center, win_type, axis, on, **kwargs)
     76         self.win_type = win_type
     77         self.axis = obj._get_axis_number(axis) if axis is not None else None
---> 78         self.validate()
     79 
     80     @property

/home/firdaus/.conda/envs/tsconda/lib/python3.5/site-packages/pandas/core/window.py in validate(self)
   1055 
   1056         elif not is_integer(self.window):
-> 1057             raise ValueError("window must be an integer")
   1058         elif self.window < 0:
   1059             raise ValueError("window must be non-negative")

ValueError: window must be an integer

The offset feature of specifying timelike windows in 'rolling' doesn't work if the dataframe has multindex with level_0 = 'time' and level_1 = something else.

Works correctly.