| 825 | |
| 826 | |
| 827 | def test_groupby_getitem(dataset) -> None: |
| 828 | assert_identical(dataset.sel(x=["a"]), dataset.groupby("x")["a"]) |
| 829 | assert_identical(dataset.sel(z=[1]), dataset.groupby("z")[1]) |
| 830 | assert_identical(dataset.foo.sel(x=["a"]), dataset.foo.groupby("x")["a"]) |
| 831 | assert_identical(dataset.foo.sel(z=[1]), dataset.foo.groupby("z")[1]) |
| 832 | assert_identical(dataset.cat.sel(y=[1]), dataset.cat.groupby("y")[1]) |
| 833 | |
| 834 | with pytest.raises( |
| 835 | NotImplementedError, match=r"Cannot broadcast 1d-only pandas extension array." |
| 836 | ): |
| 837 | dataset.groupby("boo") |
| 838 | dataset = dataset.drop_vars(["cat"]) |
| 839 | actual = dataset.groupby("boo")["f"].unstack().transpose("x", "y", "z") |
| 840 | expected = dataset.sel(y=[1], z=[1, 2]).transpose("x", "y", "z") |
| 841 | assert_identical(expected, actual) |
| 842 | |
| 843 | |
| 844 | def test_groupby_dataset() -> None: |