@@ -248,7 +248,8 @@ def test_concat(self):
248
248
249
249
# from dataset array:
250
250
expected = DataArray (np .array ([foo .values , bar .values ]),
251
- dims = ['w' , 'x' , 'y' ], coords = {'x' : [0 , 1 ]})
251
+ dims = ['w' , 'x' , 'y' ],
252
+ coords = {'x' : [0 , 1 ], 'w' : ['foo' , 'bar' ]})
252
253
actual = concat ([foo , bar ], 'w' )
253
254
assert_equal (expected , actual )
254
255
# from iteration:
@@ -297,15 +298,24 @@ def test_concat_lazy(self):
297
298
assert combined .shape == (2 , 3 , 3 )
298
299
assert combined .dims == ('z' , 'x' , 'y' )
299
300
300
- def test_concat_names (self ):
301
+ def test_concat_names_and_coords (self ):
301
302
ds = Dataset ({'foo' : (['x' , 'y' ], np .random .random ((2 , 2 ))),
302
303
'bar' : (['x' , 'y' ], np .random .random ((2 , 2 )))})
303
304
# Concat arrays with different names, new name is None
305
+ # and unique array names are used as coordinates
304
306
new = concat ([ds .foo , ds .bar ], dim = 'new' )
305
307
assert new .name is None
308
+ assert (new .coords ['new' ] == ['foo' , 'bar' ]).values .all ()
309
+ # Get a useful error message for unexpectedly different names
310
+ with pytest .raises (ValueError ) as err :
311
+ concat ([ds .foo , ds .bar ], dim = 'new' , compat = 'identical' )
312
+ assert err .value .args [0 ] == "compat='identical', " + \
313
+ "but array names ['foo', 'bar'] are not identical"
306
314
# Concat arrays with same name, name is preserved
315
+ # and non-unique names are not used as coords
307
316
foobar = ds .foo .rename ('bar' )
308
317
assert concat ([foobar , ds .bar ], dim = 'new' ).name == 'bar'
318
+ assert 'new' not in concat ([foobar , ds .bar ], dim = 'new' ).coords
309
319
310
320
311
321
class TestAutoCombine (object ):
0 commit comments