home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 957439114

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
957439114 MDExOlB1bGxSZXF1ZXN0NzAwODY1NDE3 5662 Limit and format number of displayed dimensions in repr 14371165 closed 0     11 2021-08-01T09:12:24Z 2022-08-12T09:07:49Z 2022-01-03T17:38:49Z MEMBER   0 pydata/xarray/pulls/5662

When there's a lot of dims, create a new line and continue printing. If there's even more dims that even a few rows can't display them all then limit the number of dims displayed in similar fashion to coordinates.

Questions: * Where should this be used? Datasets, dataarrays, dimensions without coords? * Should dim_summary_limited be a straight replacement for dim_summary? I'm not super familiar with all the places it is used so I'm unsure. * Should we print the number of dims shown and the total number of dims? If yes, then we need to rethink how the dimensions are displayed, as it's not possible with the current style. See the example with short names.

  • [x] Closes #5546
  • [x] Tests added
  • [x] Passes pre-commit run --all-files
  • [x] User visible changes (including notable bug fixes) are documented in whats-new.rst

Test case: ```python import numpy as np import xarray as xr

A few dims with long names:

a = np.arange(0, 24) data_vars = dict() for i in a: data_vars[f"long_variable_name_{i}"] = xr.DataArray( name=f"long_variable_name_{i}", data=np.arange(0, 20), dims=[f"long_coord_name_{i}x"], coords={f"long_coord_name{i}x": np.arange(0, 20) * 2}, ) ds0 = xr.Dataset(data_vars) ds0.attrs = {f"attr{k}": 2 for k in a}

print(ds0) <xarray.Dataset> Dimensions: (long_coord_name_0_x: 20, long_coord_name_10_x: 20, long_coord_name_11_x: 20, long_coord_name_12_x: 20, long_coord_name_13_x: 20, long_coord_name_14_x: 20, long_coord_name_15_x: 20, long_coord_name_16_x: 20, long_coord_name_17_x: 20, long_coord_name_18_x: 20, long_coord_name_19_x: 20, long_coord_name_1_x: 20, long_coord_name_20_x: 20, long_coord_name_21_x: 20, long_coord_name_22_x: 20, long_coord_name_23_x: 20, long_coord_name_2_x: 20, long_coord_name_3_x: 20, long_coord_name_4_x: 20, long_coord_name_5_x: 20, long_coord_name_6_x: 20, long_coord_name_7_x: 20, long_coord_name_8_x: 20, long_coord_name_9_x: 20) Coordinates: (12/24) * long_coord_name_0_x (long_coord_name_0_x) int32 0 2 4 6 8 ... 32 34 36 38 * long_coord_name_1_x (long_coord_name_1_x) int32 0 2 4 6 8 ... 32 34 36 38 * long_coord_name_2_x (long_coord_name_2_x) int32 0 2 4 6 8 ... 32 34 36 38 * long_coord_name_3_x (long_coord_name_3_x) int32 0 2 4 6 8 ... 32 34 36 38 * long_coord_name_4_x (long_coord_name_4_x) int32 0 2 4 6 8 ... 32 34 36 38 * long_coord_name_5_x (long_coord_name_5_x) int32 0 2 4 6 8 ... 32 34 36 38 ... * long_coord_name_18_x (long_coord_name_18_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_19_x (long_coord_name_19_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_20_x (long_coord_name_20_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_21_x (long_coord_name_21_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_22_x (long_coord_name_22_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_23_x (long_coord_name_23_x) int32 0 2 4 6 ... 32 34 36 38 Data variables: (12/24) long_variable_name_0 (long_coord_name_0_x) int32 0 1 2 3 4 ... 16 17 18 19 long_variable_name_1 (long_coord_name_1_x) int32 0 1 2 3 4 ... 16 17 18 19 long_variable_name_2 (long_coord_name_2_x) int32 0 1 2 3 4 ... 16 17 18 19 long_variable_name_3 (long_coord_name_3_x) int32 0 1 2 3 4 ... 16 17 18 19 long_variable_name_4 (long_coord_name_4_x) int32 0 1 2 3 4 ... 16 17 18 19 long_variable_name_5 (long_coord_name_5_x) int32 0 1 2 3 4 ... 16 17 18 19 ... long_variable_name_18 (long_coord_name_18_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_19 (long_coord_name_19_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_20 (long_coord_name_20_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_21 (long_coord_name_21_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_22 (long_coord_name_22_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_23 (long_coord_name_23_x) int32 0 1 2 3 ... 16 17 18 19 Attributes: (12/24) attr_0: 2 attr_1: 2 attr_2: 2 attr_3: 2 attr_4: 2 attr_5: 2 ... attr_18: 2 attr_19: 2 attr_20: 2 attr_21: 2 attr_22: 2 attr_23: 2 ```

