(self)
| 2965 | assert_equal(v[:3, :2], v.loc[d1[:3], d2[:2]]) |
| 2966 | |
| 2967 | def test_drop_variables(self) -> None: |
| 2968 | data = create_test_data() |
| 2969 | |
| 2970 | assert_identical(data, data.drop_vars([])) |
| 2971 | |
| 2972 | expected = Dataset({k: data[k] for k in data.variables if k != "time"}) |
| 2973 | actual = data.drop_vars("time") |
| 2974 | assert_identical(expected, actual) |
| 2975 | actual = data.drop_vars(["time"]) |
| 2976 | assert_identical(expected, actual) |
| 2977 | |
| 2978 | with pytest.raises( |
| 2979 | ValueError, |
| 2980 | match=re.escape( |
| 2981 | "These variables cannot be found in this dataset: ['not_found_here']" |
| 2982 | ), |
| 2983 | ): |
| 2984 | data.drop_vars("not_found_here") |
| 2985 | |
| 2986 | actual = data.drop_vars("not_found_here", errors="ignore") |
| 2987 | assert_identical(data, actual) |
| 2988 | |
| 2989 | actual = data.drop_vars(["not_found_here"], errors="ignore") |
| 2990 | assert_identical(data, actual) |
| 2991 | |
| 2992 | actual = data.drop_vars(["time", "not_found_here"], errors="ignore") |
| 2993 | assert_identical(expected, actual) |
| 2994 | |
| 2995 | # deprecated approach with `drop` works (straight copy paste from above) |
| 2996 | |
| 2997 | with pytest.warns(FutureWarning): |
| 2998 | actual = data.drop("not_found_here", errors="ignore") |
| 2999 | assert_identical(data, actual) |
| 3000 | |
| 3001 | with pytest.warns(FutureWarning): |
| 3002 | actual = data.drop(["not_found_here"], errors="ignore") |
| 3003 | assert_identical(data, actual) |
| 3004 | |
| 3005 | with pytest.warns(FutureWarning): |
| 3006 | actual = data.drop(["time", "not_found_here"], errors="ignore") |
| 3007 | assert_identical(expected, actual) |
| 3008 | |
| 3009 | with pytest.warns(FutureWarning): |
| 3010 | actual = data.drop({"time", "not_found_here"}, errors="ignore") |
| 3011 | assert_identical(expected, actual) |
| 3012 | |
| 3013 | def test_drop_multiindex_level(self) -> None: |
| 3014 | data = create_test_multiindex() |
nothing calls this directly
no test coverage detected