def to_dask_dataframe(self, dim_order=None, set_index=False):
        import dask.array as da
        import dask.dataframe as dd
        if dim_order is None:
            dim_order = list(self.dims)
        elif set(dim_order) != set(self.dims):
            raise ValueError(
                'dim_order {} does not match the set of dimensions on this '
                'Dataset: {}'.format(dim_order, list(self.dims)))
        ordered_dims = OrderedDict((k, self.dims[k]) for k in dim_order)
        columns = list(ordered_dims)
        columns.extend(k for k in self.coords if k not in self.dims)
        columns.extend(self.data_vars)
        series_list = []
        for name in columns:
            try:
                var = self.variables[name]
            except KeyError:
                size = self.dims[name]
                data = da.arange(size, chunks=size, dtype=np.int64)
                var = Variable((name,), data)
            if isinstance(var, IndexVariable):
                var = var.to_base_variable()
            dask_array = var.set_dims(ordered_dims).chunk(self.chunks).data
            series = dd.from_array(dask_array.reshape(-1), columns=[name])
            series_list.append(series)
        df = dd.concat(series_list, axis=1)
        if set_index:
            if len(dim_order) == 1:
                (dim,) = dim_order
                df = df.set_index(dim)
            else:
                df = df.set_index(dim_order)
        return df