Wrap a pandas multi-index as Xarray coordinates (dimension + levels). The returned coordinate variables can be directly assigned to a :py:class:`~xarray.Dataset` or :py:class:`~xarray.DataArray` via the ``coords`` argument of their constructor. Parameters --
(cls, midx: pd.MultiIndex, dim: Hashable)
| 403 | |
| 404 | @classmethod |
| 405 | def from_pandas_multiindex(cls, midx: pd.MultiIndex, dim: Hashable) -> Self: |
| 406 | """Wrap a pandas multi-index as Xarray coordinates (dimension + levels). |
| 407 | |
| 408 | The returned coordinate variables can be directly assigned to a |
| 409 | :py:class:`~xarray.Dataset` or :py:class:`~xarray.DataArray` via the |
| 410 | ``coords`` argument of their constructor. |
| 411 | |
| 412 | Parameters |
| 413 | ---------- |
| 414 | midx : :py:class:`pandas.MultiIndex` |
| 415 | Pandas multi-index object. |
| 416 | dim : str |
| 417 | Dimension name. |
| 418 | |
| 419 | Returns |
| 420 | ------- |
| 421 | coords : Coordinates |
| 422 | A collection of Xarray indexed coordinates created from the multi-index. |
| 423 | |
| 424 | """ |
| 425 | xr_idx = PandasMultiIndex(midx, dim) |
| 426 | |
| 427 | variables = xr_idx.create_variables() |
| 428 | indexes = dict.fromkeys(variables, xr_idx) |
| 429 | |
| 430 | return cls(coords=variables, indexes=indexes) |
| 431 | |
| 432 | @property |
| 433 | def _names(self) -> set[Hashable]: |