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

Method from_xindex

xarray/core/coordinates.py:376–402  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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:

Callers 15

create_transform_daFunction · 0.80
setupMethod · 0.80
setupMethod · 0.80
create_dataset_arangeFunction · 0.80
test_range_index_arangeFunction · 0.80
test_range_index_dtypeFunction · 0.80
test_range_index_renameFunction · 0.80

Calls 1

create_variablesMethod · 0.45