| 3033 | assert_identical(expected, actual) |
| 3034 | |
| 3035 | def test_drop_index_labels(self) -> None: |
| 3036 | data = Dataset({"A": (["x", "y"], np.random.randn(2, 3)), "x": ["a", "b"]}) |
| 3037 | |
| 3038 | with pytest.warns(FutureWarning): |
| 3039 | actual = data.drop(["a"], dim="x") |
| 3040 | expected = data.isel(x=[1]) |
| 3041 | assert_identical(expected, actual) |
| 3042 | |
| 3043 | with pytest.warns(FutureWarning): |
| 3044 | actual = data.drop(["a", "b"], dim="x") |
| 3045 | expected = data.isel(x=slice(0, 0)) |
| 3046 | assert_identical(expected, actual) |
| 3047 | |
| 3048 | with pytest.raises(KeyError): |
| 3049 | # not contained in axis |
| 3050 | with pytest.warns(FutureWarning): |
| 3051 | data.drop(["c"], dim="x") |
| 3052 | |
| 3053 | with pytest.warns(FutureWarning): |
| 3054 | actual = data.drop(["c"], dim="x", errors="ignore") |
| 3055 | assert_identical(data, actual) |
| 3056 | |
| 3057 | with pytest.raises(ValueError): |
| 3058 | data.drop(["c"], dim="x", errors="wrong_value") # type: ignore[arg-type] |
| 3059 | |
| 3060 | with pytest.warns(FutureWarning): |
| 3061 | actual = data.drop(["a", "b", "c"], "x", errors="ignore") |
| 3062 | expected = data.isel(x=slice(0, 0)) |
| 3063 | assert_identical(expected, actual) |
| 3064 | |
| 3065 | # DataArrays as labels are a nasty corner case as they are not |
| 3066 | # Iterable[Hashable] - DataArray.__iter__ yields scalar DataArrays. |
| 3067 | actual = data.drop_sel(x=DataArray(["a", "b", "c"]), errors="ignore") |
| 3068 | expected = data.isel(x=slice(0, 0)) |
| 3069 | assert_identical(expected, actual) |
| 3070 | with pytest.warns(FutureWarning): |
| 3071 | data.drop(DataArray(["a", "b", "c"]), dim="x", errors="ignore") |
| 3072 | assert_identical(expected, actual) |
| 3073 | |
| 3074 | actual = data.drop_sel(y=[1]) |
| 3075 | expected = data.isel(y=[0, 2]) |
| 3076 | assert_identical(expected, actual) |
| 3077 | |
| 3078 | with pytest.raises(KeyError, match=r"not found in axis"): |
| 3079 | data.drop_sel(x=0) |
| 3080 | |
| 3081 | def test_drop_labels_by_keyword(self) -> None: |
| 3082 | data = Dataset( |