3
3
from copy import deepcopy
4
4
from textwrap import dedent
5
5
6
- from xray import Dataset , DataArray , Index , Variable , align
6
+ from xray import Dataset , DataArray , Coordinate , Variable , align
7
7
from xray .pycompat import iteritems , OrderedDict
8
8
from . import TestCase , ReturnItem , source_ndarray
9
9
@@ -25,7 +25,7 @@ def test_repr(self):
25
25
<xray.DataArray 'my_variable' (time: 2, x: 3)>
26
26
array([[1, 2, 3],
27
27
[4, 5, 6]])
28
- Indexes :
28
+ Coordinates :
29
29
time: Int64Index([0, 1], dtype='int64')
30
30
x: Int64Index([0, 1, 2], dtype='int64')
31
31
Linked dataset variables:
@@ -44,9 +44,9 @@ def test_properties(self):
44
44
self .assertEqual (getattr (self .dv , attr ), getattr (self .v , attr ))
45
45
self .assertEqual (len (self .dv ), len (self .v ))
46
46
self .assertVariableEqual (self .dv , self .v )
47
- self .assertEqual (list (self .dv .indexes ), list (self .ds .indexes ))
48
- for k , v in iteritems (self .dv .indexes ):
49
- self .assertArrayEqual (v , self .ds .indexes [k ])
47
+ self .assertEqual (list (self .dv .coordinates ), list (self .ds .coordinates ))
48
+ for k , v in iteritems (self .dv .coordinates ):
49
+ self .assertArrayEqual (v , self .ds .coordinates [k ])
50
50
with self .assertRaises (AttributeError ):
51
51
self .dv .name = 'bar'
52
52
with self .assertRaises (AttributeError ):
@@ -85,25 +85,25 @@ def test_constructor(self):
85
85
'y' : ('y' , [- 1 , - 2 , - 3 ])})[None ]
86
86
self .assertDataArrayIdentical (expected , actual )
87
87
88
- indexes = [['a' , 'b' ], [- 1 , - 2 , - 3 ]]
89
- actual = DataArray (data , indexes , ['x' , 'y' ])
88
+ coordinates = [['a' , 'b' ], [- 1 , - 2 , - 3 ]]
89
+ actual = DataArray (data , coordinates , ['x' , 'y' ])
90
90
self .assertDataArrayIdentical (expected , actual )
91
91
92
- indexes = [pd .Index (['a' , 'b' ], name = 'A' ),
92
+ coordinates = [pd .Index (['a' , 'b' ], name = 'A' ),
93
93
pd .Index ([- 1 , - 2 , - 3 ], name = 'B' )]
94
- actual = DataArray (data , indexes , ['x' , 'y' ])
94
+ actual = DataArray (data , coordinates , ['x' , 'y' ])
95
95
self .assertDataArrayIdentical (expected , actual )
96
96
97
- indexes = {'x' : ['a' , 'b' ], 'y' : [- 1 , - 2 , - 3 ]}
98
- actual = DataArray (data , indexes , ['x' , 'y' ])
97
+ coordinates = {'x' : ['a' , 'b' ], 'y' : [- 1 , - 2 , - 3 ]}
98
+ actual = DataArray (data , coordinates , ['x' , 'y' ])
99
99
self .assertDataArrayIdentical (expected , actual )
100
100
101
- indexes = OrderedDict ([('x' , ['a' , 'b' ]), ('y' , [- 1 , - 2 , - 3 ])])
102
- actual = DataArray (data , indexes )
101
+ coordinates = OrderedDict ([('x' , ['a' , 'b' ]), ('y' , [- 1 , - 2 , - 3 ])])
102
+ actual = DataArray (data , coordinates )
103
103
self .assertDataArrayIdentical (expected , actual )
104
104
105
- indexes = pd .Series ([['a' , 'b' ], [- 1 , - 2 , - 3 ]], ['x' , 'y' ])
106
- actual = DataArray (data , indexes )
105
+ coordinates = pd .Series ([['a' , 'b' ], [- 1 , - 2 , - 3 ]], ['x' , 'y' ])
106
+ actual = DataArray (data , coordinates )
107
107
self .assertDataArrayIdentical (expected , actual )
108
108
109
109
expected = Dataset ({None : (['x' , 'y' ], data ),
@@ -146,7 +146,7 @@ def test_constructor(self):
146
146
def test_constructor_from_self_described (self ):
147
147
data = [[- 0.1 , 21 ], [0 , 2 ]]
148
148
expected = DataArray (data ,
149
- indexes = {'x' : ['a' , 'b' ], 'y' : [- 1 , - 2 ]},
149
+ coordinates = {'x' : ['a' , 'b' ], 'y' : [- 1 , - 2 ]},
150
150
dimensions = ['x' , 'y' ], name = 'foobar' ,
151
151
attributes = {'bar' : 2 }, encoding = {'foo' : 3 })
152
152
actual = DataArray (expected )
@@ -163,7 +163,7 @@ def test_constructor_from_self_described(self):
163
163
164
164
panel = pd .Panel ({0 : frame })
165
165
actual = DataArray (panel )
166
- expected = DataArray ([data ], expected .indexes , ['dim_0' , 'x' , 'y' ])
166
+ expected = DataArray ([data ], expected .coordinates , ['dim_0' , 'x' , 'y' ])
167
167
self .assertDataArrayIdentical (expected , actual )
168
168
169
169
expected = DataArray (['a' , 'b' ], name = 'foo' )
@@ -249,30 +249,30 @@ def test_loc(self):
249
249
da .loc ['a' :'j' ] = 0
250
250
self .assertTrue (np .all (da .values == 0 ))
251
251
252
- def test_indexes (self ):
253
- indexes = [Index ('x' , [- 1 , - 2 ]), Index ('y' , [0 , 1 , 2 ])]
254
- da = DataArray (np .random .randn (2 , 3 ), indexes , name = 'foo' )
252
+ def test_coordinates (self ):
253
+ coordinates = [Coordinate ('x' , [- 1 , - 2 ]), Coordinate ('y' , [0 , 1 , 2 ])]
254
+ da = DataArray (np .random .randn (2 , 3 ), coordinates , name = 'foo' )
255
255
256
- self .assertEquals (2 , len (da .indexes ))
256
+ self .assertEquals (2 , len (da .coordinates ))
257
257
258
- self .assertEquals (['x' , 'y' ], list (da .indexes ))
258
+ self .assertEquals (['x' , 'y' ], list (da .coordinates ))
259
259
260
- self .assertTrue (da .indexes [0 ].identical (indexes [0 ]))
261
- self .assertTrue (da .indexes ['x' ].identical (indexes [0 ]))
262
- self .assertTrue (da .indexes [1 ].identical (indexes [1 ]))
263
- self .assertTrue (da .indexes ['y' ].identical (indexes [1 ]))
260
+ self .assertTrue (da .coordinates [0 ].identical (coordinates [0 ]))
261
+ self .assertTrue (da .coordinates ['x' ].identical (coordinates [0 ]))
262
+ self .assertTrue (da .coordinates [1 ].identical (coordinates [1 ]))
263
+ self .assertTrue (da .coordinates ['y' ].identical (coordinates [1 ]))
264
264
265
- self .assertIn ('x' , da .indexes )
266
- self .assertNotIn (0 , da .indexes )
267
- self .assertNotIn ('foo' , da .indexes )
265
+ self .assertIn ('x' , da .coordinates )
266
+ self .assertNotIn (0 , da .coordinates )
267
+ self .assertNotIn ('foo' , da .coordinates )
268
268
269
269
with self .assertRaises (KeyError ):
270
- da .indexes ['foo' ]
270
+ da .coordinates ['foo' ]
271
271
272
272
expected = dedent ("""\
273
273
x: Int64Index([-1, -2], dtype='int64')
274
274
y: Int64Index([0, 1, 2], dtype='int64')""" )
275
- actual = repr (da .indexes )
275
+ actual = repr (da .coordinates )
276
276
self .assertEquals (expected , actual )
277
277
278
278
def test_reindex (self ):
@@ -474,12 +474,12 @@ def make_groupby_example_array(self):
474
474
def test_groupby_properties (self ):
475
475
grouped = self .make_groupby_example_array ().groupby ('abc' )
476
476
expected_unique = Variable ('abc' , ['a' , 'b' , 'c' ])
477
- self .assertVariableEqual (expected_unique , grouped .unique_index )
477
+ self .assertVariableEqual (expected_unique , grouped .unique_coord )
478
478
self .assertEqual (3 , len (grouped ))
479
479
480
480
def test_groupby_apply_identity (self ):
481
481
expected = self .make_groupby_example_array ()
482
- idx = expected .indexes ['y' ]
482
+ idx = expected .coordinates ['y' ]
483
483
identity = lambda x : x
484
484
for g in ['x' , 'y' , 'abc' , idx ]:
485
485
for shortcut in [False , True ]:
0 commit comments