Skip to content

Commit

Permalink
Rename ordered_dict_union -> compat_dict_union
Browse files Browse the repository at this point in the history
Do not use OrderedDicts any more, so name did not make sense.
  • Loading branch information
johnomotani committed Mar 23, 2020
1 parent 23df58e commit 5249814
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions xarray/core/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from . import dtypes, pdcompat
from .alignment import deep_align
from .duck_array_ops import lazy_array_equiv
from .utils import Frozen, dict_equiv, ordered_dict_union
from .utils import Frozen, compat_dict_union, dict_equiv
from .variable import Variable, as_variable, assert_unique_multiindex_level_names

if TYPE_CHECKING:
Expand Down Expand Up @@ -506,7 +506,7 @@ def merge_attrs(variable_attrs, combine_attrs):
result = dict(variable_attrs[0])
for attrs in variable_attrs[1:]:
try:
result = ordered_dict_union(result, attrs)
result = compat_dict_union(result, attrs)
except ValueError:
raise MergeError(
"combine_attrs='no_conflicts', but some values are not "
Expand Down
9 changes: 6 additions & 3 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ def ordered_dict_intersection(
Binary operator to determine if two values are compatible. By default,
checks for equivalence.
# TODO: Rename to compat_dict_intersection, as we do not use OrderedDicts
# any more.
Returns
-------
intersection : dict
Expand All @@ -371,15 +374,15 @@ def ordered_dict_intersection(
return new_dict


def ordered_dict_union(
def compat_dict_union(
first_dict: Mapping[K, V],
second_dict: Mapping[K, V],
compat: Callable[[V, V], bool] = equivalent,
) -> MutableMapping[K, V]:
"""Return the union of two dictionaries as a new dictionary.
An exception is raised if any keys are found in both dictionaries and the values are
not compatible.
An exception is raised if any keys are found in both dictionaries and the
values are not compatible.
Parameters
----------
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ def test_ordered_dict_intersection(self):
assert {"b": "B"} == utils.ordered_dict_intersection(self.x, self.y)
assert {} == utils.ordered_dict_intersection(self.x, self.z)

def test_ordered_dict_union(self):
assert {"a": "A", "b": "B", "c": "C"} == utils.ordered_dict_union(
def test_compat_dict_union(self):
assert {"a": "A", "b": "B", "c": "C"} == utils.compat_dict_union(
self.x, self.y
)
with raises_regex(
ValueError,
"unsafe to merge dictionaries without "
"overriding values; conflicting key",
):
utils.ordered_dict_union(self.x, self.z)
utils.compat_dict_union(self.x, self.z)

def test_dict_equiv(self):
x = {}
Expand Down

0 comments on commit 5249814

Please sign in to comment.