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

Method test_squeeze

xarray/tests/test_units.py:5093–5118  ·  view source on GitHub ↗
(self, shape, dim, dtype)

Source from the content-addressed store, hash-verified

5091 ),
5092 )
5093 def test_squeeze(self, shape, dim, dtype):
5094 names = "xyzt"
5095 dim_lengths = dict(zip(names, shape, strict=False))
5096 array1 = (
5097 np.linspace(0, 1, 10 * 20).astype(dtype).reshape(shape) * unit_registry.degK
5098 )
5099 array2 = (
5100 np.linspace(1, 2, 10 * 20).astype(dtype).reshape(shape) * unit_registry.Pa
5101 )
5102
5103 ds = xr.Dataset(
5104 data_vars={
5105 "a": (tuple(names[: len(shape)]), array1),
5106 "b": (tuple(names[: len(shape)]), array2),
5107 },
5108 )
5109 units = extract_units(ds)
5110
5111 kwargs = {"dim": dim} if dim != "all" and dim_lengths.get(dim, 0) == 1 else {}
5112
5113 expected = attach_units(strip_units(ds).squeeze(**kwargs), units)
5114
5115 actual = ds.squeeze(**kwargs)
5116
5117 assert_units_equal(expected, actual)
5118 assert_equal(expected, actual)
5119
5120 @pytest.mark.parametrize("variant", ("data", "coords"))
5121 @pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 9

assert_equalFunction · 0.90
extract_unitsFunction · 0.85
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
astypeMethod · 0.45
getMethod · 0.45
squeezeMethod · 0.45

Tested by

no test coverage detected