@@ -324,9 +324,15 @@ def _calc_concat_over(datasets, dim, dim_names, data_vars: T_DataVars, coords, c
324
324
"""
325
325
Determine which dataset variables need to be concatenated in the result,
326
326
"""
327
- # Return values
327
+ # variables to be concatenated
328
328
concat_over = set ()
329
+ # variables checked for equality
329
330
equals = {}
331
+ # skip merging these variables.
332
+ # if concatenating over a dimension 'x' that is associated with an indexo ver 2 variables,
333
+ # 'x' and 'y', then we assert join="equals" on `y` and don't need to merge it.
334
+ # that assertion happens in the align step prior to this function being called
335
+ skip_merge = set ()
330
336
331
337
if dim in dim_names :
332
338
concat_over_existing_dim = True
@@ -341,6 +347,9 @@ def _calc_concat_over(datasets, dim, dim_names, data_vars: T_DataVars, coords, c
341
347
if dim in ds :
342
348
ds = ds .set_coords (dim )
343
349
concat_over .update (k for k , v in ds .variables .items () if dim in v .dims )
350
+ for index , idx_coords in ds .xindexes .group_by_index ():
351
+ if dim in idx_coords :
352
+ skip_merge .update (idx_coords .keys ())
344
353
concat_dim_lengths .append (ds .sizes .get (dim , 1 ))
345
354
346
355
def process_subset_opt (opt , subset ):
@@ -438,7 +447,7 @@ def process_subset_opt(opt, subset):
438
447
439
448
process_subset_opt (data_vars , "data_vars" )
440
449
process_subset_opt (coords , "coords" )
441
- return concat_over , equals , concat_dim_lengths
450
+ return concat_over , equals , concat_dim_lengths , skip_merge
442
451
443
452
444
453
# determine dimensional coordinate names and a dict mapping name to DataArray
@@ -542,12 +551,12 @@ def _dataset_concat(
542
551
]
543
552
544
553
# determine which variables to concatenate
545
- concat_over , equals , concat_dim_lengths = _calc_concat_over (
554
+ concat_over , equals , concat_dim_lengths , skip_merge = _calc_concat_over (
546
555
datasets , dim_name , dim_names , data_vars , coords , compat
547
556
)
548
557
549
558
# determine which variables to merge, and then merge them according to compat
550
- variables_to_merge = (coord_names | data_names ) - concat_over
559
+ variables_to_merge = (coord_names | data_names ) - concat_over - skip_merge
551
560
552
561
result_vars = {}
553
562
result_indexes = {}
0 commit comments