44
44
"broadcast_equals" : 2 ,
45
45
"minimal" : 3 ,
46
46
"no_conflicts" : 4 ,
47
+ "override" : 5 ,
47
48
}
48
49
)
49
50
@@ -81,7 +82,7 @@ def unique_variable(name, variables, compat="broadcast_equals"):
81
82
variables : list of xarray.Variable
82
83
List of Variable objects, all of which go by the same name in different
83
84
inputs.
84
- compat : {'identical', 'equals', 'broadcast_equals', 'no_conflicts'}, optional
85
+ compat : {'identical', 'equals', 'broadcast_equals', 'no_conflicts', 'override' }, optional
85
86
Type of equality check to use.
86
87
87
88
Returns
@@ -106,17 +107,20 @@ def unique_variable(name, variables, compat="broadcast_equals"):
106
107
if compat == "no_conflicts" :
107
108
combine_method = "fillna"
108
109
109
- for var in variables [1 :]:
110
- if not getattr (out , compat )(var ):
111
- raise MergeError (
112
- "conflicting values for variable %r on "
113
- "objects to be combined:\n "
114
- "first value: %r\n second value: %r" % (name , out , var )
115
- )
116
- if combine_method :
117
- # TODO: add preservation of attrs into fillna
118
- out = getattr (out , combine_method )(var )
119
- out .attrs = var .attrs
110
+ if compat == "override" :
111
+ out = variables [0 ]
112
+ else :
113
+ for var in variables [1 :]:
114
+ if not getattr (out , compat )(var ):
115
+ raise MergeError (
116
+ "conflicting values for variable %r on "
117
+ "objects to be combined:\n "
118
+ "first value: %r\n second value: %r" % (name , out , var )
119
+ )
120
+ if combine_method :
121
+ # TODO: add preservation of attrs into fillna
122
+ out = getattr (out , combine_method )(var )
123
+ out .attrs = var .attrs
120
124
121
125
return out
122
126
@@ -152,7 +156,7 @@ def merge_variables(
152
156
priority_vars : mapping with Variable or None values, optional
153
157
If provided, variables are always taken from this dict in preference to
154
158
the input variable dictionaries, without checking for conflicts.
155
- compat : {'identical', 'equals', 'broadcast_equals', 'minimal', 'no_conflicts'}, optional
159
+ compat : {'identical', 'equals', 'broadcast_equals', 'minimal', 'no_conflicts', 'override' }, optional
156
160
Type of equality check to use when checking for conflicts.
157
161
158
162
Returns
@@ -449,7 +453,7 @@ def merge_core(
449
453
----------
450
454
objs : list of mappings
451
455
All values must be convertable to labeled arrays.
452
- compat : {'identical', 'equals', 'broadcast_equals', 'no_conflicts'}, optional
456
+ compat : {'identical', 'equals', 'broadcast_equals', 'no_conflicts', 'override' }, optional
453
457
Compatibility checks to use when merging variables.
454
458
join : {'outer', 'inner', 'left', 'right'}, optional
455
459
How to combine objects with different indexes.
0 commit comments