@@ -46,7 +46,7 @@ def concat(
46
46
objs : Iterable [T_Dataset ],
47
47
dim : Hashable | T_Variable | T_DataArray | pd .Index | Any ,
48
48
data_vars : T_DataVars | CombineKwargDefault = _DATA_VARS_DEFAULT ,
49
- coords : ConcatOptions | list [Hashable ] | CombineKwargDefault = _COORDS_DEFAULT ,
49
+ coords : ConcatOptions | Iterable [Hashable ] | CombineKwargDefault = _COORDS_DEFAULT ,
50
50
compat : CompatOptions | CombineKwargDefault = _COMPAT_CONCAT_DEFAULT ,
51
51
positions : Iterable [Iterable [int ]] | None = None ,
52
52
fill_value : object = dtypes .NA ,
@@ -61,7 +61,7 @@ def concat(
61
61
objs : Iterable [T_DataArray ],
62
62
dim : Hashable | T_Variable | T_DataArray | pd .Index | Any ,
63
63
data_vars : T_DataVars | CombineKwargDefault = _DATA_VARS_DEFAULT ,
64
- coords : ConcatOptions | list [Hashable ] | CombineKwargDefault = _COORDS_DEFAULT ,
64
+ coords : ConcatOptions | Iterable [Hashable ] | CombineKwargDefault = _COORDS_DEFAULT ,
65
65
compat : CompatOptions | CombineKwargDefault = _COMPAT_CONCAT_DEFAULT ,
66
66
positions : Iterable [Iterable [int ]] | None = None ,
67
67
fill_value : object = dtypes .NA ,
@@ -75,7 +75,7 @@ def concat(
75
75
objs ,
76
76
dim ,
77
77
data_vars : T_DataVars | CombineKwargDefault = _DATA_VARS_DEFAULT ,
78
- coords : ConcatOptions | list [Hashable ] | CombineKwargDefault = _COORDS_DEFAULT ,
78
+ coords : ConcatOptions | Iterable [Hashable ] | CombineKwargDefault = _COORDS_DEFAULT ,
79
79
compat : CompatOptions | CombineKwargDefault = _COMPAT_CONCAT_DEFAULT ,
80
80
positions = None ,
81
81
fill_value = dtypes .NA ,
@@ -339,25 +339,25 @@ def _calc_concat_dim_index(
339
339
340
340
341
341
def _calc_concat_over (
342
- datasets ,
343
- dim ,
344
- all_dims ,
342
+ datasets : list [ T_Dataset ] ,
343
+ dim : Hashable ,
344
+ all_dims : set [ Hashable ] ,
345
345
data_vars : T_DataVars | CombineKwargDefault ,
346
- coords ,
347
- compat ,
348
- ):
346
+ coords : ConcatOptions | Iterable [ Hashable ] | CombineKwargDefault ,
347
+ compat : CompatOptions | CombineKwargDefault ,
348
+ ) -> tuple [ set [ Hashable ], dict [ Hashable , bool ], list [ int ], set [ Hashable ]] :
349
349
"""
350
350
Determine which dataset variables need to be concatenated in the result,
351
351
"""
352
352
# variables to be concatenated
353
353
concat_over = set ()
354
354
# variables checked for equality
355
- equals : dict [Hashable , bool | None ] = {}
355
+ equals : dict [Hashable , bool ] = {}
356
356
# skip merging these variables.
357
357
# if concatenating over a dimension 'x' that is associated with an index over 2 variables,
358
358
# 'x' and 'y', then we assert join="equals" on `y` and don't need to merge it.
359
359
# that assertion happens in the align step prior to this function being called
360
- skip_merge = set ()
360
+ skip_merge : set [ Hashable ] = set ()
361
361
362
362
if dim in all_dims :
363
363
concat_over_existing_dim = True
@@ -380,7 +380,10 @@ def _calc_concat_over(
380
380
skip_merge .update (idx_vars .keys ())
381
381
concat_dim_lengths .append (ds .sizes .get (dim , 1 ))
382
382
383
- def process_subset_opt (opt , subset : Literal ["coords" , "data_vars" ]) -> None :
383
+ def process_subset_opt (
384
+ opt : ConcatOptions | Iterable [Hashable ] | CombineKwargDefault ,
385
+ subset : Literal ["coords" , "data_vars" ],
386
+ ) -> None :
384
387
original = set (concat_over )
385
388
compat_str = (
386
389
compat ._value if isinstance (compat , CombineKwargDefault ) else compat
@@ -411,7 +414,7 @@ def process_subset_opt(opt, subset: Literal["coords", "data_vars"]) -> None:
411
414
# all nonindexes that are not the same in each dataset
412
415
for k in getattr (datasets [0 ], subset ):
413
416
if k not in concat_over :
414
- equals [ k ] = None
417
+ equal = None
415
418
416
419
variables = [
417
420
ds .variables [k ] for ds in datasets if k in ds .variables
@@ -430,19 +433,19 @@ def process_subset_opt(opt, subset: Literal["coords", "data_vars"]) -> None:
430
433
431
434
# first check without comparing values i.e. no computes
432
435
for var in variables [1 :]:
433
- equals [ k ] = getattr (variables [0 ], compat_str )(
436
+ equal = getattr (variables [0 ], compat_str )(
434
437
var , equiv = lazy_array_equiv
435
438
)
436
- if equals [ k ] is not True :
439
+ if equal is not True :
437
440
# exit early if we know these are not equal or that
438
441
# equality cannot be determined i.e. one or all of
439
442
# the variables wraps a numpy array
440
443
break
441
444
442
- if equals [ k ] is False :
445
+ if equal is False :
443
446
concat_over .add (k )
444
447
445
- elif equals [ k ] is None :
448
+ elif equal is None :
446
449
# Compare the variable of all datasets vs. the one
447
450
# of the first dataset. Perform the minimum amount of
448
451
# loads in order to avoid multiple loads from disk
@@ -464,7 +467,10 @@ def process_subset_opt(opt, subset: Literal["coords", "data_vars"]) -> None:
464
467
ds .variables [k ].data = v .data
465
468
break
466
469
else :
467
- equals [k ] = True
470
+ equal = True
471
+ if TYPE_CHECKING :
472
+ assert equal is not None
473
+ equals [k ] = equal
468
474
469
475
elif opt == "all" :
470
476
concat_over .update (
@@ -564,7 +570,7 @@ def _dataset_concat(
564
570
datasets : Iterable [T_Dataset ],
565
571
dim : str | T_Variable | T_DataArray | pd .Index ,
566
572
data_vars : T_DataVars | CombineKwargDefault ,
567
- coords : str | list [Hashable ] | CombineKwargDefault ,
573
+ coords : ConcatOptions | Iterable [Hashable ] | CombineKwargDefault ,
568
574
compat : CompatOptions | CombineKwargDefault ,
569
575
positions : Iterable [Iterable [int ]] | None ,
570
576
fill_value : Any ,
@@ -807,7 +813,7 @@ def _dataarray_concat(
807
813
arrays : Iterable [T_DataArray ],
808
814
dim : str | T_Variable | T_DataArray | pd .Index ,
809
815
data_vars : T_DataVars | CombineKwargDefault ,
810
- coords : str | list [Hashable ] | CombineKwargDefault ,
816
+ coords : ConcatOptions | Iterable [Hashable ] | CombineKwargDefault ,
811
817
compat : CompatOptions | CombineKwargDefault ,
812
818
positions : Iterable [Iterable [int ]] | None ,
813
819
fill_value : object ,
0 commit comments