Skip to content

Conversation

@shoyer
Copy link
Member

@shoyer shoyer commented Jan 15, 2017

Fixes #680

This shortens the array portion of the DataArray repr to reasonable lengths for high dimensional arrays:

Array Old length New length
np.random.randn(500) 167 1
np.random.randn(20, 20) 150 7
np.random.randn(5, 10, 15) 254 24
np.random.randn(5, 10, 15, 3) 248 19
air_temperature['air'] 41 24
rasm['Tair'] 37 24

The last two entries refer to the corresponding datasets loaded from xarray.tutorial.load_dataset.

Importantly, this change does not preclude future improvements, such as those suggested in #1044.

Example of why I switched to lower precision:

In [24]: x = np.random.randn(20, 100)

In [25]: x
Out[25]:
array([[-0.11684307,  0.67454961, -0.0617408 , ..., -0.08199539,
         0.11447149,  1.18730556],
       [ 1.17061389, -0.72944301, -0.45572465, ...,  1.4337907 ,
        -0.80810471,  0.51210789],
       [-0.69365824, -1.1452782 ,  1.8398729 , ...,  0.06559557,
         1.77739577,  2.12243584],
       ...,
       [-2.52712434,  0.53711727, -0.08554198, ...,  0.79291491,
        -0.4017885 , -0.58840279],
       [ 0.12926157, -0.71417823, -0.40803449, ...,  0.97339737,
         1.58154386, -0.78457038],
       [ 1.71986036, -1.02348818,  1.79216626, ..., -0.11309842,
        -1.00089845,  0.11611589]])

In [27]: print(xr.core.formatting.short_array_repr(x))
array([[-0.116843,  0.67455 , -0.061741, ..., -0.081995,  0.114471,  1.187306],
       [ 1.170614, -0.729443, -0.455725, ...,  1.433791, -0.808105,  0.512108],
       [-0.693658, -1.145278,  1.839873, ...,  0.065596,  1.777396,  2.122436],
       ...,
       [-2.527124,  0.537117, -0.085542, ...,  0.792915, -0.401788, -0.588403],
       [ 0.129262, -0.714178, -0.408034, ...,  0.973397,  1.581544, -0.78457 ],
       [ 1.71986 , -1.023488,  1.792166, ..., -0.113098, -1.000898,  0.116116]])

This shortens the array portion of DataArray repr to reasonable lengths for high
dimensional arrays:

Array                         | Old length | New length
------------------------------+------------+-----------
np.random.randn(500)          | 167        | 1
np.random.randn(20, 20)       | 150        | 7
np.random.randn(5, 10, 15)    | 254        | 24
np.random.randn(5, 10, 15, 3) | 248        | 19
air_temperature['air']        | 41         | 24
rasm['Tair']                  | 37         | 24

where the last two entries refer to the corresponding datasets loaded from
`xarray.tutorial.load_dataset`.

Importantly, this change does not preclude future improvements, such as those
suggested in GH1044.
@shoyer
Copy link
Member Author

shoyer commented Jan 15, 2017

Here is what @MaximilianR's example from #680 looks like with this change:

In [31]: print(xr.core.formatting.short_array_repr(np.nan * np.zeros((2, 2, 5, 6771, 58))))
array([[[[[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]],

         ...,
         [[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]]],


        [[[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]],

         ...,
         [[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]]]],



       [[[[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]],

         ...,
         [[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]]],


        [[[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]],

         ...,
         [[ nan, ...,  nan],
          ...,
          [ nan, ...,  nan]]]]])

It's not ideal (still pretty hard to make sense of the number of dimensions, and lots of wasted horizontal space), but it's definitely an improvement.

@shoyer
Copy link
Member Author

shoyer commented Jan 21, 2017

OK, merging this for v0.9

@shoyer shoyer merged commit 601c262 into pydata:master Jan 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants