# xarray.DataArray.roll

#### DataArray.roll(shifts=None, roll_coords=False, \*\*shifts_kwargs)[[source]](https://github.com/pydata/xarray/blob/v2026.09.0/xarray/core/dataarray.py#L5213-L5260)

Roll this array 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.

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` to [`int`](https://docs.python.org/3/builtins/functions.html#int), *optional*) – Integer offset 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** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – DataArray with the same attributes but rolled data and coordinates.

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

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('032196f8-48c0-4de3-b5a1-493d270421f3','c4c1782a-ec15-4fc4-89a8-fe9b89a2e5b3','97533e86-988e-4d90-81ed-7afc7d99cf74','../lite/tree/../notebooks/index.html?path=0d41d6bc_2a2f_425a_8983_6baf2f8c33cc.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> arr = xr.DataArray([5, 6, 7], dims="x")
>>> arr.roll(x=1)
<xarray.DataArray (x: 3)> Size: 24B
array([7, 5, 6])
Dimensions without coordinates: x
```

<div id="97533e86-988e-4d90-81ed-7afc7d99cf74" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('032196f8-48c0-4de3-b5a1-493d270421f3','97533e86-988e-4d90-81ed-7afc7d99cf74')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('032196f8-48c0-4de3-b5a1-493d270421f3','97533e86-988e-4d90-81ed-7afc7d99cf74')">Open In Tab</button></div><div id="c4c1782a-ec15-4fc4-89a8-fe9b89a2e5b3" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
