# Buggy code
def __init__(self, obj, min_periods=None, center=False, **windows):
    """
    Moving window object.

    Parameters
    ----------
    obj : Dataset or DataArray
        Object to window.
    min_periods : int, default None
        Minimum number of observations in window required to have a value
        (otherwise result is NA). The default, None, is equivalent to
        setting min_periods equal to the size of the window.
    center : boolean, default False
        Set the labels at the center of the window.
    **windows : dim=window
        dim : str
            Name of the dimension to create the rolling iterator
            along (e.g., `time`).
        window : int
            Size of the moving window.

    Returns
    -------
    rolling : type of input argument
    """

    if has_bottleneck and (LooseVersion(bn.__version__) < LooseVersion("1.0")):
        warnings.warn(
            "xarray requires bottleneck version of 1.0 or "
            "greater for rolling operations. Rolling "
            "aggregation methods will use numpy instead"
            "of bottleneck."
        )

    if len(windows) != 1:
        raise ValueError("exactly one dim/window should be provided")

    dim, window = next(iter(windows.items()))

    if window <= 0:
        raise ValueError("window must be > 0")

    self.obj = obj

    # attributes
    self.window = window
    self.min_periods = min_periods
    if min_periods is None:
        self._min_periods = window
    else:
        if min_periods <= 0:
            raise ValueError("min_periods must be greater than zero or None")

        self._min_periods = min_periods
    self.center = center
    self.dim = dim

    self._axis_num = self.obj.get_axis_num(self.dim)

    self._windows = None
    self._valid_windows = None
    self.window_indices = None
    self.window_labels = None

    self._setup_windows()


# Traceback (AttributeError)
In [13]: xr.DataArray(np.random.rand(10,3)).to_dataset('dim_1').rolling
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-438d3638a0d0> in <module>()
----> 1 xr.DataArray(np.random.rand(10,3)).to_dataset('dim_1').rolling

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xarray/core/common.py in __getattr__(self, name)
135                     return source[name]
136         raise AttributeError("%r object has no attribute %r" %
--> 137                              (type(self).__name__, name))
138
139     def __setattr__(self, name, value):

AttributeError: 'Dataset' object has no attribute 'rolling'

# Fixed code
def __init__(self, obj, min_periods=None, center=False, **windows):
    """
    Moving window object.

    Parameters
    ----------
    obj : Dataset or DataArray
        Object to window.
    min_periods : int, default None
        Minimum number of observations in window required to have a value
        (otherwise result is NA). The default, None, is equivalent to
        setting min_periods equal to the size of the window.
    center : boolean, default False
        Set the labels at the center of the window.
    **windows : dim=window
        dim : str
            Name of the dimension to create the rolling iterator
            along (e.g., `time`).
        window : int
            Size of the moving window.

    Returns
    -------
    rolling : type of input argument
    """

    if has_bottleneck and (LooseVersion(bn.__version__) < LooseVersion("1.0")):
        warnings.warn(
            "xarray requires bottleneck version of 1.0 or "
            "greater for rolling operations. Rolling "
            "aggregation methods will use numpy instead"
            "of bottleneck."
        )

    if len(windows) != 1:
        raise ValueError("exactly one dim/window should be provided")

    dim, window = next(iter(windows.items()))

    if window <= 0:
        raise ValueError("window must be > 0")

    self.obj = obj

    # attributes
    self.window = window
    self.min_periods = min_periods
    if min_periods is None:
        self._min_periods = window
    else:
        if min_periods <= 0:
            raise ValueError("min_periods must be greater than zero or None")

        self._min_periods = min_periods
    self.center = center
    self.dim = dim