Assert removing coordinates or indexes will not corrupt indexes.
(
indexes: Indexes[Index],
coord_names: set[Hashable],
action: str = "remove coordinate(s)",
)
| 2250 | |
| 2251 | |
| 2252 | def 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 | ) |
no test coverage detected
searching dependent graphs…