MCPcopy
hub / github.com/pydata/xarray / test_reduce_keep_attrs

Method test_reduce_keep_attrs

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

Source from the content-addressed store, hash-verified

6315 assert_identical(expected, actual)
6316
6317 def test_reduce_keep_attrs(self) -> None:
6318 data = create_test_data()
6319 _attrs = {"attr1": "value1", "attr2": 2929}
6320
6321 attrs = dict(_attrs)
6322 data.attrs = attrs
6323
6324 # Test default behavior (keeps attrs for reduction operations)
6325 ds = data.mean()
6326 assert ds.attrs == attrs
6327 for k, v in ds.data_vars.items():
6328 assert v.attrs == data[k].attrs
6329
6330 # Test explicitly keeping attrs
6331 ds = data.mean(keep_attrs=True)
6332 assert ds.attrs == attrs
6333 for k, v in ds.data_vars.items():
6334 assert v.attrs == data[k].attrs
6335
6336 # Test explicitly dropping attrs
6337 ds = data.mean(keep_attrs=False)
6338 assert ds.attrs == {}
6339 for v in ds.data_vars.values():
6340 assert v.attrs == {}
6341
6342 @pytest.mark.filterwarnings("ignore:Once the behaviour of DataArray:FutureWarning")
6343 def test_reduce_argmin(self) -> None:

Callers

nothing calls this directly

Calls 4

create_test_dataFunction · 0.90
itemsMethod · 0.80
meanMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected