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

Method test_rolling_keep_attrs

xarray/tests/test_rolling.py:384–424  ·  view source on GitHub ↗
(self, funcname, argument)

Source from the content-addressed store, hash-verified

382 ],
383 )
384 def test_rolling_keep_attrs(self, funcname, argument) -> None:
385 attrs_da = {"da_attr": "test"}
386
387 data = np.linspace(10, 15, 100)
388 coords = np.linspace(1, 10, 100)
389
390 da = DataArray(
391 data, dims=("coord"), coords={"coord": coords}, attrs=attrs_da, name="name"
392 )
393
394 # attrs are kept by default
395 func = getattr(da.rolling(dim={"coord": 5}), funcname)
396 result = func(*argument)
397 assert result.attrs == attrs_da
398 assert result.name == "name"
399
400 # discard attrs
401 func = getattr(da.rolling(dim={"coord": 5}), funcname)
402 result = func(*argument, keep_attrs=False)
403 assert result.attrs == {}
404 assert result.name == "name"
405
406 # test discard attrs using global option
407 func = getattr(da.rolling(dim={"coord": 5}), funcname)
408 with set_options(keep_attrs=False):
409 result = func(*argument)
410 assert result.attrs == {}
411 assert result.name == "name"
412
413 # keyword takes precedence over global option
414 func = getattr(da.rolling(dim={"coord": 5}), funcname)
415 with set_options(keep_attrs=False):
416 result = func(*argument, keep_attrs=True)
417 assert result.attrs == attrs_da
418 assert result.name == "name"
419
420 func = getattr(da.rolling(dim={"coord": 5}), funcname)
421 with set_options(keep_attrs=True):
422 result = func(*argument, keep_attrs=False)
423 assert result.attrs == {}
424 assert result.name == "name"
425
426 @requires_dask
427 @pytest.mark.parametrize("dtype", ["int", "float32", "float64"])

Callers

nothing calls this directly

Calls 5

rollingMethod · 0.95
DataArrayClass · 0.90
set_optionsClass · 0.90
linspaceMethod · 0.80
funcFunction · 0.70

Tested by

no test coverage detected