| 846 | @pytest.mark.parametrize("fill_value", (np.nan, 0.0)) |
| 847 | @pytest.mark.parametrize("dask", (True, False)) |
| 848 | def test_ndrolling_construct(self, center, fill_value, dask) -> None: |
| 849 | da = DataArray( |
| 850 | np.arange(5 * 6 * 7).reshape(5, 6, 7).astype(float), |
| 851 | dims=["x", "y", "z"], |
| 852 | coords={"x": ["a", "b", "c", "d", "e"], "y": np.arange(6)}, |
| 853 | ) |
| 854 | ds = xr.Dataset({"da": da}) |
| 855 | if dask and has_dask: |
| 856 | ds = ds.chunk({"x": 4}) |
| 857 | |
| 858 | actual = ds.rolling(x=3, z=2, center=center).construct( |
| 859 | x="x1", z="z1", fill_value=fill_value |
| 860 | ) |
| 861 | if not isinstance(center, tuple): |
| 862 | center = (center, center) |
| 863 | expected = ( |
| 864 | ds.rolling(x=3, center=center[0]) |
| 865 | .construct(x="x1", fill_value=fill_value) |
| 866 | .rolling(z=2, center=center[1]) |
| 867 | .construct(z="z1", fill_value=fill_value) |
| 868 | ) |
| 869 | assert_allclose(actual, expected) |
| 870 | |
| 871 | @requires_dask |
| 872 | @pytest.mark.filterwarnings("error") |