MCPcopy Index your code
hub / github.com/pydata/xarray / shift

Method shift

xarray/core/dataarray.py:5041–5089  ·  view source on GitHub ↗

Shift this DataArray by an offset along one or more dimensions. Only the data is moved; coordinates stay in place. This is consistent with the behavior of ``shift`` in pandas. Values shifted from beyond array bounds will appear at one end of each dimension, which ar

(
        self,
        shifts: Mapping[Any, int] | None = None,
        fill_value: Any = dtypes.NA,
        **shifts_kwargs: int,
    )

Source from the content-addressed store, hash-verified

5039 return self._from_temp_dataset(ds)
5040
5041 def shift(
5042 self,
5043 shifts: Mapping[Any, int] | None = None,
5044 fill_value: Any = dtypes.NA,
5045 **shifts_kwargs: int,
5046 ) -> Self:
5047 """Shift this DataArray by an offset along one or more dimensions.
5048
5049 Only the data is moved; coordinates stay in place. This is consistent
5050 with the behavior of ``shift`` in pandas.
5051
5052 Values shifted from beyond array bounds will appear at one end of
5053 each dimension, which are filled according to `fill_value`. For periodic
5054 offsets instead see `roll`.
5055
5056 Parameters
5057 ----------
5058 shifts : mapping of Hashable to int or None, optional
5059 Integer offset to shift along each of the given dimensions.
5060 Positive offsets shift to the right; negative offsets shift to the
5061 left.
5062 fill_value : scalar, optional
5063 Value to use for newly missing values
5064 **shifts_kwargs
5065 The keyword arguments form of ``shifts``.
5066 One of shifts or shifts_kwargs must be provided.
5067
5068 Returns
5069 -------
5070 shifted : DataArray
5071 DataArray with the same coordinates and attributes but shifted
5072 data.
5073
5074 See Also
5075 --------
5076 roll
5077
5078 Examples
5079 --------
5080 >>> arr = xr.DataArray([5, 6, 7], dims="x")
5081 >>> arr.shift(x=1)
5082 <xarray.DataArray (x: 3)> Size: 24B
5083 array([nan, 5., 6.])
5084 Dimensions without coordinates: x
5085 """
5086 variable = self.variable.shift(
5087 shifts=shifts, fill_value=fill_value, **shifts_kwargs
5088 )
5089 return self._replace(variable=variable)
5090
5091 def roll(
5092 self,

Callers 1

test_shiftMethod · 0.95

Calls 1

_replaceMethod · 0.95

Tested by 1

test_shiftMethod · 0.76