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

Method test_squeeze

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

Source from the content-addressed store, hash-verified

5223 del data["level_1"]
5224
5225 def test_squeeze(self) -> None:
5226 data = Dataset({"foo": (["x", "y", "z"], [[[1], [2]]])})
5227 test_args: list[list] = [[], [["x"]], [["x", "z"]]]
5228 for args in test_args:
5229
5230 def get_args(args, v):
5231 return [set(args[0]) & set(v.dims)] if args else []
5232
5233 expected = Dataset(
5234 {k: v.squeeze(*get_args(args, v)) for k, v in data.variables.items()}
5235 )
5236 expected = expected.set_coords(data.coords)
5237 assert_identical(expected, data.squeeze(*args))
5238 # invalid squeeze
5239 with pytest.raises(ValueError, match=r"cannot select a dimension"):
5240 data.squeeze("y")
5241
5242 def test_squeeze_drop(self) -> None:
5243 data = Dataset({"foo": ("x", [1])}, {"x": [0]})

Callers

nothing calls this directly

Calls 5

set_coordsMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90
itemsMethod · 0.80
squeezeMethod · 0.45

Tested by

no test coverage detected