Skip to content

Commit

Permalink
fixes pydata#1027
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Oct 15, 2016
1 parent 9cf107b commit 4ef6c0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xarray/core/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def differs(vname):
concat_over.update(process_subset_opt(coords, 'coords'))
if dim in datasets[0]:
concat_over.add(dim)

return concat_over
# return a list to keep the variables order
return [vn for vn in datasets[0].variables if vn in concat_over]


def _dataset_concat(datasets, dim, data_vars, coords, compat, positions):
Expand Down
15 changes: 15 additions & 0 deletions xarray/test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,21 @@ def test_groupby_nan(self):
expected = Dataset({'foo': ('bar', [1.5, 3]), 'bar': [1, 2]})
self.assertDatasetIdentical(actual, expected)

def test_groupby_order(self):
# groupby should preserve variables order

ds = Dataset()
for vn in ['a', 'b', 'c']:
ds[vn] = DataArray(np.arange(10), dims=['t'])
all_vars_ref = list(ds.variables.keys())
data_vars_ref = list(ds.data_vars.keys())
ds = ds.groupby('t').mean()
all_vars = list(ds.variables.keys())
data_vars = list(ds.data_vars.keys())
self.assertEqual(data_vars, data_vars_ref)
# coords are now at the end of the list, so the test below fails
# self.assertEqual(all_vars, all_vars_ref)

def test_resample_and_first(self):
times = pd.date_range('2000-01-01', freq='6H', periods=10)
ds = Dataset({'foo': (['time', 'x', 'y'], np.random.randn(10, 5, 3)),
Expand Down

0 comments on commit 4ef6c0e

Please sign in to comment.