@@ -1025,19 +1025,8 @@ def validate(self):
1025
1025
if (self .is_datetimelike and
1026
1026
isinstance (self .window , (compat .string_types , DateOffset ))):
1027
1027
1028
- # must be monotonic for on
1029
- if not self ._on .is_monotonic :
1030
- formatted = self .on or 'index'
1031
- raise ValueError ("{0} must be "
1032
- "monotonic" .format (formatted ))
1033
-
1034
- from pandas .tseries .frequencies import to_offset
1035
- try :
1036
- freq = to_offset (self .window )
1037
- except (TypeError , ValueError ):
1038
- raise ValueError ("passed window {0} in not "
1039
- "compat with a datetimelike "
1040
- "index" .format (self .window ))
1028
+ self ._validate_monotonic ()
1029
+ freq = self ._validate_freq ()
1041
1030
1042
1031
# we don't allow center
1043
1032
if self .center :
@@ -1058,6 +1047,23 @@ def validate(self):
1058
1047
elif self .window < 0 :
1059
1048
raise ValueError ("window must be non-negative" )
1060
1049
1050
+ def _validate_monotonic (self ):
1051
+ """ validate on is monotonic """
1052
+ if not self ._on .is_monotonic :
1053
+ formatted = self .on or 'index'
1054
+ raise ValueError ("{0} must be "
1055
+ "monotonic" .format (formatted ))
1056
+
1057
+ def _validate_freq (self ):
1058
+ """ validate & return our freq """
1059
+ from pandas .tseries .frequencies import to_offset
1060
+ try :
1061
+ return to_offset (self .window )
1062
+ except (TypeError , ValueError ):
1063
+ raise ValueError ("passed window {0} in not "
1064
+ "compat with a datetimelike "
1065
+ "index" .format (self .window ))
1066
+
1061
1067
@Substitution (name = 'rolling' )
1062
1068
@Appender (SelectionMixin ._see_also_template )
1063
1069
@Appender (SelectionMixin ._agg_doc )
@@ -1175,6 +1181,23 @@ class RollingGroupby(_GroupByMixin, Rolling):
1175
1181
def _constructor (self ):
1176
1182
return Rolling
1177
1183
1184
+ def _gotitem (self , key , ndim , subset = None ):
1185
+
1186
+ # we are resetting the actual object here so our
1187
+ # index is carried thru to the selected obj
1188
+ # when we do the splitting for the groupby
1189
+ if self .on is not None :
1190
+ self ._groupby .obj = self ._groupby .obj .set_index (self ._on )
1191
+ self .on = None
1192
+ return super (RollingGroupby , self )._gotitem (key , ndim , subset = subset )
1193
+
1194
+ def _validate_monotonic (self ):
1195
+ """
1196
+ validate on is monotonic;
1197
+ we don't care for groupby.rolling
1198
+ """
1199
+ pass
1200
+
1178
1201
1179
1202
class Expanding (_Rolling_and_Expanding ):
1180
1203
"""
0 commit comments