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

Function test_weighted_quantile_3D

xarray/tests/test_weighted.py:627–651  ·  view source on GitHub ↗
(dim, q, add_nans, skipna)

Source from the content-addressed store, hash-verified

625@pytest.mark.parametrize("add_nans", (True, False))
626@pytest.mark.parametrize("skipna", (None, True, False))
627def 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(

Callers

nothing calls this directly

Calls 9

weightedMethod · 0.95
quantileMethod · 0.95
to_datasetMethod · 0.95
DataArrayClass · 0.90
assert_allcloseFunction · 0.90
arangeMethod · 0.80
astypeMethod · 0.45
quantileMethod · 0.45
weightedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…