Skip to content

Commit

Permalink
Use int16
Browse files Browse the repository at this point in the history
  • Loading branch information
etienneschalk committed Feb 4, 2024
1 parent 560a35d commit aafacd4
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<xarray.Dataset>
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()
Expand All @@ -845,30 +848,30 @@ def test_display_nbytes() -> None:
actual = repr(xds["foo"])
expected = """
<xarray.DataArray 'foo' (foo: 1200)>
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 = """
<xarray.Dataset 10kB>
<xarray.Dataset 3kB>
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()
assert actual == expected

actual = repr(xds["foo"])
expected = """
<xarray.DataArray 'foo' (foo: 1200) 10kB>
array([ 0, 1, 2, ..., 1197, 1198, 1199])
<xarray.DataArray 'foo' (foo: 1200) 2kB>
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

0 comments on commit aafacd4

Please sign in to comment.