Skip to content

Commit df30b55

Browse files
committed
Consistent names: always use 'attrs' rather than 'attributes'
Related: pydata#190
1 parent db292af commit df30b55

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

test/test_data_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_constructor(self):
160160
expected = Dataset({'foo': (['dim_0', 'dim_1'], data)})['foo']
161161
self.assertDataArrayIdentical(expected, actual)
162162

163-
actual = DataArray(data, dimensions=['x', 'y'], attributes={'bar': 2})
163+
actual = DataArray(data, dimensions=['x', 'y'], attrs={'bar': 2})
164164
expected = Dataset({None: (['x', 'y'], data, {'bar': 2})})[None]
165165
self.assertDataArrayIdentical(expected, actual)
166166

@@ -173,7 +173,7 @@ def test_constructor_from_self_described(self):
173173
expected = DataArray(data,
174174
coordinates={'x': ['a', 'b'], 'y': [-1, -2]},
175175
dimensions=['x', 'y'], name='foobar',
176-
attributes={'bar': 2}, encoding={'foo': 3})
176+
attrs={'bar': 2}, encoding={'foo': 3})
177177
actual = DataArray(expected)
178178
self.assertDataArrayIdentical(expected, actual)
179179

test/test_variable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ def test_equals_and_identical(self):
339339
d = np.random.rand(10, 3)
340340
d[0, 0] = np.nan
341341
v1 = Variable(('dim1', 'dim2'), data=d,
342-
attributes={'att1': 3, 'att2': [1, 2, 3]})
342+
attrs={'att1': 3, 'att2': [1, 2, 3]})
343343
v2 = Variable(('dim1', 'dim2'), data=d,
344-
attributes={'att1': 3, 'att2': [1, 2, 3]})
344+
attrs={'att1': 3, 'att2': [1, 2, 3]})
345345
self.assertTrue(v1.equals(v2))
346346
self.assertTrue(v1.identical(v2))
347347

xray/data_array.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class DataArray(AbstractArray):
153153
Dictionary of Coordinate objects that label values along each dimension.
154154
"""
155155
def __init__(self, data=None, coordinates=None, dimensions=None, name=None,
156-
attributes=None, encoding=None):
156+
attrs=None, encoding=None):
157157
"""
158158
Parameters
159159
----------
@@ -175,7 +175,7 @@ def __init__(self, data=None, coordinates=None, dimensions=None, name=None,
175175
``['dim_0', ... 'dim_n']``.
176176
name : str or None, optional
177177
Name of this array.
178-
attributes : dict_like or None, optional
178+
attrs : dict_like or None, optional
179179
Attributes to assign to the new variable. By default, an empty
180180
attribute dictionary is initialized.
181181
encoding : dict_like or None, optional
@@ -200,8 +200,8 @@ def __init__(self, data=None, coordinates=None, dimensions=None, name=None,
200200
dimensions = getattr(data, 'dimensions', None)
201201
if name is None:
202202
name = getattr(data, 'name', None)
203-
if attributes is None:
204-
attributes = getattr(data, 'attrs', None)
203+
if attrs is None:
204+
attrs = getattr(data, 'attrs', None)
205205
if encoding is None:
206206
encoding = getattr(data, 'encoding', None)
207207

@@ -210,7 +210,7 @@ def __init__(self, data=None, coordinates=None, dimensions=None, name=None,
210210
data.shape, coordinates, dimensions)
211211
variables = OrderedDict((var.name, var) for var in coordinates)
212212
variables[name] = variable.Variable(
213-
dimensions, data, attributes, encoding)
213+
dimensions, data, attrs, encoding)
214214
dataset = xray.Dataset(variables)
215215

216216
self._dataset = dataset

xray/dataset.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,29 +289,29 @@ class Dataset(Mapping, common.ImplementsDatasetReduce):
289289
coordinates, which means they are saved in the dataset as `xray.Coordinate`
290290
objects.
291291
"""
292-
def __init__(self, variables=None, attributes=None):
292+
def __init__(self, variables=None, attrs=None):
293293
"""To load data from a file or file-like object, use the `open_dataset`
294294
function.
295295
296296
Parameters
297297
----------
298298
variables : dict-like, optional
299299
A mapping from variable names to `DataArray` objets, `Variable`
300-
objects or sequences of the form `(dimensions, data[, attributes])`
300+
objects or sequences of the form `(dimensions, data[, attrs])`
301301
which can be used as arguments to create a new `Variable`. Each
302302
dimension must have the same length in all variables in which it
303303
appears.
304-
attributes : dict-like, optional
304+
attrs : dict-like, optional
305305
Global attributes to save on this dataset.
306306
"""
307307
self._variables = VariablesDict()
308308
self._dimensions = SortedKeysDict()
309-
self._attributes = OrderedDict()
309+
self._attrs = OrderedDict()
310310
self._file_obj = None
311311
if variables is not None:
312312
self._set_init_vars_and_dims(variables)
313-
if attributes is not None:
314-
self._attributes.update(attributes)
313+
if attrs is not None:
314+
self._attrs.update(attrs)
315315

316316
def _add_missing_coordinates(self):
317317
"""Add missing coordinate variables IN-PLACE to the variables dict
@@ -403,22 +403,22 @@ def variables(self):
403403
@property
404404
def attributes(self):
405405
utils.alias_warning('attributes', 'attrs', 3)
406-
return self._attributes
406+
return self._attrs
407407

408408
@attributes.setter
409409
def attributes(self, value):
410410
utils.alias_warning('attributes', 'attrs', 3)
411-
self._attributes = OrderedDict(value)
411+
self._attrs = OrderedDict(value)
412412

413413
@property
414414
def attrs(self):
415415
"""Dictionary of global attributes on this dataset
416416
"""
417-
return self._attributes
417+
return self._attrs
418418

419419
@attrs.setter
420420
def attrs(self, value):
421-
self._attributes = OrderedDict(value)
421+
self._attrs = OrderedDict(value)
422422

423423
@property
424424
def dimensions(self):
@@ -458,7 +458,7 @@ def copy(self, deep=False):
458458
obj = self.__new__(type(self))
459459
obj._variables = variables
460460
obj._dimensions = self._dimensions.copy()
461-
obj._attributes = self._attributes.copy()
461+
obj._attrs = self._attrs.copy()
462462
obj._file_obj = None
463463
return obj
464464

@@ -516,7 +516,7 @@ def __setitem__(self, key, value):
516516
dataset.
517517
518518
If value is an `Variable` object (or tuple of form
519-
`(dimensions, data[, attributes])`), add it to this dataset as a new
519+
`(dimensions, data[, attrs])`), add it to this dataset as a new
520520
variable.
521521
"""
522522
self.merge({key: value}, inplace=True, overwrite_vars=[key])
@@ -1150,7 +1150,7 @@ def reduce(self, func, dimension=None, keep_attrs=False, **kwargs):
11501150

11511151
attrs = self.attrs if keep_attrs else {}
11521152

1153-
return Dataset(variables=variables, attributes=attrs)
1153+
return Dataset(variables, attrs)
11541154

11551155
def apply(self, func, to=None, keep_attrs=False, **kwargs):
11561156
"""Apply a function over noncoordinates in this dataset.

