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

Function assert_no_index_corrupted

xarray/core/indexes.py:2252–2270  ·  view source on GitHub ↗

Assert removing coordinates or indexes will not corrupt indexes.

(
    indexes: Indexes[Index],
    coord_names: set[Hashable],
    action: str = "remove coordinate(s)",
)

Source from the content-addressed store, hash-verified

2250
2251
2252def assert_no_index_corrupted(
2253 indexes: Indexes[Index],
2254 coord_names: set[Hashable],
2255 action: str = "remove coordinate(s)",
2256) -> None:
2257 """Assert removing coordinates or indexes will not corrupt indexes."""
2258
2259 # An index may be corrupted when the set of its corresponding coordinate name(s)
2260 # partially overlaps the set of coordinate names to remove
2261 for index, index_coords in indexes.group_by_index():
2262 common_names = set(index_coords) & coord_names
2263 if common_names and len(common_names) != len(index_coords):
2264 common_names_str = ", ".join(f"{k!r}" for k in common_names)
2265 index_names_str = ", ".join(f"{k!r}" for k in index_coords)
2266 raise ValueError(
2267 f"cannot {action} {common_names_str}, which would corrupt "
2268 f"the following index built from coordinates {index_names_str}:\n"
2269 f"{index}"
2270 )

Callers 4

__delitem__Method · 0.90
drop_varsMethod · 0.90
drop_indexesMethod · 0.90
__delitem__Method · 0.90

Calls 2

group_by_indexMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…