# Buggy code
def validate(self):
    super(Rolling, self).validate()

    # we allow rolling on a datetimelike index
    if self.is_datetimelike and isinstance(
        self.window, (compat.string_types, DateOffset)
    ):
        # must be monotonic for on
        if not self._on.is_monotonic:
            formatted = self.on or "index"
            raise ValueError("{0} must be monotonic".format(formatted))

        from pandas.tseries.frequencies import to_offset

        try:
            freq = to_offset(self.window)
        except (TypeError, ValueError):
            raise ValueError(
                "passed window {0} in not compat with a datetimelike index".format(
                    self.window
                )
            )

        # we don't allow center
        if self.center:
            raise NotImplementedError(
                "center is not implemented for datetimelike and offset based windows"
            )

        # this will raise ValueError on non-fixed freqs
        self.window = freq.nanos
        self.win_type = "freq"

        # min_periods must be an integer
        if self.min_periods is None:
            self.min_periods = 1

    elif not is_integer(self.window):
        raise ValueError("window must be an integer")
    elif self.window < 0:
        raise ValueError("window must be non-negative")


# Traceback (ValueError)
In [7]: dates_df.groupby('name').rolling('180D', on='date')['amount'].sum()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-8896cb99a66a> in <module>()
----> 1 dates_df.groupby('name').rolling('180D', on='date')['amount'].sum()

/Users/jreback/pandas/pandas/core/groupby.py in rolling(self, *args, **kwargs)
1148         """
1149         from pandas.core.window import RollingGroupby
-> 1150         return RollingGroupby(self, *args, **kwargs)
1151
1152     @Substitution(name='groupby')

/Users/jreback/pandas/pandas/core/window.py in __init__(self, obj, *args, **kwargs)
635         self._groupby.mutated = True
636         self._groupby.grouper.mutated = True
--> 637         super(GroupByMixin, self).__init__(obj, *args, **kwargs)
638
639     count = GroupByMixin._dispatch('count')

/Users/jreback/pandas/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

/Users/jreback/pandas/pandas/core/window.py in validate(self)
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

ValueError: date must be monotonic

# Fixed code
def validate(self):
    super(Rolling, self).validate()

    # we allow rolling on a datetimelike index
    if self.is_datetimelike and isinstance(
        self.window, (compat.string_types, DateOffset)
    ):
        self._validate_monotonic()
        freq = self._validate_freq()

        # we don't allow center
        if self.center:
            raise NotImplementedError(
                "center is not implemented for datetimelike and offset based windows"
            )

        # this will raise ValueError on non-fixed freqs
        self.window = freq.nanos
        self.win_type = "freq"

        # min_periods must be an integer
        if self.min_periods is None:
            self.min_periods = 1

    elif not is_integer(self.window):
        raise ValueError("window must be an integer")
    elif self.window < 0:
        raise ValueError("window must be non-negative")