MCPcopy
hub / github.com/pydata/xarray / test_multiple_groupers_string

Function test_multiple_groupers_string

xarray/tests/test_groupby.py:2958–2984  ·  view source on GitHub ↗
(as_dataset)

Source from the content-addressed store, hash-verified

2956
2957@pytest.mark.parametrize("as_dataset", [True, False])
2958def test_multiple_groupers_string(as_dataset) -> None:
2959 obj = DataArray(
2960 np.array([1, 2, 3, 0, 2, np.nan]),
2961 dims="d",
2962 coords=dict(
2963 labels1=("d", np.array(["a", "b", "c", "c", "b", "a"])),
2964 labels2=("d", np.array(["x", "y", "z", "z", "y", "x"])),
2965 ),
2966 name="foo",
2967 )
2968
2969 if as_dataset:
2970 obj = obj.to_dataset() # type: ignore[assignment]
2971
2972 expected = obj.groupby(labels1=UniqueGrouper(), labels2=UniqueGrouper()).mean()
2973 actual = obj.groupby(("labels1", "labels2")).mean()
2974 assert_identical(expected, actual)
2975
2976 # Passes `"labels2"` to squeeze; will raise an error around kwargs rather than the
2977 # warning & type error in the future
2978 with pytest.warns(FutureWarning):
2979 with pytest.raises(TypeError):
2980 obj.groupby("labels1", "labels2") # type: ignore[arg-type, misc]
2981 with pytest.raises(ValueError):
2982 obj.groupby("labels1", foo="bar") # type: ignore[arg-type]
2983 with pytest.raises(ValueError):
2984 obj.groupby("labels1", foo=UniqueGrouper())
2985
2986
2987@pytest.mark.parametrize("shuffle", [True, False])

Callers

nothing calls this directly

Calls 6

to_datasetMethod · 0.95
groupbyMethod · 0.95
DataArrayClass · 0.90
UniqueGrouperClass · 0.90
assert_identicalFunction · 0.90
meanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…