Skip to content

Commit

Permalink
split vars into data_vars and coord_vars in one loop
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Apr 26, 2024
1 parent 51eea5d commit bde9f2b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions xarray/core/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,13 @@ def get_indexes(name):
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
}
result_data_vars = {}
coord_vars = {}
for name, result_var in result_vars.items():
if name in coord_names:
coord_vars[name] = result_var
else:
result_data_vars[name] = result_var

if index is not None:
if dim_var is not None:
Expand All @@ -680,12 +682,6 @@ def get_indexes(name):
# TODO: add indexes at Dataset creation (when it is supported)
coords = Coordinates(coord_vars, indexes=result_indexes)

result_data_vars = {
name: result_var
for name, result_var in result_vars.items()
if name not in coord_names
}

result = type(datasets[0])(result_data_vars, coords=coords, attrs=result_attrs)
result.encoding = result_encoding

Expand Down

0 comments on commit bde9f2b

Please sign in to comment.