(self)
| 2182 | assert actual.xindexes[dim_name].equals(expected.xindexes[dim_name]) |
| 2183 | |
| 2184 | def test_expand_dims_error(self) -> None: |
| 2185 | array = DataArray( |
| 2186 | np.random.randn(3, 4), |
| 2187 | dims=["x", "dim_0"], |
| 2188 | coords={"x": np.linspace(0.0, 1.0, 3)}, |
| 2189 | attrs={"key": "entry"}, |
| 2190 | ) |
| 2191 | |
| 2192 | with pytest.raises(TypeError, match=r"dim should be Hashable or"): |
| 2193 | array.expand_dims(0) |
| 2194 | with pytest.raises(ValueError, match=r"lengths of dim and axis"): |
| 2195 | # dims and axis argument should be the same length |
| 2196 | array.expand_dims(dim=["a", "b"], axis=[1, 2, 3]) |
| 2197 | with pytest.raises(ValueError, match=r"Dimension x already"): |
| 2198 | # Should not pass the already existing dimension. |
| 2199 | array.expand_dims(dim=["x"]) |
| 2200 | # raise if duplicate |
| 2201 | with pytest.raises(ValueError, match=r"duplicate values"): |
| 2202 | array.expand_dims(dim=["y", "y"]) |
| 2203 | with pytest.raises(ValueError, match=r"duplicate values"): |
| 2204 | array.expand_dims(dim=["y", "z"], axis=[1, 1]) |
| 2205 | with pytest.raises(ValueError, match=r"duplicate values"): |
| 2206 | array.expand_dims(dim=["y", "z"], axis=[2, -2]) |
| 2207 | |
| 2208 | # out of bounds error, axis must be in [-4, 3] |
| 2209 | with pytest.raises(IndexError): |
| 2210 | array.expand_dims(dim=["y", "z"], axis=[2, 4]) |
| 2211 | with pytest.raises(IndexError): |
| 2212 | array.expand_dims(dim=["y", "z"], axis=[2, -5]) |
| 2213 | # Does not raise an IndexError |
| 2214 | array.expand_dims(dim=["y", "z"], axis=[2, -4]) |
| 2215 | array.expand_dims(dim=["y", "z"], axis=[2, 3]) |
| 2216 | |
| 2217 | array = DataArray( |
| 2218 | np.random.randn(3, 4), |
| 2219 | dims=["x", "dim_0"], |
| 2220 | coords={"x": np.linspace(0.0, 1.0, 3)}, |
| 2221 | attrs={"key": "entry"}, |
| 2222 | ) |
| 2223 | with pytest.raises(TypeError): |
| 2224 | array.expand_dims({"new_dim": 3.2}) |
| 2225 | |
| 2226 | # Attempt to use both dim and kwargs |
| 2227 | with pytest.raises(ValueError): |
| 2228 | array.expand_dims({"d": 4}, e=4) |
| 2229 | |
| 2230 | def test_expand_dims(self) -> None: |
| 2231 | array = DataArray( |
nothing calls this directly
no test coverage detected