@@ -136,7 +136,7 @@ def _check_shape_tile_ids(combined_tile_ids):
136
136
137
137
def _combine_nd (combined_ids , concat_dims , data_vars = 'all' ,
138
138
coords = 'different' , compat = 'no_conflicts' ,
139
- fill_value = dtypes .NA ):
139
+ fill_value = dtypes .NA , join = 'outer' ):
140
140
"""
141
141
Combines an N-dimensional structure of datasets into one by applying a
142
142
series of either concat and merge operations along each dimension.
@@ -177,13 +177,14 @@ def _combine_nd(combined_ids, concat_dims, data_vars='all',
177
177
data_vars = data_vars ,
178
178
coords = coords ,
179
179
compat = compat ,
180
- fill_value = fill_value )
180
+ fill_value = fill_value ,
181
+ join = join )
181
182
(combined_ds ,) = combined_ids .values ()
182
183
return combined_ds
183
184
184
185
185
186
def _combine_all_along_first_dim (combined_ids , dim , data_vars , coords , compat ,
186
- fill_value = dtypes .NA ):
187
+ fill_value = dtypes .NA , join = 'outer' ):
187
188
188
189
# Group into lines of datasets which must be combined along dim
189
190
# need to sort by _new_tile_id first for groupby to work
@@ -197,12 +198,13 @@ def _combine_all_along_first_dim(combined_ids, dim, data_vars, coords, compat,
197
198
combined_ids = OrderedDict (sorted (group ))
198
199
datasets = combined_ids .values ()
199
200
new_combined_ids [new_id ] = _combine_1d (datasets , dim , compat ,
200
- data_vars , coords , fill_value )
201
+ data_vars , coords , fill_value ,
202
+ join )
201
203
return new_combined_ids
202
204
203
205
204
206
def _combine_1d (datasets , concat_dim , compat = 'no_conflicts' , data_vars = 'all' ,
205
- coords = 'different' , fill_value = dtypes .NA ):
207
+ coords = 'different' , fill_value = dtypes .NA , join = 'outer' ):
206
208
"""
207
209
Applies either concat or merge to 1D list of datasets depending on value
208
210
of concat_dim
@@ -211,7 +213,7 @@ def _combine_1d(datasets, concat_dim, compat='no_conflicts', data_vars='all',
211
213
if concat_dim is not None :
212
214
try :
213
215
combined = concat (datasets , dim = concat_dim , data_vars = data_vars ,
214
- coords = coords , fill_value = fill_value )
216
+ coords = coords , fill_value = fill_value , join = join )
215
217
except ValueError as err :
216
218
if "encountered unexpected variable" in str (err ):
217
219
raise ValueError ("These objects cannot be combined using only "
@@ -222,7 +224,8 @@ def _combine_1d(datasets, concat_dim, compat='no_conflicts', data_vars='all',
222
224
else :
223
225
raise
224
226
else :
225
- combined = merge (datasets , compat = compat , fill_value = fill_value )
227
+ combined = merge (datasets , compat = compat , fill_value = fill_value ,
228
+ join = join )
226
229
227
230
return combined
228
231
@@ -233,7 +236,7 @@ def _new_tile_id(single_id_ds_pair):
233
236
234
237
235
238
def _nested_combine (datasets , concat_dims , compat , data_vars , coords , ids ,
236
- fill_value = dtypes .NA ):
239
+ fill_value = dtypes .NA , join = 'outer' ):
237
240
238
241
if len (datasets ) == 0 :
239
242
return Dataset ()
@@ -254,12 +257,13 @@ def _nested_combine(datasets, concat_dims, compat, data_vars, coords, ids,
254
257
# Apply series of concatenate or merge operations along each dimension
255
258
combined = _combine_nd (combined_ids , concat_dims , compat = compat ,
256
259
data_vars = data_vars , coords = coords ,
257
- fill_value = fill_value )
260
+ fill_value = fill_value , join = join )
258
261
return combined
259
262
260
263
261
264
def combine_nested (datasets , concat_dim , compat = 'no_conflicts' ,
262
- data_vars = 'all' , coords = 'different' , fill_value = dtypes .NA ):
265
+ data_vars = 'all' , coords = 'different' , fill_value = dtypes .NA ,
266
+ join = 'outer' ):
263
267
"""
264
268
Explicitly combine an N-dimensional grid of datasets into one by using a
265
269
succession of concat and merge operations along each dimension of the grid.
@@ -312,6 +316,16 @@ def combine_nested(datasets, concat_dim, compat='no_conflicts',
312
316
Details are in the documentation of concat
313
317
fill_value : scalar, optional
314
318
Value to use for newly missing values
319
+ join : {'outer', 'inner', 'left', 'right', 'exact'}, optional
320
+ String indicating how to combine differing indexes
321
+ (excluding concat_dim) in objects
322
+
323
+ - 'outer': use the union of object indexes
324
+ - 'inner': use the intersection of object indexes
325
+ - 'left': use indexes from the first object with each dimension
326
+ - 'right': use indexes from the last object with each dimension
327
+ - 'exact': instead of aligning, raise `ValueError` when indexes to be
328
+ aligned are not equal
315
329
316
330
Returns
317
331
-------
@@ -383,15 +397,15 @@ def combine_nested(datasets, concat_dim, compat='no_conflicts',
383
397
# The IDs argument tells _manual_combine that datasets aren't yet sorted
384
398
return _nested_combine (datasets , concat_dims = concat_dim , compat = compat ,
385
399
data_vars = data_vars , coords = coords , ids = False ,
386
- fill_value = fill_value )
400
+ fill_value = fill_value , join = join )
387
401
388
402
389
403
def vars_as_keys (ds ):
390
404
return tuple (sorted (ds ))
391
405
392
406
393
407
def combine_by_coords (datasets , compat = 'no_conflicts' , data_vars = 'all' ,
394
- coords = 'different' , fill_value = dtypes .NA ):
408
+ coords = 'different' , fill_value = dtypes .NA , join = 'outer' ):
395
409
"""
396
410
Attempt to auto-magically combine the given datasets into one by using
397
411
dimension coordinates.
@@ -439,6 +453,16 @@ def combine_by_coords(datasets, compat='no_conflicts', data_vars='all',
439
453
Details are in the documentation of concat
440
454
fill_value : scalar, optional
441
455
Value to use for newly missing values
456
+ join : {'outer', 'inner', 'left', 'right', 'exact'}, optional
457
+ String indicating how to combine differing indexes
458
+ (excluding concat_dim) in objects
459
+
460
+ - 'outer': use the union of object indexes
461
+ - 'inner': use the intersection of object indexes
462
+ - 'left': use indexes from the first object with each dimension
463
+ - 'right': use indexes from the last object with each dimension
464
+ - 'exact': instead of aligning, raise `ValueError` when indexes to be
465
+ aligned are not equal
442
466
443
467
Returns
444
468
-------
@@ -498,7 +522,7 @@ def combine_by_coords(datasets, compat='no_conflicts', data_vars='all',
498
522
# Concatenate along all of concat_dims one by one to create single ds
499
523
concatenated = _combine_nd (combined_ids , concat_dims = concat_dims ,
500
524
data_vars = data_vars , coords = coords ,
501
- fill_value = fill_value )
525
+ fill_value = fill_value , join = join )
502
526
503
527
# Check the overall coordinates are monotonically increasing
504
528
for dim in concat_dims :
@@ -511,7 +535,7 @@ def combine_by_coords(datasets, compat='no_conflicts', data_vars='all',
511
535
concatenated_grouped_by_data_vars .append (concatenated )
512
536
513
537
return merge (concatenated_grouped_by_data_vars , compat = compat ,
514
- fill_value = fill_value )
538
+ fill_value = fill_value , join = join )
515
539
516
540
517
541
# Everything beyond here is only needed until the deprecation cycle in #2616
@@ -523,7 +547,7 @@ def combine_by_coords(datasets, compat='no_conflicts', data_vars='all',
523
547
524
548
def auto_combine (datasets , concat_dim = '_not_supplied' , compat = 'no_conflicts' ,
525
549
data_vars = 'all' , coords = 'different' , fill_value = dtypes .NA ,
526
- from_openmfds = False ):
550
+ join = 'outer' , from_openmfds = False ):
527
551
"""
528
552
Attempt to auto-magically combine the given datasets into one.
529
553
@@ -571,6 +595,16 @@ def auto_combine(datasets, concat_dim='_not_supplied', compat='no_conflicts',
571
595
Details are in the documentation of concat
572
596
fill_value : scalar, optional
573
597
Value to use for newly missing values
598
+ join : {'outer', 'inner', 'left', 'right', 'exact'}, optional
599
+ String indicating how to combine differing indexes
600
+ (excluding concat_dim) in objects
601
+
602
+ - 'outer': use the union of object indexes
603
+ - 'inner': use the intersection of object indexes
604
+ - 'left': use indexes from the first object with each dimension
605
+ - 'right': use indexes from the last object with each dimension
606
+ - 'exact': instead of aligning, raise `ValueError` when indexes to be
607
+ aligned are not equal
574
608
575
609
Returns
576
610
-------
@@ -629,7 +663,8 @@ def auto_combine(datasets, concat_dim='_not_supplied', compat='no_conflicts',
629
663
630
664
return _old_auto_combine (datasets , concat_dim = concat_dim ,
631
665
compat = compat , data_vars = data_vars ,
632
- coords = coords , fill_value = fill_value )
666
+ coords = coords , fill_value = fill_value ,
667
+ join = join )
633
668
634
669
635
670
def _dimension_coords_exist (datasets ):
@@ -670,7 +705,7 @@ def _requires_concat_and_merge(datasets):
670
705
def _old_auto_combine (datasets , concat_dim = _CONCAT_DIM_DEFAULT ,
671
706
compat = 'no_conflicts' ,
672
707
data_vars = 'all' , coords = 'different' ,
673
- fill_value = dtypes .NA ):
708
+ fill_value = dtypes .NA , join = 'outer' ):
674
709
if concat_dim is not None :
675
710
dim = None if concat_dim is _CONCAT_DIM_DEFAULT else concat_dim
676
711
@@ -679,16 +714,17 @@ def _old_auto_combine(datasets, concat_dim=_CONCAT_DIM_DEFAULT,
679
714
680
715
concatenated = [_auto_concat (list (datasets ), dim = dim ,
681
716
data_vars = data_vars , coords = coords ,
682
- fill_value = fill_value )
717
+ fill_value = fill_value , join = join )
683
718
for vars , datasets in grouped ]
684
719
else :
685
720
concatenated = datasets
686
- merged = merge (concatenated , compat = compat , fill_value = fill_value )
721
+ merged = merge (concatenated , compat = compat , fill_value = fill_value ,
722
+ join = join )
687
723
return merged
688
724
689
725
690
726
def _auto_concat (datasets , dim = None , data_vars = 'all' , coords = 'different' ,
691
- fill_value = dtypes .NA ):
727
+ fill_value = dtypes .NA , join = 'outer' ):
692
728
if len (datasets ) == 1 and dim is None :
693
729
# There is nothing more to combine, so kick out early.
694
730
return datasets [0 ]
0 commit comments