```python

Many dims with long names:

a = np.arange(0, 200) data_vars = dict() for i in a: data_vars[f"long_variable_name_{i}"] = xr.DataArray( name=f"long_variable_name_{i}", data=np.arange(0, 20), dims=[f"long_coord_name_{i}x"], coords={f"long_coord_name{i}x": np.arange(0, 20) * 2}, ) ds1 = xr.Dataset(data_vars) ds1.attrs = {f"attr{k}": 2 for k in a}

print(ds1) <xarray.Dataset> Dimensions: (long_coord_name_0_x: 20, long_coord_name_100_x: 20, long_coord_name_101_x: 20, long_coord_name_102_x: 20, long_coord_name_103_x: 20, long_coord_name_104_x: 20, ... long_coord_name_94_x: 20, long_coord_name_95_x: 20, long_coord_name_96_x: 20, long_coord_name_97_x: 20, long_coord_name_98_x: 20, long_coord_name_99_x: 20, long_coord_name_9_x: 20) Coordinates: (12/200) * long_coord_name_0_x (long_coord_name_0_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_1_x (long_coord_name_1_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_2_x (long_coord_name_2_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_3_x (long_coord_name_3_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_4_x (long_coord_name_4_x) int32 0 2 4 6 ... 32 34 36 38 * long_coord_name_5_x (long_coord_name_5_x) int32 0 2 4 6 ... 32 34 36 38 ... * long_coord_name_194_x (long_coord_name_194_x) int32 0 2 4 6 ... 34 36 38 * long_coord_name_195_x (long_coord_name_195_x) int32 0 2 4 6 ... 34 36 38 * long_coord_name_196_x (long_coord_name_196_x) int32 0 2 4 6 ... 34 36 38 * long_coord_name_197_x (long_coord_name_197_x) int32 0 2 4 6 ... 34 36 38 * long_coord_name_198_x (long_coord_name_198_x) int32 0 2 4 6 ... 34 36 38 * long_coord_name_199_x (long_coord_name_199_x) int32 0 2 4 6 ... 34 36 38 Data variables: (12/200) long_variable_name_0 (long_coord_name_0_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_1 (long_coord_name_1_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_2 (long_coord_name_2_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_3 (long_coord_name_3_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_4 (long_coord_name_4_x) int32 0 1 2 3 ... 16 17 18 19 long_variable_name_5 (long_coord_name_5_x) int32 0 1 2 3 ... 16 17 18 19 ... long_variable_name_194 (long_coord_name_194_x) int32 0 1 2 3 ... 17 18 19 long_variable_name_195 (long_coord_name_195_x) int32 0 1 2 3 ... 17 18 19 long_variable_name_196 (long_coord_name_196_x) int32 0 1 2 3 ... 17 18 19 long_variable_name_197 (long_coord_name_197_x) int32 0 1 2 3 ... 17 18 19 long_variable_name_198 (long_coord_name_198_x) int32 0 1 2 3 ... 17 18 19 long_variable_name_199 (long_coord_name_199_x) int32 0 1 2 3 ... 17 18 19 Attributes: (12/200) attr_0: 2 attr_1: 2 attr_2: 2 attr_3: 2 attr_4: 2 attr_5: 2 ... attr_194: 2 attr_195: 2 attr_196: 2 attr_197: 2 attr_198: 2 attr_199: 2 ```

