Skip to content

Commit e98d85f

Browse files
authored
Better repr for coordinates without dimensions (#1236)
* Better repr for coordinates without dimensions Fixes GH1199 * Fix whats new
1 parent 384c9b3 commit e98d85f

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

doc/data-structures.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ in with default values:
6969
7070
As you can see, dimension names are always present in the xarray data model: if
7171
you do not provide them, defaults of the form ``dim_N`` will be created.
72-
However, coordinates are optional. If you do not specific coordinates for a
73-
dimension, the axis name will appear under the list of "Unindexed dimensions".
72+
However, coordinates are always optional, and dimensions do not have automatic
73+
coordinate labels.
7474

7575
.. note::
7676

doc/whats-new.rst

+14-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ What's New
1313
import xarray as xr
1414
np.random.seed(123456)
1515
16+
17+
.. _whats-new.0.9.1:
18+
19+
v0.9.1 (30 January 2017)
20+
------------------------
21+
22+
Renamed the "Unindexed dimensions" section in the ``Dataset`` and
23+
``DataArray`` repr (added in v0.9.0) to "Dimensions without coordinates"
24+
(:issue:`1199`).
25+
1626
.. _whats-new.0.9.0:
1727

1828
v0.9.0 (25 January 2017)
@@ -48,9 +58,9 @@ Breaking changes
4858
~~~~~~~~~~~~~~~~
4959

5060
- Index coordinates for each dimensions are now optional, and no longer created
51-
by default :issue:`1017`. You can identify such dimensions without indexes by
52-
their appearance in list of "Unindexed dimensions" in the ``Dataset`` or
53-
``DataArray`` repr:
61+
by default :issue:`1017`. You can identify such dimensions without coordinates
62+
by their appearance in list of "Dimensions without coordinates" in the
63+
``Dataset`` or ``DataArray`` repr:
5464

5565
.. ipython::
5666
:verbatim:
@@ -59,10 +69,7 @@ Breaking changes
5969
Out[1]:
6070
<xarray.Dataset>
6171
Dimensions: (x: 1, y: 2)
62-
Coordinates:
63-
*empty*
64-
Unindexed dimensions:
65-
x, y
72+
Dimensions without coordinates: x, y
6673
Data variables:
6774
foo (x, y) int64 1 2
6875

xarray/core/formatting.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def unindexed_dims_repr(dims, coords):
327327
unindexed_dims = [d for d in dims if d not in coords]
328328
if unindexed_dims:
329329
dims_str = u', '.join(u'%s' % d for d in unindexed_dims)
330-
return u'Unindexed dimensions:\n' + u' ' * 4 + dims_str
330+
return u'Dimensions without coordinates: ' + dims_str
331331
else:
332332
return None
333333

@@ -399,7 +399,8 @@ def dataset_repr(ds):
399399
dims_start = pretty_print(u'Dimensions:', col_width)
400400
summary.append(u'%s(%s)' % (dims_start, dim_summary(ds)))
401401

402-
summary.append(coords_repr(ds.coords, col_width=col_width))
402+
if ds.coords:
403+
summary.append(coords_repr(ds.coords, col_width=col_width))
403404

404405
unindexed_dims_str = unindexed_dims_repr(ds.dims, ds.coords)
405406
if unindexed_dims_str:

xarray/tests/test_dataarray.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def test_repr(self):
4747
Coordinates:
4848
* x (x) int64 0 1 2
4949
other int64 0
50-
Unindexed dimensions:
51-
time
50+
Dimensions without coordinates: time
5251
Attributes:
5352
foo: bar""")
5453
self.assertEqual(expected, repr(data_array))

xarray/tests/test_dataset.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def test_repr(self):
9191
* dim2 (dim2) float64 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
9292
* dim3 (dim3) %s 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
9393
numbers (dim3) int64 0 1 2 0 0 1 1 2 2 3
94-
Unindexed dimensions:
95-
dim1
94+
Dimensions without coordinates: dim1
9695
Data variables:
9796
var1 (dim1, dim2) float64 -1.086 0.9973 0.283 -1.506 -0.5786 1.651 ...
9897
var2 (dim1, dim2) float64 1.162 -1.097 -2.123 1.04 -0.4034 -0.126 ...
@@ -110,8 +109,6 @@ def test_repr(self):
110109
expected = dedent("""\
111110
<xarray.Dataset>
112111
Dimensions: ()
113-
Coordinates:
114-
*empty*
115112
Data variables:
116113
*empty*""")
117114
actual = '\n'.join(x.rstrip() for x in repr(Dataset()).split('\n'))
@@ -123,8 +120,6 @@ def test_repr(self):
123120
expected = dedent("""\
124121
<xarray.Dataset>
125122
Dimensions: ()
126-
Coordinates:
127-
*empty*
128123
Data variables:
129124
foo float64 1.0""")
130125
actual = '\n'.join(x.rstrip() for x in repr(data).split('\n'))

0 commit comments

Comments
 (0)