| 1035 | |
| 1036 | |
| 1037 | def test_display_nbytes() -> None: |
| 1038 | xds = xr.Dataset( |
| 1039 | { |
| 1040 | "foo": np.arange(1200, dtype=np.int16), |
| 1041 | "bar": np.arange(111, dtype=np.int16), |
| 1042 | } |
| 1043 | ) |
| 1044 | |
| 1045 | # Note: int16 is used to ensure that dtype is shown in the |
| 1046 | # numpy array representation for all OSes included Windows |
| 1047 | |
| 1048 | actual = repr(xds) |
| 1049 | expected = """ |
| 1050 | <xarray.Dataset> Size: 3kB |
| 1051 | Dimensions: (foo: 1200, bar: 111) |
| 1052 | Coordinates: |
| 1053 | * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 |
| 1054 | * bar (bar) int16 222B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 |
| 1055 | Data variables: |
| 1056 | *empty* |
| 1057 | """.strip() |
| 1058 | assert actual == expected |
| 1059 | |
| 1060 | actual = repr(xds["foo"]) |
| 1061 | array_repr = repr(xds.foo.data).replace("\n ", "") |
| 1062 | expected = f""" |
| 1063 | <xarray.DataArray 'foo' (foo: 1200)> Size: 2kB |
| 1064 | {array_repr} |
| 1065 | Coordinates: |
| 1066 | * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 |
| 1067 | """.strip() |
| 1068 | assert actual == expected |
| 1069 | |
| 1070 | |
| 1071 | def test_array_repr_dtypes(): |