MCPcopy
hub / github.com/pydata/xarray / indexes_equal

Function indexes_equal

xarray/core/indexes.py:2016–2052  ·  view source on GitHub ↗

Check if two indexes are equal, possibly with cached results. If the two indexes are not of the same type or they do not implement equality, fallback to coordinate labels equality check.

(
    index: Index,
    other_index: Index,
    variable: Variable,
    other_variable: Variable,
    cache: dict[tuple[int, int], bool | None] | None = None,
)

Source from the content-addressed store, hash-verified

2014
2015
2016def indexes_equal(
2017 index: Index,
2018 other_index: Index,
2019 variable: Variable,
2020 other_variable: Variable,
2021 cache: dict[tuple[int, int], bool | None] | None = None,
2022) -> bool:
2023 """Check if two indexes are equal, possibly with cached results.
2024
2025 If the two indexes are not of the same type or they do not implement
2026 equality, fallback to coordinate labels equality check.
2027
2028 """
2029 if cache is None:
2030 # dummy cache
2031 cache = {}
2032
2033 key = (id(index), id(other_index))
2034 equal: bool | None = None
2035
2036 if key not in cache:
2037 if type(index) is type(other_index):
2038 try:
2039 equal = index.equals(other_index)
2040 except NotImplementedError:
2041 equal = None
2042 else:
2043 cache[key] = equal
2044 else:
2045 equal = None
2046 else:
2047 equal = cache[key]
2048
2049 if equal is None:
2050 equal = variable.equals(other_variable)
2051
2052 return cast(bool, equal)
2053
2054
2055def indexes_identical(

Callers 1

merge_collectedFunction · 0.90

Calls 2

typeFunction · 0.85
equalsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…