MCPcopy Index your code
hub / github.com/pydata/xarray / Index

Class Index

xarray/core/indexes.py:39–488  ·  view source on GitHub ↗

Base class inherited by all xarray-compatible indexes. Do not use this class directly for creating index objects. Xarray indexes are created exclusively from subclasses of ``Index``, mostly via Xarray's public API like ``Dataset.set_xindex``. Every subclass must at least imple

Source from the content-addressed store, hash-verified

37
38
39class Index:
40 """
41 Base class inherited by all xarray-compatible indexes.
42
43 Do not use this class directly for creating index objects. Xarray indexes
44 are created exclusively from subclasses of ``Index``, mostly via Xarray's
45 public API like ``Dataset.set_xindex``.
46
47 Every subclass must at least implement :py:meth:`Index.from_variables`. The
48 (re)implementation of the other methods of this base class is optional but
49 mostly required in order to support operations relying on indexes such as
50 label-based selection or alignment.
51
52 The ``Index`` API closely follows the :py:meth:`Dataset` and
53 :py:meth:`DataArray` API, e.g., for an index to support ``.sel()`` it needs
54 to implement :py:meth:`Index.sel`, to support ``.stack()`` and
55 ``.unstack()`` it needs to implement :py:meth:`Index.stack` and
56 :py:meth:`Index.unstack`, etc.
57
58 When a method is not (re)implemented, depending on the case the
59 corresponding operation on a :py:meth:`Dataset` or :py:meth:`DataArray`
60 either will raise a ``NotImplementedError`` or will simply drop/pass/copy
61 the index from/to the result.
62
63 Do not use this class directly for creating index objects.
64 """
65
66 @classmethod
67 def from_variables(
68 cls,
69 variables: Mapping[Any, Variable],
70 *,
71 options: Mapping[str, Any],
72 ) -> Self:
73 """Create a new index object from one or more coordinate variables.
74
75 This factory method must be implemented in all subclasses of Index.
76
77 The coordinate variables may be passed here in an arbitrary number and
78 order and each with arbitrary dimensions. It is the responsibility of
79 the index to check the consistency and validity of these coordinates.
80
81 Parameters
82 ----------
83 variables : dict-like
84 Mapping of :py:class:`Variable` objects holding the coordinate labels
85 to index.
86 options : dict-like
87 Keyword arguments passed to this constructor. Propagated from
88 the ``**options`` argument of :py:meth:`xarray.DataArray.set_xindex`
89 or :py:meth:`xarray.Dataset.set_xindex`.
90
91 Returns
92 -------
93 index : Index
94 A new Index object.
95 """
96 raise NotImplementedError()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…