()
| 842 | |
| 843 | |
| 844 | def 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 | |
| 870 | def test_groupby_dataset_returns_new_type() -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…