Create Xarray coordinates from an existing Xarray index. Parameters ---------- index : Index Xarray index object. The index must support generating new coordinate variables from itself. Returns ------- coords : Coordinates
(cls, index: Index)
| 374 | |
| 375 | @classmethod |
| 376 | def from_xindex(cls, index: Index) -> Self: |
| 377 | """Create Xarray coordinates from an existing Xarray index. |
| 378 | |
| 379 | Parameters |
| 380 | ---------- |
| 381 | index : Index |
| 382 | Xarray index object. The index must support generating new |
| 383 | coordinate variables from itself. |
| 384 | |
| 385 | Returns |
| 386 | ------- |
| 387 | coords : Coordinates |
| 388 | A collection of Xarray indexed coordinates created from the index. |
| 389 | |
| 390 | """ |
| 391 | variables = index.create_variables() |
| 392 | |
| 393 | if not variables: |
| 394 | raise ValueError( |
| 395 | "`Coordinates.from_xindex()` only supports index objects that can generate " |
| 396 | "new coordinate variables from scratch. The given index (shown below) did not " |
| 397 | f"create any coordinate.\n{index!r}" |
| 398 | ) |
| 399 | |
| 400 | indexes = dict.fromkeys(variables, index) |
| 401 | |
| 402 | return cls(coords=variables, indexes=indexes) |
| 403 | |
| 404 | @classmethod |
| 405 | def from_pandas_multiindex(cls, midx: pd.MultiIndex, dim: Hashable) -> Self: |