From aafacd4ebcd4b553c2e5e05e78e0d499ad386f04 Mon Sep 17 00:00:00 2001 From: eschalk Date: Sun, 4 Feb 2024 20:56:24 +0100 Subject: [PATCH] Use int16 --- xarray/tests/test_formatting.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 9b6aaf7d632..708d249a9b8 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -824,19 +824,22 @@ def test_empty_cftimeindex_repr() -> None: def test_display_nbytes() -> None: xds = xr.Dataset( { - "foo": np.arange(1200, dtype=np.int64), - "bar": np.arange(111, dtype=np.int64), + "foo": np.arange(1200, dtype=np.int16), + "bar": np.arange(111, dtype=np.int16), } ) + # Note: int16 is used to ensure that dtype is shown in the + # numpy array representation for all OSes included Windows + with xr.set_options(display_nbytes=False): actual = repr(xds) expected = """ Dimensions: (foo: 1200, bar: 111) Coordinates: - * foo (foo) int64 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 - * bar (bar) int64 0 1 2 3 4 5 6 7 8 ... 103 104 105 106 107 108 109 110 + * foo (foo) int16 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 + * bar (bar) int16 0 1 2 3 4 5 6 7 8 ... 103 104 105 106 107 108 109 110 Data variables: *empty* """.strip() @@ -845,20 +848,20 @@ def test_display_nbytes() -> None: actual = repr(xds["foo"]) expected = """ -array([ 0, 1, 2, ..., 1197, 1198, 1199]) +array([ 0, 1, 2, ..., 1197, 1198, 1199], dtype=int16) Coordinates: - * foo (foo) int64 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 + * foo (foo) int16 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 """.strip() assert actual == expected with xr.set_options(display_nbytes=True): actual = repr(xds) expected = """ - + Dimensions: (foo: 1200, bar: 111) Coordinates: - * foo (foo) int64 10kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 - * bar (bar) int64 888B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 + * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 + * bar (bar) int16 222B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 Data variables: *empty* """.strip() @@ -866,9 +869,9 @@ def test_display_nbytes() -> None: actual = repr(xds["foo"]) expected = """ - -array([ 0, 1, 2, ..., 1197, 1198, 1199]) + +array([ 0, 1, 2, ..., 1197, 1198, 1199], dtype=int16) Coordinates: - * foo (foo) int64 10kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 + * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 """.strip() assert actual == expected