xarray.Dataset.roll

Dataset.roll(shifts=None, roll_coords=None, **shifts_kwargs)

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

Unlike shift, roll may rotate all variables, including coordinates if specified. The direction of rotation is consistent with numpy.roll().

Parameters
shiftsdict, 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_coordsbool

Indicates whether to roll the coordinates by the offset The current default of roll_coords (None, equivalent to True) is deprecated and will change to False in a future version. Explicitly pass roll_coords to silence the warning.

**shifts_kwargs{dim: offset, …}, optional

The keyword arguments form of shifts. One of shifts or shifts_kwargs must be provided.

Returns
——-
rolledDataset

Dataset with the same coordinates and attributes but rolled variables.

See also

shift

Examples

>>> ds = xr.Dataset({'foo': ('x', list('abcde'))})
>>> ds.roll(x=2)
<xarray.Dataset>
Dimensions:  (x: 5)
Coordinates:
  * x        (x) int64 3 4 0 1 2
Data variables:
    foo      (x) object 'd' 'e' 'a' 'b' 'c'