Skip to content

Commit

Permalink
Better repr for coordinates without dimensions (#1236)
Browse files Browse the repository at this point in the history
* Better repr for coordinates without dimensions

Fixes GH1199

* Fix whats new
  • Loading branch information
shoyer committed Jan 30, 2017
1 parent 384c9b3 commit e98d85f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions doc/data-structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ in with default values:
As you can see, dimension names are always present in the xarray data model: if
you do not provide them, defaults of the form ``dim_N`` will be created.
However, coordinates are optional. If you do not specific coordinates for a
dimension, the axis name will appear under the list of "Unindexed dimensions".
However, coordinates are always optional, and dimensions do not have automatic
coordinate labels.

.. note::

Expand Down
21 changes: 14 additions & 7 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ What's New
import xarray as xr
np.random.seed(123456)
.. _whats-new.0.9.1:

v0.9.1 (30 January 2017)
------------------------

Renamed the "Unindexed dimensions" section in the ``Dataset`` and
``DataArray`` repr (added in v0.9.0) to "Dimensions without coordinates"
(:issue:`1199`).

.. _whats-new.0.9.0:

v0.9.0 (25 January 2017)
Expand Down Expand Up @@ -48,9 +58,9 @@ Breaking changes
~~~~~~~~~~~~~~~~

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

.. ipython::
:verbatim:
Expand All @@ -59,10 +69,7 @@ Breaking changes
Out[1]:
<xarray.Dataset>
Dimensions: (x: 1, y: 2)
Coordinates:
*empty*
Unindexed dimensions:
x, y
Dimensions without coordinates: x, y
Data variables:
foo (x, y) int64 1 2

Expand Down
5 changes: 3 additions & 2 deletions xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def unindexed_dims_repr(dims, coords):
unindexed_dims = [d for d in dims if d not in coords]
if unindexed_dims:
dims_str = u', '.join(u'%s' % d for d in unindexed_dims)
return u'Unindexed dimensions:\n' + u' ' * 4 + dims_str
return u'Dimensions without coordinates: ' + dims_str
else:
return None

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

summary.append(coords_repr(ds.coords, col_width=col_width))
if ds.coords:
summary.append(coords_repr(ds.coords, col_width=col_width))

unindexed_dims_str = unindexed_dims_repr(ds.dims, ds.coords)
if unindexed_dims_str:
Expand Down
3 changes: 1 addition & 2 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def test_repr(self):
Coordinates:
* x (x) int64 0 1 2
other int64 0
Unindexed dimensions:
time
Dimensions without coordinates: time
Attributes:
foo: bar""")
self.assertEqual(expected, repr(data_array))
Expand Down
7 changes: 1 addition & 6 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def test_repr(self):
* dim2 (dim2) float64 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
* dim3 (dim3) %s 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
numbers (dim3) int64 0 1 2 0 0 1 1 2 2 3
Unindexed dimensions:
dim1
Dimensions without coordinates: dim1
Data variables:
var1 (dim1, dim2) float64 -1.086 0.9973 0.283 -1.506 -0.5786 1.651 ...
var2 (dim1, dim2) float64 1.162 -1.097 -2.123 1.04 -0.4034 -0.126 ...
Expand All @@ -110,8 +109,6 @@ def test_repr(self):
expected = dedent("""\
<xarray.Dataset>
Dimensions: ()
Coordinates:
*empty*
Data variables:
*empty*""")
actual = '\n'.join(x.rstrip() for x in repr(Dataset()).split('\n'))
Expand All @@ -123,8 +120,6 @@ def test_repr(self):
expected = dedent("""\
<xarray.Dataset>
Dimensions: ()
Coordinates:
*empty*
Data variables:
foo float64 1.0""")
actual = '\n'.join(x.rstrip() for x in repr(data).split('\n'))
Expand Down

0 comments on commit e98d85f

Please sign in to comment.