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

Method test_pad_constant

xarray/tests/test_dataarray.py:4651–4676  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4649 assert_allclose(actual, expected)
4650
4651 def test_pad_constant(self) -> None:
4652 ar = DataArray(np.arange(3 * 4 * 5).reshape(3, 4, 5))
4653 actual = ar.pad(dim_0=(1, 3))
4654 expected = DataArray(
4655 np.pad(
4656 np.arange(3 * 4 * 5).reshape(3, 4, 5).astype(np.float32),
4657 mode="constant",
4658 pad_width=((1, 3), (0, 0), (0, 0)),
4659 constant_values=np.nan,
4660 )
4661 )
4662 assert actual.shape == (7, 4, 5)
4663 assert_identical(actual, expected)
4664
4665 ar = xr.DataArray([9], dims="x")
4666
4667 actual = ar.pad(x=1)
4668 expected = xr.DataArray([np.nan, 9, np.nan], dims="x")
4669 assert_identical(actual, expected)
4670
4671 actual = ar.pad(x=1, constant_values=1.23456)
4672 expected = xr.DataArray([1, 9, 1], dims="x")
4673 assert_identical(actual, expected)
4674
4675 with pytest.raises(ValueError, match="cannot convert float NaN to integer"):
4676 ar.pad(x=1, constant_values=np.nan)
4677
4678 def test_pad_coords(self) -> None:
4679 ar = DataArray(

Callers

nothing calls this directly

Calls 6

padMethod · 0.95
DataArrayClass · 0.90
assert_identicalFunction · 0.90
arangeMethod · 0.80
padMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected