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

Method test_shift

xarray/tests/test_variable.py:1494–1527  ·  view source on GitHub ↗
(self, fill_value)

Source from the content-addressed store, hash-verified

1492
1493 @pytest.mark.parametrize("fill_value", [dtypes.NA, 2, 2.0])
1494 def test_shift(self, fill_value):
1495 v = Variable("x", [1, 2, 3, 4, 5])
1496
1497 assert_identical(v, v.shift(x=0))
1498 assert v is not v.shift(x=0)
1499
1500 expected = Variable("x", [np.nan, np.nan, 1, 2, 3])
1501 assert_identical(expected, v.shift(x=2))
1502
1503 if fill_value == dtypes.NA:
1504 # if we supply the default, we expect the missing value for a
1505 # float array
1506 fill_value_exp = np.nan
1507 else:
1508 fill_value_exp = fill_value
1509
1510 expected = Variable("x", [fill_value_exp, 1, 2, 3, 4])
1511 assert_identical(expected, v.shift(x=1, fill_value=fill_value))
1512
1513 expected = Variable("x", [2, 3, 4, 5, fill_value_exp])
1514 assert_identical(expected, v.shift(x=-1, fill_value=fill_value))
1515
1516 expected = Variable("x", [fill_value_exp] * 5)
1517 assert_identical(expected, v.shift(x=5, fill_value=fill_value))
1518 assert_identical(expected, v.shift(x=6, fill_value=fill_value))
1519
1520 with pytest.raises(ValueError, match=r"dimension"):
1521 v.shift(z=0)
1522
1523 v = Variable("x", [1, 2, 3, 4, 5], {"foo": "bar"})
1524 assert_identical(v, v.shift(x=0))
1525
1526 expected = Variable("x", [fill_value_exp, 1, 2, 3, 4], {"foo": "bar"})
1527 assert_identical(expected, v.shift(x=1, fill_value=fill_value))
1528
1529 def test_shift2d(self):
1530 v = Variable(("x", "y"), [[1, 2], [3, 4]])

Callers

nothing calls this directly

Calls 3

shiftMethod · 0.95
VariableClass · 0.90
assert_identicalFunction · 0.90

Tested by

no test coverage detected