```python

Many dims with short names:

data_vars = dict() for i in a: data_vars[f"n_{i}"] = xr.DataArray( name=f"n_{i}", data=np.arange(0, 20), dims=[f"{i}x"], coords={f"{i}_x": np.arange(0, 20) * 2}, ) ds2 = xr.Dataset(data_vars) ds2.attrs = {f"attr{k}": 2 for k in a}

print(ds2) <xarray.Dataset> Dimensions: (0_x: 20, 100_x: 20, 101_x: 20, 102_x: 20, 103_x: 20, 104_x: 20, 105_x: 20, 106_x: 20, 107_x: 20, 108_x: 20, 109_x: 20, 10_x: 20, 110_x: 20, 111_x: 20, 112_x: 20, 113_x: 20, 114_x: 20, 115_x: 20, 116_x: 20, 117_x: 20, 118_x: 20, 119_x: 20, 11_x: 20, 120_x: 20, 121_x: 20, 122_x: 20, 123_x: 20, 124_x: 20, 125_x: 20, 126_x: 20, 127_x: 20, 128_x: 20, 129_x: 20, 12_x: 20, 130_x: 20, 131_x: 20, ... 71_x: 20, 72_x: 20, 73_x: 20, 74_x: 20, 75_x: 20, 76_x: 20, 77_x: 20, 78_x: 20, 79_x: 20, 7_x: 20, 80_x: 20, 81_x: 20, 82_x: 20, 83_x: 20, 84_x: 20, 85_x: 20, 86_x: 20, 87_x: 20, 88_x: 20, 89_x: 20, 8_x: 20, 90_x: 20, 91_x: 20, 92_x: 20, 93_x: 20, 94_x: 20, 95_x: 20, 96_x: 20, 97_x: 20, 98_x: 20, 99_x: 20, 9_x: 20) Coordinates: (12/200) * 0_x (0_x) int32 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 * 1_x (1_x) int32 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 * 2_x (2_x) int32 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 * 3_x (3_x) int32 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 * 4_x (4_x) int32 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 * 5_x (5_x) int32 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 ... * 194_x (194_x) int32 0 2 4 6 8 10 12 14 16 ... 22 24 26 28 30 32 34 36 38 * 195_x (195_x) int32 0 2 4 6 8 10 12 14 16 ... 22 24 26 28 30 32 34 36 38 * 196_x (196_x) int32 0 2 4 6 8 10 12 14 16 ... 22 24 26 28 30 32 34 36 38 * 197_x (197_x) int32 0 2 4 6 8 10 12 14 16 ... 22 24 26 28 30 32 34 36 38 * 198_x (198_x) int32 0 2 4 6 8 10 12 14 16 ... 22 24 26 28 30 32 34 36 38 * 199_x (199_x) int32 0 2 4 6 8 10 12 14 16 ... 22 24 26 28 30 32 34 36 38 Data variables: (12/200) n_0 (0_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_1 (1_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_2 (2_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_3 (3_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_4 (4_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_5 (5_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... n_194 (194_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_195 (195_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_196 (196_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_197 (197_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_198 (198_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 n_199 (199_x) int32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Attributes: (12/200) attr_0: 2 attr_1: 2 attr_2: 2 attr_3: 2 attr_4: 2 attr_5: 2 ... attr_194: 2 attr_195: 2 attr_196: 2 attr_197: 2 attr_198: 2 attr_199: 2 ```

