12
12
from xarray .core .dataset import Dataset
13
13
from xarray .core .merge import merge
14
14
from xarray .core .utils import iterate_nested
15
+ from xarray .util .deprecation_helpers import (
16
+ _COMPAT_DEFAULT ,
17
+ _COORDS_DEFAULT ,
18
+ _DATA_VARS_DEFAULT ,
19
+ _JOIN_DEFAULT ,
20
+ CombineKwargDefault ,
21
+ )
15
22
16
23
if TYPE_CHECKING :
17
24
from xarray .core .types import (
@@ -202,9 +209,9 @@ def _combine_nd(
202
209
concat_dims ,
203
210
data_vars ,
204
211
coords ,
205
- compat : CompatOptions ,
212
+ compat : CompatOptions | CombineKwargDefault ,
206
213
fill_value ,
207
- join : JoinOptions ,
214
+ join : JoinOptions | CombineKwargDefault ,
208
215
combine_attrs : CombineAttrsOptions ,
209
216
):
210
217
"""
@@ -264,7 +271,7 @@ def _combine_all_along_first_dim(
264
271
coords ,
265
272
compat : CompatOptions ,
266
273
fill_value ,
267
- join : JoinOptions ,
274
+ join : JoinOptions | CombineKwargDefault ,
268
275
combine_attrs : CombineAttrsOptions ,
269
276
):
270
277
# Group into lines of datasets which must be combined along dim
@@ -295,7 +302,7 @@ def _combine_1d(
295
302
data_vars ,
296
303
coords ,
297
304
fill_value ,
298
- join : JoinOptions ,
305
+ join : JoinOptions | CombineKwargDefault ,
299
306
combine_attrs : CombineAttrsOptions ,
300
307
):
301
308
"""
@@ -345,18 +352,21 @@ def _new_tile_id(single_id_ds_pair):
345
352
346
353
def _nested_combine (
347
354
datasets ,
348
- concat_dims ,
355
+ concat_dim ,
349
356
compat ,
350
357
data_vars ,
351
358
coords ,
352
359
ids ,
353
360
fill_value ,
354
- join : JoinOptions ,
361
+ join : JoinOptions | CombineKwargDefault ,
355
362
combine_attrs : CombineAttrsOptions ,
356
363
):
357
364
if len (datasets ) == 0 :
358
365
return Dataset ()
359
366
367
+ if isinstance (concat_dim , str | DataArray ) or concat_dim is None :
368
+ concat_dim = [concat_dim ] # type: ignore[assignment]
369
+
360
370
# Arrange datasets for concatenation
361
371
# Use information from the shape of the user input
362
372
if not ids :
@@ -373,7 +383,7 @@ def _nested_combine(
373
383
# Apply series of concatenate or merge operations along each dimension
374
384
combined = _combine_nd (
375
385
combined_ids ,
376
- concat_dims ,
386
+ concat_dims = concat_dim ,
377
387
compat = compat ,
378
388
data_vars = data_vars ,
379
389
coords = coords ,
@@ -391,11 +401,11 @@ def _nested_combine(
391
401
def combine_nested (
392
402
datasets : DATASET_HYPERCUBE ,
393
403
concat_dim : str | DataArray | None | Sequence [str | DataArray | pd .Index | None ],
394
- compat : str = "no_conflicts" ,
395
- data_vars : str = "all" ,
396
- coords : str = "different" ,
404
+ compat : str | CombineKwargDefault = _COMPAT_DEFAULT ,
405
+ data_vars : str | CombineKwargDefault = _DATA_VARS_DEFAULT ,
406
+ coords : str | CombineKwargDefault = _COORDS_DEFAULT ,
397
407
fill_value : object = dtypes .NA ,
398
- join : JoinOptions = "outer" ,
408
+ join : JoinOptions | CombineKwargDefault = _JOIN_DEFAULT ,
399
409
combine_attrs : CombineAttrsOptions = "drop" ,
400
410
) -> Dataset :
401
411
"""
@@ -588,13 +598,10 @@ def combine_nested(
588
598
if mixed_datasets_and_arrays :
589
599
raise ValueError ("Can't combine datasets with unnamed arrays." )
590
600
591
- if isinstance (concat_dim , str | DataArray ) or concat_dim is None :
592
- concat_dim = [concat_dim ]
593
-
594
601
# The IDs argument tells _nested_combine that datasets aren't yet sorted
595
602
return _nested_combine (
596
603
datasets ,
597
- concat_dims = concat_dim ,
604
+ concat_dim = concat_dim ,
598
605
compat = compat ,
599
606
data_vars = data_vars ,
600
607
coords = coords ,
@@ -629,8 +636,8 @@ def _combine_single_variable_hypercube(
629
636
fill_value ,
630
637
data_vars ,
631
638
coords ,
632
- compat : CompatOptions ,
633
- join : JoinOptions ,
639
+ compat : CompatOptions | CombineKwargDefault ,
640
+ join : JoinOptions | CombineKwargDefault ,
634
641
combine_attrs : CombineAttrsOptions ,
635
642
):
636
643
"""
@@ -685,11 +692,13 @@ def _combine_single_variable_hypercube(
685
692
686
693
def combine_by_coords (
687
694
data_objects : Iterable [Dataset | DataArray ] = [],
688
- compat : CompatOptions = "no_conflicts" ,
689
- data_vars : Literal ["all" , "minimal" , "different" ] | list [str ] = "all" ,
690
- coords : str = "different" ,
695
+ compat : CompatOptions | CombineKwargDefault = _COMPAT_DEFAULT ,
696
+ data_vars : Literal ["all" , "minimal" , "different" ]
697
+ | list [str ]
698
+ | CombineKwargDefault = _DATA_VARS_DEFAULT ,
699
+ coords : str | CombineKwargDefault = _COORDS_DEFAULT ,
691
700
fill_value : object = dtypes .NA ,
692
- join : JoinOptions = "outer" ,
701
+ join : JoinOptions | CombineKwargDefault = _JOIN_DEFAULT ,
693
702
combine_attrs : CombineAttrsOptions = "no_conflicts" ,
694
703
) -> Dataset | DataArray :
695
704
"""
0 commit comments