Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for #2662 #2678

Merged
merged 4 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions xarray/core/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,21 @@ def _auto_combine_all_along_first_dim(combined_ids, dim, data_vars,
return new_combined_ids


def vars_as_keys(ds):
return tuple(sorted(ds))


def _auto_combine_1d(datasets, concat_dim=_CONCAT_DIM_DEFAULT,
compat='no_conflicts',
data_vars='all', coords='different'):
# This is just the old auto_combine function (which only worked along 1D)
if concat_dim is not None:
dim = None if concat_dim is _CONCAT_DIM_DEFAULT else concat_dim
grouped = itertools.groupby(datasets, key=lambda ds: tuple(sorted(ds)))
sorted_datasets = sorted(datasets, key=vars_as_keys)
grouped_by_vars = itertools.groupby(sorted_datasets, key=vars_as_keys)
concatenated = [_auto_concat(list(ds_group), dim=dim,
data_vars=data_vars, coords=coords)
for id, ds_group in grouped]
for id, ds_group in grouped_by_vars]
else:
concatenated = datasets
merged = merge(concatenated, compat=compat)
Expand Down
15 changes: 13 additions & 2 deletions xarray/tests/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def test_merge_one_dim_concat_another(self):
expected = Dataset({'foo': ('x', [0, 1, 2, 3]),
'bar': ('x', [10, 20, 30, 40])})

actual = auto_combine(objs, concat_dim=['x', None])
actual = auto_combine(objs, concat_dim=['x', None], compat='equals')
assert_identical(expected, actual)

actual = auto_combine(objs)
Expand All @@ -661,7 +661,18 @@ def test_merge_one_dim_concat_another(self):
Dataset({'foo': ('x', [2, 3])})],
[Dataset({'bar': ('x', [10, 20])}),
Dataset({'bar': ('x', [30, 40])})]]
actual = auto_combine(objs, concat_dim=[None, 'x'])
actual = auto_combine(objs, concat_dim=[None, 'x'], compat='equals')
assert_identical(expected, actual)

def test_internal_odering(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test fail with the old logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it gives a MergeError.

Though maybe I need to dig more, because I thought it would pass with compat='no_conflicts', and fail with compat='equals'...

# See GH #2662
objs = [Dataset({'foo': ('x', [0, 1])}),
Dataset({'bar': ('x', [10, 20])}),
Dataset({'foo': ('x', [2, 3])}),
Dataset({'bar': ('x', [30, 40])})]
actual = auto_combine(objs, concat_dim='x', compat='equals')
expected = Dataset({'foo': ('x', [0, 1, 2, 3]),
'bar': ('x', [10, 20, 30, 40])})
assert_identical(expected, actual)

def test_combine_concat_over_redundant_nesting(self):
Expand Down