```python

DataArray with many dimensions:

dims = {f"dim_{v}": 2 for v in np.arange(12)} a = xr.DataArray( name="LongDataArrayName", data=np.random.randn(*dims.values()), dims=dims.keys(), coords={k: np.arange(v) * (i + 1) for i, (k, v) in enumerate(dims.items())}, ) print(a) <xarray.DataArray 'LongDataArrayName' (dim_0: 2, dim_1: 2, dim_2: 2, dim_3: 2, dim_4: 2, dim_5: 2, dim_6: 2, dim_7: 2, dim_8: 2, dim_9: 2, dim_10: 2, dim_11: 2)> array([[[[[[[[[[[[ 8.28296160e-01, 2.08993090e-01], [ 8.70468836e-01, 8.90423004e-01]],

            [[ 7.34784427e-01,  2.05408058e-01],
             [-8.57071909e-02,  8.44265228e-01]]],


           [[[-9.35953498e-01, -1.28911601e+00],
             [ 1.10041466e+00,  6.65778297e-02]],

            [[-1.20951652e+00,  6.75763964e-01],
             [-4.71836513e-02,  9.06088516e-01]]]],



          [[[[ 1.59629635e+00,  7.32189004e-01],
             [-3.93944434e-01,  2.46067012e+00]],

            [[ 1.20534658e-01, -1.10855175e+00],
             [ 1.75768289e+00,  1.82771876e+00]]],

... [[[ 1.24664897e+00, 1.72548620e+00], [-7.64230130e-02, -7.96243220e-01]],

            [[-7.02358327e-01,  2.20921513e+00],
             [-7.45919399e-01,  8.16166442e-01]]]],



          [[[[-1.06278662e+00, -3.01061594e-01],
             [-2.68674730e-01,  7.61941899e-01]],

            [[-7.40916926e-01,  1.85122750e+00],
             [-5.42460065e-02, -7.57741769e-01]]],


           [[[-4.12356234e-02,  7.41777992e-01],
             [-1.36243505e+00, -1.25845181e+00]],

            [[-7.42535368e-01,  1.13262286e-01],
             [ 1.03699306e+00, -8.51127899e-01]]]]]]]]]]]])

Coordinates: * dim_0 (dim_0) int32 0 1 * dim_1 (dim_1) int32 0 2 * dim_2 (dim_2) int32 0 3 * dim_3 (dim_3) int32 0 4 * dim_4 (dim_4) int32 0 5 * dim_5 (dim_5) int32 0 6 * dim_6 (dim_6) int32 0 7 * dim_7 (dim_7) int32 0 8 * dim_8 (dim_8) int32 0 9 * dim_9 (dim_9) int32 0 10 * dim_10 (dim_10) int32 0 11 * dim_11 (dim_11) int32 0 12 ```

```python

DataArray with many dimensions but no coords:

dims = {f"dim_{v}": 2 for v in np.arange(12)} a = xr.DataArray( name="LongDataArrayName", data=np.random.randn(*dims.values()), dims=dims.keys(), ) print(a) <xarray.DataArray 'LongDataArrayName' (dim_0: 2, dim_1: 2, dim_2: 2, dim_3: 2, dim_4: 2, dim_5: 2, dim_6: 2, dim_7: 2, dim_8: 2, dim_9: 2, dim_10: 2, dim_11: 2)> array([[[[[[[[[[[[ 2.53218063e-02, -2.01034380e+00], [ 3.07624042e-01, 1.82085569e-01]],

            [[ 1.23998647e+00,  2.80961964e-01],
             [ 5.22623248e-01, -2.10621456e-01]]],


           [[[ 1.55794218e+00, -1.32803310e+00],
             [-7.41474289e-01, -3.35995545e-01]],

            [[ 9.96489723e-03, -1.84197059e-01],
             [-1.24173835e+00,  4.94205388e-01]]]],



          [[[[-2.11962358e-01,  1.18012909e+00],
             [-4.62991218e-01, -9.49171994e-01]],

            [[ 3.90534280e-01, -2.63453002e+00],
             [ 3.57944636e-01,  2.16335768e-01]]],

... [[[-1.11275429e+00, -9.33574221e-01], [ 8.62574702e-01, 1.14185983e+00]],

            [[ 1.36795402e+00,  1.14331852e+00],
             [ 5.96785305e-01,  1.47307855e+00]]]],



          [[[[ 1.95270558e+00, -7.76150298e-01],
             [ 2.05301468e+00, -1.15633640e+00]],

            [[-9.45507288e-01,  1.21096830e+00],
             [ 1.59340121e+00, -3.60261023e-01]]],


           [[[ 2.25343528e+00, -2.84332626e-01],
             [ 1.86644712e-01, -2.78371182e-01]],

            [[-8.86245009e-01, -4.00356195e-01],
             [-2.44036388e-01, -1.53543170e+00]]]]]]]]]]]])

Dimensions without coordinates: dim_0, dim_1, dim_2, dim_3, dim_4, dim_5, dim_6, dim_7, dim_8, dim_9, dim_10, dim_11 ```

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5662/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 pull

Links from other tables

  • 1 row from issues_id in issues_labels
  • 11 rows from issue in issue_comments
Powered by Datasette · Queries took 0.752ms · About: xarray-datasette