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

Method test_shift

xarray/tests/test_dataarray.py:4223–4237  ·  view source on GitHub ↗
(self, offset, fill_value, dtype)

Source from the content-addressed store, hash-verified

4221 @pytest.mark.parametrize("offset", [-5, 0, 1, 2])
4222 @pytest.mark.parametrize("fill_value, dtype", [(2, int), (dtypes.NA, float)])
4223 def test_shift(self, offset, fill_value, dtype) -> None:
4224 arr = DataArray([1, 2, 3], dims="x")
4225 actual = arr.shift(x=1, fill_value=fill_value)
4226 if fill_value == dtypes.NA:
4227 # if we supply the default, we expect the missing value for a
4228 # float array
4229 fill_value = np.nan
4230 expected = DataArray([fill_value, 1, 2], dims="x")
4231 assert_identical(expected, actual)
4232 assert actual.dtype == dtype
4233
4234 arr = DataArray([1, 2, 3], [("x", ["a", "b", "c"])])
4235 expected = DataArray(arr.to_pandas().shift(offset))
4236 actual = arr.shift(x=offset)
4237 assert_identical(expected, actual)
4238
4239 def test_roll_coords(self) -> None:
4240 arr = DataArray([1, 2, 3], coords={"x": range(3)}, dims="x")

Callers

nothing calls this directly

Calls 5

shiftMethod · 0.95
to_pandasMethod · 0.95
DataArrayClass · 0.90
assert_identicalFunction · 0.90
shiftMethod · 0.45

Tested by

no test coverage detected