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

Function test_groupby_dataset

xarray/tests/test_groupby.py:844–867  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

842
843
844def test_groupby_dataset() -> None:
845 data = Dataset(
846 {"z": (["x", "y"], np.random.randn(3, 5))},
847 {"x": ("x", list("abc")), "c": ("x", [0, 1, 0]), "y": range(5)},
848 )
849 groupby = data.groupby("x")
850 assert len(groupby) == 3
851 expected_groups = {"a": slice(0, 1), "b": slice(1, 2), "c": slice(2, 3)}
852 assert groupby.groups == expected_groups
853 expected_items = [
854 ("a", data.isel(x=[0])),
855 ("b", data.isel(x=[1])),
856 ("c", data.isel(x=[2])),
857 ]
858 for actual1, expected1 in zip(groupby, expected_items, strict=True):
859 assert actual1[0] == expected1[0]
860 assert_equal(actual1[1], expected1[1])
861
862 def identity(x):
863 return x
864
865 for k in ["x", "c", "y"]:
866 actual2 = data.groupby(k).map(identity)
867 assert_equal(data, actual2)
868
869
870def test_groupby_dataset_returns_new_type() -> None:

Callers

nothing calls this directly

Calls 5

groupbyMethod · 0.95
iselMethod · 0.95
DatasetClass · 0.90
assert_equalFunction · 0.90
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…