(self)
| 2852 | data.to_unstacked_dataset("x", 0) |
| 2853 | |
| 2854 | def test_transpose(self) -> None: |
| 2855 | da = DataArray( |
| 2856 | np.random.randn(3, 4, 5), |
| 2857 | dims=("x", "y", "z"), |
| 2858 | coords={ |
| 2859 | "x": range(3), |
| 2860 | "y": range(4), |
| 2861 | "z": range(5), |
| 2862 | "xy": (("x", "y"), np.random.randn(3, 4)), |
| 2863 | }, |
| 2864 | ) |
| 2865 | |
| 2866 | actual = da.transpose(transpose_coords=False) |
| 2867 | expected = DataArray(da.values.T, dims=("z", "y", "x"), coords=da.coords) |
| 2868 | assert_equal(expected, actual) |
| 2869 | |
| 2870 | actual = da.transpose("z", "y", "x", transpose_coords=True) |
| 2871 | expected = DataArray( |
| 2872 | da.values.T, |
| 2873 | dims=("z", "y", "x"), |
| 2874 | coords={ |
| 2875 | "x": da.x.values, |
| 2876 | "y": da.y.values, |
| 2877 | "z": da.z.values, |
| 2878 | "xy": (("y", "x"), da.xy.values.T), |
| 2879 | }, |
| 2880 | ) |
| 2881 | assert_equal(expected, actual) |
| 2882 | |
| 2883 | # same as previous but with ellipsis |
| 2884 | actual = da.transpose("z", ..., "x", transpose_coords=True) |
| 2885 | assert_equal(expected, actual) |
| 2886 | |
| 2887 | # same as previous but with a missing dimension |
| 2888 | actual = da.transpose( |
| 2889 | "z", "y", "x", "not_a_dim", transpose_coords=True, missing_dims="ignore" |
| 2890 | ) |
| 2891 | assert_equal(expected, actual) |
| 2892 | |
| 2893 | with pytest.raises(ValueError): |
| 2894 | da.transpose("x", "y") |
| 2895 | |
| 2896 | with pytest.raises(ValueError): |
| 2897 | da.transpose("not_a_dim", "z", "x", ...) |
| 2898 | |
| 2899 | with pytest.warns(UserWarning): |
| 2900 | da.transpose("not_a_dim", "y", "x", ..., missing_dims="warn") |
| 2901 | |
| 2902 | def test_squeeze(self) -> None: |
| 2903 | assert_equal(self.dv.variable.squeeze(), self.dv.squeeze().variable) |
nothing calls this directly
no test coverage detected