@@ -536,7 +536,7 @@ def _dataset_concat(
536
536
537
537
# we've already verified everything is consistent; now, calculate
538
538
# shared dimension sizes so we can expand the necessary variables
539
- def ensure_common_dims (vars ):
539
+ def ensure_common_dims (vars , concat_dim_lengths ):
540
540
# ensure each variable with the given name shares the same
541
541
# dimensions and the same shape for all of them except along the
542
542
# concat dimension
@@ -573,23 +573,24 @@ def get_indexes(name):
573
573
if name in concat_over and name not in result_indexes :
574
574
variables = []
575
575
variable_index = []
576
+ var_concat_dim_length = []
576
577
for i , ds in enumerate (datasets ):
577
578
if name in ds .variables :
578
579
variables .append (ds [name ].variable )
579
580
# add to variable index, needed for reindexing
580
- variable_index . extend (
581
- [
582
- sum (concat_dim_lengths [: i ]) + k
583
- for k in range ( concat_dim_lengths [ i ])
584
- ]
585
- )
581
+ var_idx = [
582
+ sum ( concat_dim_lengths [: i ]) + k
583
+ for k in range (concat_dim_lengths [i ])
584
+ ]
585
+ variable_index . extend ( var_idx )
586
+ var_concat_dim_length . append ( len ( var_idx ) )
586
587
else :
587
588
# raise if coordinate not in all datasets
588
589
if name in coord_names :
589
590
raise ValueError (
590
591
f"coordinate { name !r} not present in all datasets."
591
592
)
592
- vars = ensure_common_dims (variables )
593
+ vars = ensure_common_dims (variables , var_concat_dim_length )
593
594
594
595
# Try to concatenate the indexes, concatenate the variables when no index
595
596
# is found on all datasets.
0 commit comments