(dim, q, add_nans, skipna)
| 625 | @pytest.mark.parametrize("add_nans", (True, False)) |
| 626 | @pytest.mark.parametrize("skipna", (None, True, False)) |
| 627 | def test_weighted_quantile_3D(dim, q, add_nans, skipna): |
| 628 | dims = ("a", "b", "c") |
| 629 | coords = dict(a=[0, 1, 2], b=[0, 1, 2, 3], c=[0, 1, 2, 3, 4]) |
| 630 | |
| 631 | data = np.arange(60).reshape(3, 4, 5).astype(float) |
| 632 | |
| 633 | # add approximately 25 % NaNs (https://stackoverflow.com/a/32182680/3010700) |
| 634 | if add_nans: |
| 635 | c = int(data.size * 0.25) |
| 636 | data.ravel()[np.random.choice(data.size, c, replace=False)] = np.nan |
| 637 | |
| 638 | da = DataArray(data, dims=dims, coords=coords) |
| 639 | |
| 640 | # Weights are all ones, because we will compare against DataArray.quantile (non-weighted) |
| 641 | weights = xr.ones_like(da) |
| 642 | |
| 643 | result = da.weighted(weights).quantile(q, dim=dim, skipna=skipna) |
| 644 | expected = da.quantile(q, dim=dim, skipna=skipna) |
| 645 | |
| 646 | assert_allclose(expected, result) |
| 647 | |
| 648 | ds = da.to_dataset(name="data") |
| 649 | result2 = ds.weighted(weights).quantile(q, dim=dim, skipna=skipna) |
| 650 | |
| 651 | assert_allclose(expected, result2.data) |
| 652 | |
| 653 | |
| 654 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected
searching dependent graphs…