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

Method align_indexes

xarray/structure/alignment.py:395–508  ·  view source on GitHub ↗

Compute all aligned indexes and their corresponding coordinate variables.

(self)

Source from the content-addressed store, hash-verified

393 return lambda _: None
394
395 def align_indexes(self) -> None:
396 """Compute all aligned indexes and their corresponding coordinate variables."""
397
398 aligned_indexes: dict[MatchingIndexKey, Index] = {}
399 aligned_index_vars: dict[MatchingIndexKey, dict[Hashable, Variable]] = {}
400 reindex: dict[MatchingIndexKey, bool] = {}
401 new_indexes: dict[Hashable, Index] = {}
402 new_index_vars: dict[Hashable, Variable] = {}
403
404 def update_dicts(
405 key: MatchingIndexKey,
406 idx: Index,
407 idx_vars: dict[Hashable, Variable],
408 need_reindex: bool,
409 ):
410 reindex[key] = need_reindex
411 aligned_indexes[key] = idx
412 aligned_index_vars[key] = idx_vars
413
414 for name, var in idx_vars.items():
415 if name in new_indexes:
416 other_idx = new_indexes[name]
417 other_var = new_index_vars[name]
418 raise AlignmentError(
419 f"cannot align objects on coordinate {name!r} because of conflicting indexes\n"
420 f"first index: {idx!r}\nsecond index: {other_idx!r}\n"
421 f"first variable: {var!r}\nsecond variable: {other_var!r}\n"
422 )
423 new_indexes[name] = idx
424 new_index_vars[name] = var
425
426 for key, matching_indexes in self.all_indexes.items():
427 matching_index_vars = self.all_index_vars[key]
428 dims = {d for coord in matching_index_vars[0].values() for d in coord.dims}
429 index_cls = key[1]
430
431 if self.join == "override":
432 joined_index = matching_indexes[0]
433 joined_index_vars = matching_index_vars[0]
434 need_reindex = False
435 elif key in self.indexes:
436 joined_index = self.indexes[key]
437 joined_index_vars = self.index_vars[key]
438 cmp_indexes = list(
439 zip(
440 [joined_index] + matching_indexes,
441 [joined_index_vars] + matching_index_vars,
442 strict=True,
443 )
444 )
445 need_reindex = self._need_reindex(dims, cmp_indexes)
446 else:
447 if len(matching_indexes) > 1:
448 need_reindex = self._need_reindex(
449 dims,
450 list(zip(matching_indexes, matching_index_vars, strict=True)),
451 )
452 else:

Callers 1

alignMethod · 0.95

Calls 11

_need_reindexMethod · 0.95
_get_index_joinerMethod · 0.95
emit_user_level_warningFunction · 0.90
IndexesClass · 0.90
AlignmentErrorClass · 0.85
itemsMethod · 0.80
warning_messageMethod · 0.80
error_messageMethod · 0.80
valuesMethod · 0.45
joinMethod · 0.45
create_variablesMethod · 0.45

Tested by

no test coverage detected