Skip to content

Commit 2901009

Browse files
committed
Rename DatasetArray to DataArray
Per discussion in issue #85.
1 parent d498284 commit 2901009

File tree

11 files changed

+83
-83
lines changed

11 files changed

+83
-83
lines changed

doc/api.rst

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Dataset contents
3232
~~~~~~~~~~~~~~~~
3333

3434
Datasets implement the mapping interface with keys given by variable names
35-
and values given by ``DatasetArray`` objects focused on each variable name.
35+
and values given by ``DataArray`` objects focused on each variable name.
3636

3737
.. autosummary::
3838
:toctree: generated/
@@ -70,70 +70,70 @@ IO / Conversion
7070
Dataset.to_dataframe
7171

7272

73-
DatasetArray
74-
------------
73+
DataArray
74+
---------
7575

7676
.. autosummary::
7777
:toctree: generated/
7878

79-
DatasetArray
79+
DataArray
8080

8181
Selecting
8282
~~~~~~~~~
8383

8484
.. autosummary::
8585
:toctree: generated/
8686

87-
DatasetArray.loc
88-
DatasetArray.indexed_by
89-
DatasetArray.labeled_by
90-
DatasetArray.rename
91-
DatasetArray.select
92-
DatasetArray.unselect
93-
DatasetArray.squeeze
87+
DataArray.loc
88+
DataArray.indexed_by
89+
DataArray.labeled_by
90+
DataArray.rename
91+
DataArray.select
92+
DataArray.unselect
93+
DataArray.squeeze
9494

9595
Group operations
9696
~~~~~~~~~~~~~~~~
9797

9898
.. autosummary::
9999
:toctree: generated/
100100

101-
DatasetArray.groupby
102-
DatasetArray.concat
101+
DataArray.groupby
102+
DataArray.concat
103103

104104
Manipulating data
105105
~~~~~~~~~~~~~~~~~
106106

107107
.. autosummary::
108108
:toctree: generated/
109109

110-
DatasetArray.transpose
111-
DatasetArray.T
112-
DatasetArray.reduce
113-
DatasetArray.all
114-
DatasetArray.any
115-
DatasetArray.argmax
116-
DatasetArray.argmin
117-
DatasetArray.cumprod
118-
DatasetArray.cumsum
119-
DatasetArray.max
120-
DatasetArray.min
121-
DatasetArray.mean
122-
DatasetArray.prod
123-
DatasetArray.ptp
124-
DatasetArray.std
125-
DatasetArray.sum
126-
DatasetArray.var
110+
DataArray.transpose
111+
DataArray.T
112+
DataArray.reduce
113+
DataArray.all
114+
DataArray.any
115+
DataArray.argmax
116+
DataArray.argmin
117+
DataArray.cumprod
118+
DataArray.cumsum
119+
DataArray.max
120+
DataArray.min
121+
DataArray.mean
122+
DataArray.prod
123+
DataArray.ptp
124+
DataArray.std
125+
DataArray.sum
126+
DataArray.var
127127

128128
IO / Conversion
129129
~~~~~~~~~~~~~~~
130130

131131
.. autosummary::
132132
:toctree: generated/
133133

134-
DatasetArray.to_dataframe
135-
DatasetArray.to_series
136-
DatasetArray.copy
134+
DataArray.to_dataframe
135+
DataArray.to_series
136+
DataArray.copy
137137

138138

139139
XArray

doc/data-structures.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Data structures
22
===============
33

4-
``xray``'s core data structures are the ``Dataset``, ``XArray`` and ``DatasetArray``.
4+
``xray``'s core data structures are the ``Dataset``, ``XArray`` and
5+
``DataArray``.
56

67
Dataset
78
-------
@@ -32,22 +33,22 @@ XArray with dimensions `('space',)` results in a new XArray with dimensions
3233
``sum`` are overwritten to take a "dimension" argument instead of an "axis".
3334

3435
XArrays are light-weight objects used as the building block for datasets.
35-
However, usually manipulating data in the form of a DatasetArray should be
36+
However, usually manipulating data in the form of a DataArray should be
3637
preferred (see below), because they can use more complete metadata in the full
3738
of other dataset variables.
3839

39-
DatasetArray
40-
------------
40+
DataArray
41+
---------
4142

42-
``DatasetArray`` is a flexible hybrid of Dataset and XArray that attempts to
43-
provide the best of both in a single object. Under the covers, DatasetArrays
43+
``DataArray`` is a flexible hybrid of Dataset and XArray that attempts to
44+
provide the best of both in a single object. Under the covers, DataArrays
4445
are simply pointers to a dataset (the ``dataset`` attribute) and the name of a
4546
"focus variable" in the dataset (the ``focus`` attribute), which indicates to
4647
which variable array operations should be applied.
4748

