Skip to content

Commit cd0ff19

Browse files
committed
Merge pull request #194 from shoyer/consistent-names
Consistently use shorter names: always use 'attrs', 'coords' and 'dims'
2 parents db292af + 6f0fca3 commit cd0ff19

21 files changed

+537
-516
lines changed

doc/_static/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
examples*.png

doc/api.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Attributes and underlying data
2020
.. autosummary::
2121
:toctree: generated/
2222

23-
Dataset.coordinates
23+
Dataset.coords
2424
Dataset.noncoordinates
25-
Dataset.dimensions
25+
Dataset.dims
2626
Dataset.attrs
2727

2828
Dataset contents
@@ -98,7 +98,6 @@ IO / Conversion
9898

9999
Dataset.to_netcdf
100100
Dataset.dumps
101-
Dataset.dump_to_store
102101
Dataset.close
103102
Dataset.to_dataframe
104103
Dataset.from_dataframe
@@ -147,7 +146,8 @@ Attributes and underlying data
147146

148147
DataArray.values
149148
DataArray.as_index
150-
DataArray.coordinates
149+
DataArray.coords
150+
DataArray.dims
151151
DataArray.name
152152
DataArray.dataset
153153
DataArray.attrs

doc/examples.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Monthly averaging
6060
with values given by the first date of the month in which each time
6161
falls.
6262
"""
63-
time = xray_obj.coordinates['time']
63+
time = xray_obj.coords['time']
6464
values = pd.Index(time).to_period('M').to_timestamp()
6565
return xray.DataArray(values, [time], name='year_month')
6666
@@ -74,7 +74,7 @@ Monthly averaging
7474
:suppress:
7575
7676
def year_month(xray_obj):
77-
time = xray_obj.coordinates['time']
77+
time = xray_obj.coords['time']
7878
values = time.as_index.to_period('M').to_timestamp()
7979
return xray.DataArray(values, [time], name='year_month')
8080
@@ -83,7 +83,7 @@ Monthly averaging
8383
8484
monthly_avg = ds.groupby(year_month(ds)).mean('time')
8585
86-
@savefig examples_tmin_tmax_plot2.png width=4in
86+
@savefig examples_tmin_tmax_plot_mean.png width=4in
8787
monthly_avg.mean('x').to_dataframe().plot(style='s-')
8888
8989

doc/faq.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ and coordinates, xray supports arbitrary metadata in the form of global
6969

7070
Automatic interpretation of labels is powerful but also reduces flexibility.
7171
With xray, we draw a firm line between labels that the library understands
72-
(``dimensions`` and ``coordinates``) and labels for users and user code
73-
(``attrs``). For example, we do not automatically intrepret and enforce units
74-
or `CF conventions`_. (An exception is serialization to netCDF with
72+
(``dims`` and ``coords``) and labels for users and user code (``attrs``). For
73+
example, we do not automatically intrepret and enforce units or `CF
74+
conventions`_. (An exception is serialization to netCDF with
7575
``cf_conventions=True``.)
7676

7777
.. _CF conventions: http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.6/cf-conventions.html

doc/tutorial.rst

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ To get started, we will import numpy, pandas and xray:
2222
multi-dimensional array. It has three key properties:
2323

2424
- ``values``: a numpy.ndarray holding the array's values
25-
- ``dimensions``: names for each axis, e.g., ``('x', 'y', 'z')``
26-
- ``coordinates``: tick labels along each dimension, e.g., 1-dimensional arrays
27-
of numbers, datetime objects or strings.
25+
- ``dims``: dimension names for each axis, e.g., ``('x', 'y', 'z')``
26+
- ``coords``: tick labels along each dimension, e.g., 1-dimensional
27+
arrays of numbers, datetime objects or strings.
2828

29-
xray uses ``dimensions`` and ``coordinates`` to enable its core metadata aware
29+
xray uses ``dims`` and ``coords`` to enable its core metadata aware
3030
operations. Dimensions provide names that xray uses instead of the ``axis``
3131
argument found in many numpy functions. Coordinates enable fast label based
3232
indexing and alignment, like the ``index`` found on a pandas
@@ -48,8 +48,7 @@ a numpy ndarray), a list of coordinates labels and a list of dimension names:
4848
data = np.random.rand(4, 3)
4949
locs = ['IA', 'IL', 'IN']
5050
times = pd.date_range('2000-01-01', periods=4)
51-
foo = xray.DataArray(data, coordinates=[times, locs],
52-
dimensions=['time', 'space'])
51+
foo = xray.DataArray(data, coords=[times, locs], dims=['time', 'space'])
5352
foo
5453
5554
All of these arguments (except for ``data``) are optional, and will be filled
@@ -86,8 +85,8 @@ Let's take a look at the important properties on our array:
8685
.. ipython:: python
8786
8887
foo.values
89-
foo.dimensions
90-
foo.coordinates
88+
foo.dims
89+
foo.coords
9190
foo.attrs
9291
print(foo.name)
9392
@@ -99,13 +98,13 @@ Now fill in some of that missing metadata:
9998
foo.attrs['units'] = 'meters'
10099
foo
101100
102-
The ``coordinates`` property is ``dict`` like. Individual coordinates can be
101+
The ``coords`` property is ``dict`` like. Individual coordinates can be
103102
accessed by name or axis number:
104103

105104
.. ipython:: python
106105
107-
foo.coordinates['time']
108-
foo.coordinates[0]
106+
foo.coords['time']
107+
foo.coords[0]
109108
110109
These are :py:class:`xray.Coordinate` objects, which contain tick-labels for
111110
each dimension.
@@ -197,7 +196,7 @@ was filled with an array of ascending integers of the proper length:
197196
198197
Noncoordinate and coordinates are listed explicitly by the
199198
:py:attr:`~xray.Dataset.noncoordinates` and
200-
:py:attr:`~xray.Dataset.coordinates` attributes.
199+
:py:attr:`~xray.Dataset.coords` attributes.
201200

202201
There are also a few derived variables based on datetime coordinates that you
203202
can access from a dataset (e.g., "year", "month" and "day"), even if you didn't
@@ -399,7 +398,7 @@ operation over any or all non-coordinates in a dataset by using
399398
Aggregation
400399
~~~~~~~~~~~
401400

402-
Aggregation methods from ndarray have been updated to take a `dimension`
401+
Aggregation methods from ndarray have been updated to take a `dim`
403402
argument instead of `axis`. This allows for very intuitive syntax for
404403
aggregation methods that are applied along particular dimension(s):
405404

@@ -453,7 +452,7 @@ arrays with different sizes aligned along different dimensions:
453452
454453
a = xray.DataArray([1, 2, 3, 4], [['a', 'b', 'c', 'd']], ['x'])
455454
a
456-
b = xray.DataArray([-1, -2, -3], dimensions=['y'])
455+
b = xray.DataArray([-1, -2, -3], dims=['y'])
457456
b
458457
459458
With xray, we can apply binary mathematical operations to these arrays, and
@@ -1112,7 +1111,7 @@ and DataArray variables. It supports the numpy ndarray interface, but is
11121111
extended to support and use basic metadata (not including index values). It
11131112
consists of:
11141113

1115-
1. ``dimensions``: A tuple of dimension names.
1114+
1. ``dims``: A tuple of dimension names.
11161115
2. ``values``: The N-dimensional array (for example, of type
11171116
:py:class:`numpy.ndarray`) storing the array's data. It must have the same
11181117
number of dimensions as the length of ``dimensions``.

test/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def assertVariableIdentical(self, v1, v2):
7272
assert as_variable(v1).identical(v2), (v1, v2)
7373

7474
def assertVariableAllClose(self, v1, v2, rtol=1e-05, atol=1e-08):
75-
self.assertEqual(v1.dimensions, v2.dimensions)
75+
self.assertEqual(v1.dims, v2.dims)
7676
allclose = data_allclose_or_equiv(
7777
v1.values, v2.values, rtol=rtol, atol=atol)
7878
assert allclose, (v1.values, v2.values)
@@ -113,10 +113,10 @@ def assertDatasetAllClose(self, d1, d2, rtol=1e-05, atol=1e-08):
113113
self.assertVariableAllClose(v1, v2, rtol=rtol, atol=atol)
114114

115115
def assertCoordinatesEqual(self, d1, d2):
116-
self.assertEqual(sorted(d1.coordinates), sorted(d2.coordinates))
117-
for k in d1.coordinates:
118-
v1 = d1.coordinates[k]
119-
v2 = d2.coordinates[k]
116+
self.assertEqual(sorted(d1.coords), sorted(d2.coords))
117+
for k in d1.coords:
118+
v1 = d1.coords[k]
119+
v2 = d2.coords[k]
120120
self.assertVariableEqual(v1, v2)
121121

122122
def assertDataArrayEqual(self, ar1, ar2):

0 commit comments

Comments
 (0)