From 21afbb1ee88d44e0193f0ec384dac0c3d3b90f05 Mon Sep 17 00:00:00 2001 From: TomNicholas Date: Thu, 28 Mar 2024 16:06:23 -0400 Subject: [PATCH] fix failing test --- xarray/core/concat.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/xarray/core/concat.py b/xarray/core/concat.py index 468c0595b0a..5ef3c01d427 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -652,14 +652,26 @@ def get_indexes(name): raise ValueError( f"Variables {absent_coord_names!r} are coordinates in some datasets but not others." ) + coord_vars = { name: result_var for name, result_var in result_vars.items() if name in coord_names } + + if index is not None: + if dim_var is not None: + index_vars = index.create_variables({dim: dim_var}) + else: + index_vars = index.create_variables() + + coord_vars[dim] = index_vars[dim] + result_indexes[dim] = index + unlabeled_dims = unlabeled_dims - set([dim]) + + # TODO: add indexes at Dataset creation (when it is supported) coords = Coordinates(coord_vars, indexes=result_indexes) - # TODO: this is just the complement of the set of coord_vars result_data_vars = { name: result_var for name, result_var in result_vars.items() @@ -671,14 +683,6 @@ def get_indexes(name): result = result.drop_vars(unlabeled_dims, errors="ignore") - if index is not None: - # add concat index / coordinate last to ensure that its in the final Dataset - if dim_var is not None: - index_vars = index.create_variables({dim: dim_var}) - else: - index_vars = index.create_variables() - result[dim] = index_vars[dim] - return result