(self, dask: bool)
| 260 | class TestCoarsenConstruct: |
| 261 | @pytest.mark.parametrize("dask", [True, False]) |
| 262 | def test_coarsen_construct(self, dask: bool) -> None: |
| 263 | ds = Dataset( |
| 264 | { |
| 265 | "vart": ("time", np.arange(48), {"a": "b"}), |
| 266 | "varx": ("x", np.arange(10), {"a": "b"}), |
| 267 | "vartx": (("x", "time"), np.arange(480).reshape(10, 48), {"a": "b"}), |
| 268 | "vary": ("y", np.arange(12)), |
| 269 | }, |
| 270 | coords={"time": np.arange(48), "y": np.arange(12)}, |
| 271 | attrs={"foo": "bar"}, |
| 272 | ) |
| 273 | |
| 274 | if dask and has_dask: |
| 275 | ds = ds.chunk({"x": 4, "time": 10}) |
| 276 | |
| 277 | expected = xr.Dataset(attrs={"foo": "bar"}) |
| 278 | expected["vart"] = ( |
| 279 | ("year", "month"), |
| 280 | duck_array_ops.reshape(ds.vart.data, (-1, 12)), |
| 281 | {"a": "b"}, |
| 282 | ) |
| 283 | expected["varx"] = ( |
| 284 | ("x", "x_reshaped"), |
| 285 | duck_array_ops.reshape(ds.varx.data, (-1, 5)), |
| 286 | {"a": "b"}, |
| 287 | ) |
| 288 | expected["vartx"] = ( |
| 289 | ("x", "x_reshaped", "year", "month"), |
| 290 | duck_array_ops.reshape(ds.vartx.data, (2, 5, 4, 12)), |
| 291 | {"a": "b"}, |
| 292 | ) |
| 293 | expected["vary"] = ds.vary |
| 294 | expected.coords["time"] = ( |
| 295 | ("year", "month"), |
| 296 | duck_array_ops.reshape(ds.time.data, (-1, 12)), |
| 297 | ) |
| 298 | |
| 299 | with raise_if_dask_computes(): |
| 300 | actual = ds.coarsen(time=12, x=5).construct( |
| 301 | {"time": ("year", "month"), "x": ("x", "x_reshaped")} |
| 302 | ) |
| 303 | assert_identical(actual, expected) |
| 304 | |
| 305 | with raise_if_dask_computes(): |
| 306 | actual = ds.coarsen(time=12, x=5).construct( |
| 307 | time=("year", "month"), x=("x", "x_reshaped") |
| 308 | ) |
| 309 | assert_identical(actual, expected) |
| 310 | |
| 311 | with raise_if_dask_computes(): |
| 312 | actual = ds.coarsen(time=12, x=5).construct( |
| 313 | {"time": ("year", "month"), "x": ("x", "x_reshaped")}, keep_attrs=False |
| 314 | ) |
| 315 | for var in actual: |
| 316 | assert actual[var].attrs == {} |
| 317 | assert actual.attrs == {} |
| 318 | |
| 319 | with raise_if_dask_computes(): |
nothing calls this directly
no test coverage detected