# xarray.Dataset.roll

#### Dataset.roll(shifts=None, roll_coords=False, \*\*shifts_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L8177-L8261)

Roll this dataset by an offset along one or more dimensions.

Unlike shift, roll treats the given dimensions as periodic, so will not
create any missing values to be filled.

Also unlike shift, roll may rotate all variables, including coordinates
if specified. The direction of rotation is consistent with
[`numpy.roll()`](https://numpy.org/doc/stable/reference/generated/numpy.roll.html#numpy.roll).

* **Parameters:**
  * **shifts** ([mapping](https://docs.python.org/3/glossary.html#term-mapping) of [hashable](../user-guide/terminology.html.md#term-name) to [`int`](https://docs.python.org/3/builtins/functions.html#int), *optional*) – A dict with keys matching dimensions and values given
    by integers to rotate each of the given dimensions. Positive
    offsets roll to the right; negative offsets roll to the left.
  * **roll_coords** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Indicates whether to roll the coordinates by the offset too.
  * **\*\*shifts_kwargs** (`{dim: offset, ...}`, *optional*) – The keyword arguments form of `shifts`.
    One of shifts or shifts_kwargs must be provided.
* **Returns:**
  **rolled** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – Dataset with the same attributes but rolled data and coordinates.

#### SEE ALSO
[`shift`](xarray.Dataset.shift.html.md#xarray.Dataset.shift)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('119ef809-9a7b-4303-a085-818fc9fd2522','bedc772b-6367-4185-88ef-184f73904f38','86b131aa-78dc-4ff5-a55c-786e7ce2696d','../lite/tree/../notebooks/index.html?path=75e7d19e_f846_4859_91bb_2723863e0639.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> ds = xr.Dataset({"foo": ("x", list("abcde"))}, coords={"x": np.arange(5)})
>>> ds.roll(x=2)
<xarray.Dataset> Size: 60B
Dimensions:  (x: 5)
Coordinates:
  * x        (x) int64 40B 0 1 2 3 4
Data variables:
    foo      (x) <U1 20B 'd' 'e' 'a' 'b' 'c'
```

```pycon
>>> ds.roll(x=2, roll_coords=True)
<xarray.Dataset> Size: 60B
Dimensions:  (x: 5)
Coordinates:
  * x        (x) int64 40B 3 4 0 1 2
Data variables:
    foo      (x) <U1 20B 'd' 'e' 'a' 'b' 'c'
```

<div id="86b131aa-78dc-4ff5-a55c-786e7ce2696d" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('119ef809-9a7b-4303-a085-818fc9fd2522','86b131aa-78dc-4ff5-a55c-786e7ce2696d')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('119ef809-9a7b-4303-a085-818fc9fd2522','86b131aa-78dc-4ff5-a55c-786e7ce2696d')">Open In Tab</button></div><div id="bedc772b-6367-4185-88ef-184f73904f38" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
