@@ -31,19 +31,21 @@ def rectify_dim_order(dataset):
31
31
for dim in ['dim1' , 'dim2' ]:
32
32
datasets = [g for _ , g in data .groupby (dim , squeeze = False )]
33
33
self .assertDatasetIdentical (data , concat (datasets , dim ))
34
- self .assertDatasetIdentical (
35
- data , concat (datasets , data [dim ]))
36
- self .assertDatasetIdentical (
37
- data , concat (datasets , data [dim ], coords = 'minimal' ))
38
34
39
- datasets = [ g for _ , g in data . groupby ( dim , squeeze = True )]
40
- concat_over = [ k for k , v in iteritems ( data . coords )
41
- if dim in v . dims and k != dim ]
42
- actual = concat ( datasets , data [ dim ], coords = concat_over )
43
- self . assertDatasetIdentical ( data , rectify_dim_order ( actual ))
35
+ dim = 'dim2'
36
+ self . assertDatasetIdentical (
37
+ data , concat ( datasets , data [ dim ]))
38
+ self . assertDatasetIdentical (
39
+ data , concat ( datasets , data [ dim ], coords = 'minimal' ))
44
40
45
- actual = concat (datasets , data [dim ], coords = 'different' )
46
- self .assertDatasetIdentical (data , rectify_dim_order (actual ))
41
+ datasets = [g for _ , g in data .groupby (dim , squeeze = True )]
42
+ concat_over = [k for k , v in iteritems (data .coords )
43
+ if dim in v .dims and k != dim ]
44
+ actual = concat (datasets , data [dim ], coords = concat_over )
45
+ self .assertDatasetIdentical (data , rectify_dim_order (actual ))
46
+
47
+ actual = concat (datasets , data [dim ], coords = 'different' )
48
+ self .assertDatasetIdentical (data , rectify_dim_order (actual ))
47
49
48
50
# make sure the coords argument behaves as expected
49
51
data .coords ['extra' ] = ('dim4' , np .arange (3 ))
@@ -111,7 +113,8 @@ def test_concat_autoalign(self):
111
113
ds2 = Dataset ({'foo' : DataArray ([1 , 2 ], coords = [('x' , [1 , 3 ])])})
112
114
actual = concat ([ds1 , ds2 ], 'y' )
113
115
expected = Dataset ({'foo' : DataArray ([[1 , 2 , np .nan ], [1 , np .nan , 2 ]],
114
- dims = ['y' , 'x' ], coords = {'y' : [0 , 1 ], 'x' : [1 , 2 , 3 ]})})
116
+ dims = ['y' , 'x' ],
117
+ coords = {'x' : [1 , 2 , 3 ]})})
115
118
self .assertDatasetIdentical (expected , actual )
116
119
117
120
def test_concat_errors (self ):
@@ -184,7 +187,7 @@ def test_concat_promote_shape(self):
184
187
objs = [Dataset ({'x' : [0 ]}, {'y' : - 1 }),
185
188
Dataset ({'x' : [1 , 2 ]}, {'y' : - 2 })]
186
189
actual = concat (objs , 'x' )
187
- expected = Dataset ({}, {'y' : ('x' , [- 1 , - 2 , - 2 ])})
190
+ expected = Dataset ({'x' : [ 0 , 1 , 2 ] }, {'y' : ('x' , [- 1 , - 2 , - 2 ])})
188
191
self .assertDatasetIdentical (actual , expected )
189
192
190
193
# broadcast 1d x 1d -> 2d
@@ -196,8 +199,8 @@ def test_concat_promote_shape(self):
196
199
197
200
def test_concat_do_not_promote (self ):
198
201
# GH438
199
- objs = [Dataset ({'y' : ('t' , [1 ])}, {'x' : 1 }),
200
- Dataset ({'y' : ('t' , [2 ])}, {'x' : 1 })]
202
+ objs = [Dataset ({'y' : ('t' , [1 ])}, {'x' : 1 , 't' : 0 }),
203
+ Dataset ({'y' : ('t' , [2 ])}, {'x' : 1 , 't' : 0 })]
201
204
expected = Dataset ({'y' : ('t' , [1 , 2 ])}, {'x' : 1 , 't' : [0 , 0 ]})
202
205
actual = concat (objs , 't' )
203
206
self .assertDatasetIdentical (expected , actual )
@@ -291,8 +294,7 @@ def test_auto_combine(self):
291
294
objs = [Dataset (OrderedDict ([('x' , ('a' , [0 ])), ('y' , ('a' , [0 ]))])),
292
295
Dataset (OrderedDict ([('y' , ('a' , [1 ])), ('x' , ('a' , [1 ]))]))]
293
296
actual = auto_combine (objs )
294
- expected = Dataset (
295
- {'x' : ('a' , [0 , 1 ]), 'y' : ('a' , [0 , 1 ]), 'a' : [0 , 0 ]})
297
+ expected = Dataset ({'x' : ('a' , [0 , 1 ]), 'y' : ('a' , [0 , 1 ])})
296
298
self .assertDatasetIdentical (expected , actual )
297
299
298
300
objs = [Dataset ({'x' : [0 ], 'y' : [0 ]}), Dataset ({'y' : [1 ], 'x' : [1 ]})]
@@ -323,7 +325,8 @@ def test_auto_combine_previously_failed(self):
323
325
datasets = [Dataset ({'a' : ('x' , [2 , 3 ]), 'x' : [1 , 2 ]}),
324
326
Dataset ({'a' : ('x' , [1 , 2 ]), 'x' : [0 , 1 ]})]
325
327
expected = Dataset ({'a' : (('t' , 'x' ),
326
- [[np .nan , 2 , 3 ], [1 , 2 , np .nan ]])})
328
+ [[np .nan , 2 , 3 ], [1 , 2 , np .nan ]])},
329
+ {'x' : [0 , 1 , 2 ]})
327
330
actual = auto_combine (datasets , concat_dim = 't' )
328
331
self .assertDatasetIdentical (expected , actual )
329
332
0 commit comments