(self, shape, dim, dtype)
| 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( |
nothing calls this directly
no test coverage detected