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

Function test_weighted_bad_dim

xarray/tests/test_weighted.py:791–810  ·  view source on GitHub ↗
(operation, as_dataset)

Source from the content-addressed store, hash-verified

789@pytest.mark.parametrize("operation", ("sum_of_weights", "sum", "mean", "quantile"))
790@pytest.mark.parametrize("as_dataset", (True, False))
791def test_weighted_bad_dim(operation, as_dataset):
792 data_array = DataArray(np.random.randn(2, 2))
793 weights = xr.ones_like(data_array)
794 data: DataArray | Dataset = data_array
795 if as_dataset:
796 data = data_array.to_dataset(name="data")
797
798 kwargs: dict[str, Any] = {"dim": "bad_dim"}
799 if operation == "quantile":
800 kwargs["q"] = 0.5
801
802 with pytest.raises(
803 ValueError,
804 match=(
805 f"Dimensions \\('bad_dim',\\) not found in {data.__class__.__name__}Weighted "
806 # the order of (dim_0, dim_1) varies
807 "dimensions \\(('dim_0', 'dim_1'|'dim_1', 'dim_0')\\)"
808 ),
809 ):
810 getattr(data.weighted(weights), operation)(**kwargs)

Callers

nothing calls this directly

Calls 3

to_datasetMethod · 0.95
DataArrayClass · 0.90
weightedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…