xray/variable.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ class Variable(AbstractArray):
191191
described outside the context of its parent Dataset (if you want such a
192192
fully described object, use a DataArray instead).
193193
"""
194-
def __init__(self, dims, data, attributes=None, encoding=None):
194+
def __init__(self, dimensions, data, attrs=None, encoding=None):
195195
"""
196196
Parameters
197197
----------
198-
dims : str or sequence of str
198+
dimensions : str or sequence of str
199199
Name(s) of the the data dimension(s). Must be either a string (only
200200
for 1D data) or a sequence of strings with length equal to the
201201
number of dimensions.
202202
data : array_like
203203
Data array which supports numpy-like data access.
204-
attributes : dict_like or None, optional
204+
attrs : dict_like or None, optional
205205
Attributes to assign to the new variable. If None (default), an
206206
empty attribute dictionary is initialized.
207207
encoding : dict_like or None, optional
@@ -212,10 +212,10 @@ def __init__(self, dims, data, attributes=None, encoding=None):
212212
unrecognized encoding items.
213213
"""
214214
self._data = _as_compatible_data(data)
215-
self._dimensions = self._parse_dimensions(dims)
216-
if attributes is None:
217-
attributes = {}
218-
self._attributes = OrderedDict(attributes)
215+
self._dimensions = self._parse_dimensions(dimensions)
216+
if attrs is None:
217+
attrs = {}
218+
self._attrs = OrderedDict(attrs)
219219
self._encoding = dict({} if encoding is None else encoding)
220220

221221
@property
@@ -361,11 +361,11 @@ def attributes(self, value):
361361
def attrs(self):
362362
"""Dictionary of local attributes on this variable.
363363
"""
364-
return self._attributes
364+
return self._attrs
365365

366366
@attrs.setter
367367
def attrs(self, value):
368-
self._attributes = OrderedDict(value)
368+
self._attrs = OrderedDict(value)
369369

370370
@property
371371
def encoding(self):
@@ -533,7 +533,7 @@ def reduce(self, func, dimension=None, axis=None, keep_attrs=False,
533533

534534
attrs = self.attrs if keep_attrs else {}
535535

536-
return Variable(dims, data, attributes=attrs)
536+
return Variable(dims, data, attrs=attrs)
537537

538538
@classmethod
539539
def concat(cls, variables, dimension='stacked_dimension',
@@ -717,13 +717,13 @@ class Coordinate(Variable):
717717
"""
718718
_cache_data_class = PandasIndexAdapter
719719

720-
def __init__(self, name, data, attributes=None, encoding=None):
720+
def __init__(self, name, data, attrs=None, encoding=None):
721721
if isinstance(data, pd.MultiIndex):
722722
raise NotImplementedError(
723723
'no support yet for using a pandas.MultiIndex in an '
724724
'xray.Coordinate')
725725

726-
super(Coordinate, self).__init__(name, data, attributes, encoding)
726+
super(Coordinate, self).__init__(name, data, attrs, encoding)
727727
if self.ndim != 1:
728728
raise ValueError('%s objects must be 1-dimensional' %
729729
type(self).__name__)

0 commit comments

Comments
 (0)