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

Method test_pad_keep_attrs

xarray/tests/test_dataset.py:7600–7624  ·  view source on GitHub ↗
(self, keep_attrs, attrs, expected)

Source from the content-addressed store, hash-verified

7598 ],
7599 )
7600 def test_pad_keep_attrs(self, keep_attrs, attrs, expected) -> None:
7601 ds = xr.Dataset(
7602 {"a": ("x", [1, 2], attrs), "b": ("y", [1, 2], attrs)},
7603 coords={"c": ("x", [-1, 1], attrs), "d": ("y", [-1, 1], attrs)},
7604 attrs=attrs,
7605 )
7606 expected = xr.Dataset(
7607 {"a": ("x", [0, 1, 2, 0], expected), "b": ("y", [1, 2], attrs)},
7608 coords={
7609 "c": ("x", [np.nan, -1, 1, np.nan], expected),
7610 "d": ("y", [-1, 1], attrs),
7611 },
7612 attrs=expected,
7613 )
7614
7615 keep_attrs_ = "default" if keep_attrs is None else keep_attrs
7616
7617 with set_options(keep_attrs=keep_attrs_):
7618 actual = ds.pad({"x": (1, 1)}, mode="constant", constant_values=0)
7619 xr.testing.assert_identical(actual, expected)
7620
7621 actual = ds.pad(
7622 {"x": (1, 1)}, mode="constant", constant_values=0, keep_attrs=keep_attrs
7623 )
7624 xr.testing.assert_identical(actual, expected)
7625
7626 def test_astype_attrs(self) -> None:
7627 data = create_test_data(seed=123)

Callers

nothing calls this directly

Calls 2

padMethod · 0.95
set_optionsClass · 0.90

Tested by

no test coverage detected