Skip to content

Commit 57b36a9

Browse files
committed
Attempt to refactor DataQuery equality
1 parent c3e2009 commit 57b36a9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

satpy/dataset/dataid.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,8 @@ def equal(self, other: Any, shared_keys: bool = False) -> bool:
298298
return True
299299

300300
# if other is a DataID then must match this query exactly
301-
keys_to_match = set(sdict.keys())
302301
o_is_id = hasattr(other, "id_keys")
303-
if not o_is_id:
304-
# if another DataQuery, then compare both sets of keys
305-
keys_to_match |= set(odict.keys())
306-
if shared_keys:
307-
# only compare with the keys that both objects share
308-
keys_to_match &= set(odict.keys())
302+
keys_to_match = self._keys_to_compare(sdict, odict, o_is_id, shared_keys)
309303
if not keys_to_match:
310304
return False
311305

@@ -314,6 +308,17 @@ def equal(self, other: Any, shared_keys: bool = False) -> bool:
314308
return False
315309
return True
316310

311+
@staticmethod
312+
def _keys_to_compare(sdict: dict, odict: dict, o_is_id: bool, shared_keys: bool) -> set:
313+
keys_to_match = set(sdict.keys())
314+
if not o_is_id:
315+
# if another DataQuery, then compare both sets of keys
316+
keys_to_match |= set(odict.keys())
317+
if shared_keys:
318+
# only compare with the keys that both objects share
319+
keys_to_match &= set(odict.keys())
320+
return keys_to_match
321+
317322
@staticmethod
318323
def _compare_key_equality(sdict: dict, odict: dict, key: str, o_is_id: bool) -> bool:
319324
if key not in sdict:

0 commit comments

Comments
 (0)