48-
DatasetArray objects implement the broadcasting rules of XArray objects, but
49+
DataArray objects implement the broadcasting rules of XArray objects, but
4950
also use and maintain coordinates (aka "indices"). This means you can do
50-
intelligent (and fast!) label based indexing on DatasetArrays (via the
51+
intelligent (and fast!) label based indexing on DataArrays (via the
5152
``.loc`` attribute), do flexibly split-apply-combine operations with
5253
``groupby`` and also easily export them to ``pandas.DataFrame`` or
5354
``pandas.Series`` objects.

doc/getting-started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Let's create some ``XArray`` objects and put them in a ``Dataset``:
3434
This dataset contains two non-coordinate variables, ``temperature`` and
3535
``avg_rain``, as well as the coordinates ``time`` and ``us_state``.
3636

37-
We can now access the contents of ``ds`` as self-described ``DatasetArray``
37+
We can now access the contents of ``ds`` as self-described ``DataArray``
3838
objects:
3939

4040
.. ipython:: python

src/xray/common.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ def _summarize_attributes(data):
8282

8383

8484
def array_repr(arr):
85-
focus_str = ('%r ' % arr.focus) if hasattr(arr, 'focus') else ''
85+
name_str = ('%r ' % arr.name) if hasattr(arr, 'name') else ''
8686
dim_summary = ', '.join('%s: %s' % (k, v) for k, v
8787
in zip(arr.dimensions, arr.shape))
88-
summary = ['<xray.%s %s(%s)>'% (type(arr).__name__, focus_str,
89-
dim_summary)]
88+
summary = ['<xray.%s %s(%s)>'% (type(arr).__name__, name_str, dim_summary)]
9089
if arr.size < 1e5 or arr.in_memory():
9190
summary.append(repr(arr.data))
9291
else:

src/xray/dataset.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import common
1212
import groupby
1313
import utils
14-
from dataset_array import DatasetArray
14+
from dataset_array import DataArray
1515
from utils import FrozenOrderedDict, Frozen, remap_loc_indexers
1616

1717
date2num = nc4.date2num
@@ -99,7 +99,7 @@ class Dataset(Mapping):
9999
together form a self describing dataset.
100100
101101
Dataset implements the mapping interface with keys given by variable names
102-
and values given by DatasetArray objects for each variable name.
102+
and values given by DataArray objects for each variable name.
103103
104104
Note: the size of dimensions in a dataset cannot be changed.
105105
"""
@@ -135,7 +135,7 @@ def _as_variable(self, name, var, decode_cf=False):
135135
var = xarray.as_xarray(var)
136136
except TypeError:
137137
raise TypeError('Dataset variables must be of type '
138-
'DatasetArray or XArray, or a sequence of the '
138+
'DataArray or XArray, or a sequence of the '
139139
'form (dimensions, data[, attributes, encoding])')
140140
# this will unmask and rescale the data as well as convert
141141
# time variables to datetime indices.
@@ -278,20 +278,20 @@ def virtual_variables(self):
278278
def __getitem__(self, key):
279279
"""Access the array with the given variable name.
280280
"""
281-
return DatasetArray(self, key)
281+
return DataArray(self, key)
282282

283283
def __setitem__(self, key, value):
284284
"""Add an array to this dataset.
285285
286-
If value is a `DatasetArray`, call its `select()` method, rename it to
286+
If value is a `DataArray`, call its `select()` method, rename it to
287287
`key` and merge the contents of the resulting dataset into this
288288
dataset.
289289
290290
If value is an `XArray` object (or tuple of form
291291
`(dimensions, data[, attributes])`), add it to this dataset as a new
292292
variable.
293293
"""
294-
if isinstance(value, DatasetArray):
294+
if isinstance(value, DataArray):
295295
self.merge(value.rename(key).select().dataset, inplace=True,
296296
overwrite_vars=[key])
297297
else:
@@ -654,7 +654,7 @@ def groupby(self, group, squeeze=True):
654654
655655
Parameters
656656
----------
657-
group : str or DatasetArray
657+
group : str or DataArray
658658
Array whose unique values should be used to group this array. If a
659659
string, must be the name of a variable contained in this dataset.
660660
squeeze : boolean, optional
@@ -672,7 +672,7 @@ def groupby(self, group, squeeze=True):
672672
# merge in the group's dataset to allow group to be a virtual
673673
# variable in this dataset
674674
ds = self.merge(self[group].dataset)
675-
group = DatasetArray(ds, group)
675+
group = DataArray(ds, group)
676676
return groupby.GroupBy(self, group.name, group, squeeze=squeeze)
677677

678678
def squeeze(self, dimension=None):
@@ -720,7 +720,7 @@ def _add_dimension(self, dimension):
720720
dim_name = dimension
721721
else:
722722
dim_name, = dimension.dimensions
723-
if isinstance(dimension, DatasetArray):
723+
if isinstance(dimension, DataArray):
724724
self.merge(dimension._unselect_nonfocus_dims().dataset,
725725
inplace=True)
726726
else:
@@ -741,7 +741,7 @@ def concat(cls, datasets, dimension='concat_dimension', indexers=None,
741741
are listed in "concat_over") are expected to be equal.
742742
dimension : str or Array, optional
743743
Name of the dimension to stack along. If dimension is provided as
744-
an XArray or DatasetArray, the focus of the dataset array or the
744+
an XArray or DataArray, the focus of the dataset array or the
745745
singleton dimension of the xarray is used as the stacking dimension
746746
and the array is added to the returned dataset.
747747
indexers : None or iterable of indexers, optional

src/xray/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class GroupBy(object):
5050
See Also
5151
--------
5252
XArray.groupby
53-
DatasetArray.groupby
53+
DataArray.groupby
5454
"""
5555
def __init__(self, obj, group_name, group_coord, squeeze=True):
56-
"""See XArray.groupby and DatasetArray.groupby
56+
"""See XArray.groupby and DataArray.groupby
5757
"""
5858
if group_coord.ndim != 1:
5959
# TODO: remove this limitation?

src/xray/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def xarray_equal(v1, v2, rtol=1e-05, atol=1e-08, check_attributes=True):
255255
"""True if two objects have the same dimensions, attributes and data;
256256
otherwise False.
257257
258-
This function is necessary because `v1 == v2` for XArrays and DatasetArrays
258+
This function is necessary because `v1 == v2` for XArrays and DataArrays
259259
does element-wise comparisions (like numpy.ndarrays).
260260
"""
261261
def data_equiv(arr1, arr2):

src/xray/xarray.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def as_xarray(obj, strict=True):
1919
"""Convert an object into an XArray
2020
2121
- If the object is already an `XArray`, return it.
22-
- If the object is a `DatasetArray`, return it if `strict=False` or return
22+
- If the object is a `DataArray`, return it if `strict=False` or return
2323
its variable if `strict=True`.
2424
- Otherwise, if the object has 'dimensions' and 'data' attributes, convert
2525
it into a new `XArray`.
@@ -29,9 +29,9 @@ def as_xarray(obj, strict=True):
2929
# TODO: consider extending this method to automatically handle Iris and
3030
# pandas objects.
3131
if strict and hasattr(obj, 'variable'):
32-
# extract the focus XArray from DatasetArrays
32+
# extract the primary XArray from DataArrays
3333
obj = obj.variable
34-
if not isinstance(obj, (XArray, dataset_array.DatasetArray)):
34+
if not isinstance(obj, (XArray, dataset_array.DataArray)):
3535
if hasattr(obj, 'dimensions') and hasattr(obj, 'data'):
3636
obj = XArray(obj.dimensions, obj.data,
3737
getattr(obj, 'attributes', None),
@@ -64,7 +64,7 @@ class XArray(AbstractArray):
6464
"""A netcdf-like variable consisting of dimensions, data and attributes
6565
which describe a single Array. A single XArray object is not fully described
6666
outside the context of its parent Dataset (if you want such a fully
67-
described object, use a DatasetArray instead).
67+
described object, use a DataArray instead).
6868
"""
6969
def __init__(self, dims, data, attributes=None, encoding=None,
7070
indexing_mode='numpy'):
@@ -494,7 +494,7 @@ def concat(cls, variables, dimension='stacked_dimension',
494494
Arrays to stack together. Each variable is expected to have
495495
matching dimensions and shape except for along the stacked
496496
dimension.
497-
dimension : str or DatasetArray, optional
497+
dimension : str or DataArray, optional
498498
Name of the dimension to stack along. This can either be a new
499499
dimension name, in which case it is added along axis=0, or an
500500
existing dimension name, in which case the location of the
@@ -601,7 +601,7 @@ def func(self, *args, **kwargs):
601601
def _binary_op(f, reflexive=False):
602602
@functools.wraps(f)
603603
def func(self, other):
604-
if isinstance(other, dataset_array.DatasetArray):
604+
if isinstance(other, dataset_array.DataArray):
605605
return NotImplemented
606606
self_data, other_data, dims = _broadcast_xarray_data(self, other)
607607
new_data = (f(self_data, other_data)

test/test_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pandas as pd
1313
import netCDF4 as nc4
1414

15-
from xray import Dataset, DatasetArray, XArray, backends, open_dataset, utils
15+
from xray import Dataset, DataArray, XArray, backends, open_dataset, utils
1616

1717
from . import TestCase
1818

@@ -382,7 +382,7 @@ def test_merge(self):
382382

383383
def test_getitem(self):
384384
data = create_test_data()
385-
self.assertIsInstance(data['var1'], DatasetArray)
385+
self.assertIsInstance(data['var1'], DataArray)
386386
self.assertXArrayEqual(data['var1'], data.variables['var1'])
387387
self.assertIs(data['var1'].dataset, data)
388388

0 commit comments

Comments
 (0)