(self)
| 3219 | ) |
| 3220 | |
| 3221 | def test_drop_dims(self) -> None: |
| 3222 | data = xr.Dataset( |
| 3223 | { |
| 3224 | "A": (["x", "y"], np.random.randn(2, 3)), |
| 3225 | "B": ("x", np.random.randn(2)), |
| 3226 | "x": ["a", "b"], |
| 3227 | "z": np.pi, |
| 3228 | } |
| 3229 | ) |
| 3230 | |
| 3231 | actual = data.drop_dims("x") |
| 3232 | expected = data.drop_vars(["A", "B", "x"]) |
| 3233 | assert_identical(expected, actual) |
| 3234 | |
| 3235 | actual = data.drop_dims("y") |
| 3236 | expected = data.drop_vars("A") |
| 3237 | assert_identical(expected, actual) |
| 3238 | |
| 3239 | actual = data.drop_dims(["x", "y"]) |
| 3240 | expected = data.drop_vars(["A", "B", "x"]) |
| 3241 | assert_identical(expected, actual) |
| 3242 | |
| 3243 | with pytest.raises((ValueError, KeyError)): |
| 3244 | data.drop_dims("z") # not a dimension |
| 3245 | |
| 3246 | with pytest.raises((ValueError, KeyError)): |
| 3247 | data.drop_dims(None) # type:ignore[arg-type] |
| 3248 | |
| 3249 | actual = data.drop_dims("z", errors="ignore") |
| 3250 | assert_identical(data, actual) |
| 3251 | |
| 3252 | # should this be allowed? |
| 3253 | actual = data.drop_dims(None, errors="ignore") # type:ignore[arg-type] |
| 3254 | assert_identical(data, actual) |
| 3255 | |
| 3256 | with pytest.raises(ValueError): |
| 3257 | actual = data.drop_dims("z", errors="wrong_value") # type: ignore[arg-type] |
| 3258 | |
| 3259 | actual = data.drop_dims(["x", "y", "z"], errors="ignore") |
| 3260 | expected = data.drop_vars(["A", "B", "x"]) |
| 3261 | assert_identical(expected, actual) |
| 3262 | |
| 3263 | def test_copy(self) -> None: |
| 3264 | data = create_test_data() |
nothing calls this directly
no test coverage detected