Skip to content

Commit 53bd749

Browse files
author
Benoit Bovy
committed
change signature of Coordinate.__init__
1 parent fb97a67 commit 53bd749

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

xarray/core/variable.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -1072,20 +1072,18 @@ class Coordinate(Variable):
10721072
10731073
The most important difference is that Coordinate objects must always have a
10741074
name, which is the dimension along which they index values unless another
1075-
dimension name is specified.
1075+
name is specified.
10761076
10771077
Coordinates must always be 1-dimensional. In addition to Variable methods
10781078
and properties (attributes, encoding, broadcasting), they support some
10791079
pandas.Index methods directly (e.g., get_indexer), even though pandas does
10801080
not (yet) support duck-typing for indexes.
10811081
"""
10821082

1083-
def __init__(self, name, data, attrs=None, encoding=None,
1084-
fastpath=False, dim=None):
1085-
if dim is None:
1086-
dim = name
1083+
def __init__(self, dims, data, attrs=None, encoding=None,
1084+
name=None, fastpath=False):
10871085

1088-
super(Coordinate, self).__init__(dim, data, attrs, encoding, fastpath)
1086+
super(Coordinate, self).__init__(dims, data, attrs, encoding, fastpath)
10891087
if self.ndim != 1:
10901088
raise ValueError('%s objects must be 1-dimensional' %
10911089
type(self).__name__)
@@ -1106,8 +1104,8 @@ def __getitem__(self, key):
11061104
if not hasattr(values, 'ndim') or values.ndim == 0:
11071105
return Variable((), values, self._attrs, self._encoding)
11081106
else:
1109-
return type(self)(self._name, values, self._attrs,
1110-
self._encoding, fastpath=True, dim=self.dims)
1107+
return type(self)(self.dims, values, self._attrs,
1108+
self._encoding, name=self._name, fastpath=True)
11111109

11121110
def __setitem__(self, key, value):
11131111
raise TypeError('%s values cannot be modified' % type(self).__name__)
@@ -1159,8 +1157,8 @@ def copy(self, deep=True):
11591157
# there is no need to copy the index values here even if deep=True
11601158
# since pandas.Index objects are immutable
11611159
data = PandasIndexAdapter(self) if deep else self._data
1162-
return type(self)(self._name, data, self._attrs,
1163-
self._encoding, fastpath=True, dim=self.dims)
1160+
return type(self)(self.dims, data, self._attrs,
1161+
self._encoding, name=self._name, fastpath=True)
11641162

11651163
def _data_equals(self, other):
11661164
return self.to_index().equals(other.to_index())
@@ -1205,7 +1203,7 @@ def get_level_coord(self, level):
12051203
if self.level_names is None:
12061204
raise ValueError("Coordinate %s has no MultiIndex" % self.name)
12071205
index = self.to_index()
1208-
return type(self)(level, index.get_level_values(level), dim=self.name)
1206+
return type(self)(self.dims, index.get_level_values(level), name=level)
12091207

12101208
@property
12111209
def name(self):

0 commit comments

Comments
 (0)