Immutable proxy for Dataset or DataArray indexes. It is a mapping where keys are coordinate names and values are either pandas or xarray indexes. It also contains the indexed coordinate variables and provides some utility methods.
| 1683 | |
| 1684 | |
| 1685 | class Indexes(collections.abc.Mapping, Generic[T_PandasOrXarrayIndex]): |
| 1686 | """Immutable proxy for Dataset or DataArray indexes. |
| 1687 | |
| 1688 | It is a mapping where keys are coordinate names and values are either pandas |
| 1689 | or xarray indexes. |
| 1690 | |
| 1691 | It also contains the indexed coordinate variables and provides some utility |
| 1692 | methods. |
| 1693 | |
| 1694 | """ |
| 1695 | |
| 1696 | _index_type: type[Index | pd.Index] |
| 1697 | _indexes: dict[Any, T_PandasOrXarrayIndex] |
| 1698 | _variables: dict[Any, Variable] |
| 1699 | |
| 1700 | __slots__ = ( |
| 1701 | "__coord_name_id", |
| 1702 | "__id_coord_names", |
| 1703 | "__id_index", |
| 1704 | "_dims", |
| 1705 | "_index_type", |
| 1706 | "_indexes", |
| 1707 | "_variables", |
| 1708 | ) |
| 1709 | |
| 1710 | def __init__( |
| 1711 | self, |
| 1712 | indexes: Mapping[Any, T_PandasOrXarrayIndex] | None = None, |
| 1713 | variables: Mapping[Any, Variable] | None = None, |
| 1714 | index_type: type[Index | pd.Index] = Index, |
| 1715 | ): |
| 1716 | """Constructor not for public consumption. |
| 1717 | |
| 1718 | Parameters |
| 1719 | ---------- |
| 1720 | indexes : dict |
| 1721 | Indexes held by this object. |
| 1722 | variables : dict |
| 1723 | Indexed coordinate variables in this object. Entries must |
| 1724 | match those of `indexes`. |
| 1725 | index_type : type |
| 1726 | The type of all indexes, i.e., either :py:class:`xarray.indexes.Index` |
| 1727 | or :py:class:`pandas.Index`. |
| 1728 | |
| 1729 | """ |
| 1730 | if indexes is None: |
| 1731 | indexes = {} |
| 1732 | if variables is None: |
| 1733 | variables = {} |
| 1734 | |
| 1735 | unmatched_keys = set(indexes) ^ set(variables) |
| 1736 | if unmatched_keys: |
| 1737 | raise ValueError( |
| 1738 | f"unmatched keys found in indexes and variables: {unmatched_keys}" |
| 1739 | ) |
| 1740 | |
| 1741 | if any(not isinstance(idx, index_type) for idx in indexes.values()): |
| 1742 | index_type_str = f"{index_type.__module__}.{index_type.__name__}" |
no outgoing calls
searching dependent graphs…