@@ -70,7 +70,7 @@ def __init__(
7070 center : Optional [bool ] = False ,
7171 win_type : Optional [str ] = None ,
7272 axis : Axis = 0 ,
73- on : Optional [str ] = None ,
73+ on : Optional [Union [ str , Index ] ] = None ,
7474 closed : Optional [str ] = None ,
7575 ** kwargs
7676 ):
@@ -126,7 +126,7 @@ def _create_blocks(self):
126126 obj = self ._selected_obj
127127
128128 # filter out the on from the object
129- if self .on is not None :
129+ if self .on is not None and not isinstance ( self . on , Index ) :
130130 if obj .ndim == 2 :
131131 obj = obj .reindex (columns = obj .columns .difference ([self .on ]), copy = False )
132132 blocks = obj ._to_dict_of_blocks (copy = False ).values ()
@@ -637,10 +637,10 @@ class Window(_Window):
637637 Provide a window type. If ``None``, all points are evenly weighted.
638638 See the notes below for further information.
639639 on : str, optional
640- For a DataFrame, a datetime-like column on which to calculate the rolling
641- window, rather than the DataFrame's index. Provided integer column is
642- ignored and excluded from result since an integer index is not used to
643- calculate the rolling window.
640+ For a DataFrame, a datetime-like column or MultiIndex level on which
641+ to calculate the rolling window, rather than the DataFrame's index.
642+ Provided integer column is ignored and excluded from result since
643+ an integer index is not used to calculate the rolling window.
644644 axis : int or str, default 0
645645 closed : str, default None
646646 Make the interval closed on the 'right', 'left', 'both' or
@@ -1651,18 +1651,19 @@ def is_datetimelike(self):
16511651
16521652 @cache_readonly
16531653 def _on (self ):
1654-
16551654 if self .on is None :
16561655 if self .axis == 0 :
16571656 return self .obj .index
16581657 elif self .axis == 1 :
16591658 return self .obj .columns
1659+ elif isinstance (self .on , Index ):
1660+ return self .on
16601661 elif isinstance (self .obj , ABCDataFrame ) and self .on in self .obj .columns :
16611662 return Index (self .obj [self .on ])
16621663 else :
16631664 raise ValueError (
16641665 "invalid on specified as {0}, "
1665- "must be a column (if DataFrame) "
1666+ "must be a column (of DataFrame), an Index "
16661667 "or None" .format (self .on )
16671668 )
16681669
@@ -1706,10 +1707,12 @@ def validate(self):
17061707
17071708 def _validate_monotonic (self ):
17081709 """
1709- Validate on is_monotonic .
1710+ Validate monotonic (increasing or decreasing) .
17101711 """
1711- if not self ._on .is_monotonic :
1712- formatted = self .on or "index"
1712+ if not (self ._on .is_monotonic_increasing or self ._on .is_monotonic_decreasing ):
1713+ formatted = self .on
1714+ if self .on is None :
1715+ formatted = "index"
17131716 raise ValueError ("{0} must be monotonic" .format (formatted ))
17141717
17151718 def _validate_freq (self ):
0 commit comments