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

Method test_map_coords_attrs

xarray/tests/test_dataset.py:6542–6572  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

6540 assert_equal(expected, actual)
6541
6542 def test_map_coords_attrs(self) -> None:
6543 ds = xr.Dataset(
6544 {
6545 "a": (
6546 ["x", "y", "z"],
6547 np.arange(24).reshape(3, 4, 2),
6548 {"attr1": "value1"},
6549 ),
6550 "b": ("y", np.arange(4), {"attr2": "value2"}),
6551 },
6552 coords={
6553 "x": ("x", np.array([-1, 0, 1]), {"attr3": "value3"}),
6554 "z": ("z", list("ab"), {"attr4": "value4"}),
6555 },
6556 )
6557
6558 def func(arr):
6559 if "y" not in arr.dims:
6560 return arr
6561
6562 # drop attrs from coords
6563 return arr.mean(dim="y").drop_attrs()
6564
6565 expected = ds.mean(dim="y", keep_attrs=True)
6566 actual = ds.map(func, keep_attrs=True)
6567
6568 assert_identical(actual, expected)
6569 assert actual["x"].attrs
6570
6571 ds["x"].attrs["y"] = "x"
6572 assert ds["x"].attrs != actual["x"].attrs
6573
6574 def test_map_non_dataarray_outputs(self) -> None:
6575 # Test that map handles non-DataArray outputs by converting them

Callers

nothing calls this directly

Calls 4

mapMethod · 0.95
assert_identicalFunction · 0.90
arangeMethod · 0.80
meanMethod · 0.45

Tested by

no test coverage detected