MCPcopy
hub / github.com/pydata/xarray / test_drop_indexes

Method test_drop_indexes

xarray/tests/test_dataset.py:3145–3182  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3143 data.drop_isel(z=1)
3144
3145 def test_drop_indexes(self) -> None:
3146 ds = Dataset(
3147 coords={
3148 "x": ("x", [0, 1, 2]),
3149 "y": ("y", [3, 4, 5]),
3150 "foo": ("x", ["a", "a", "b"]),
3151 }
3152 )
3153
3154 actual = ds.drop_indexes("x")
3155 assert "x" not in actual.xindexes
3156 assert type(actual.x.variable) is Variable
3157
3158 actual = ds.drop_indexes(["x", "y"])
3159 assert "x" not in actual.xindexes
3160 assert "y" not in actual.xindexes
3161 assert type(actual.x.variable) is Variable
3162 assert type(actual.y.variable) is Variable
3163
3164 with pytest.raises(
3165 ValueError,
3166 match=r"The coordinates \('not_a_coord',\) are not found in the dataset coordinates",
3167 ):
3168 ds.drop_indexes("not_a_coord")
3169
3170 with pytest.raises(ValueError, match="those coordinates do not have an index"):
3171 ds.drop_indexes("foo")
3172
3173 actual = ds.drop_indexes(["foo", "not_a_coord"], errors="ignore")
3174 assert_identical(actual, ds)
3175
3176 # test index corrupted
3177 midx = pd.MultiIndex.from_tuples([(1, 2), (3, 4)], names=["a", "b"])
3178 midx_coords = Coordinates.from_pandas_multiindex(midx, "x")
3179 ds = Dataset(coords=midx_coords)
3180
3181 with pytest.raises(ValueError, match=r".*would corrupt the following index.*"):
3182 ds.drop_indexes("a")
3183
3184 def test_sel_on_unindexed_coordinate(self) -> None:
3185 # Test that .sel() works on coordinates without an index by creating

Callers

nothing calls this directly

Calls 5

drop_indexesMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90
typeFunction · 0.85

Tested by

no test coverage detected