class xarray.Index[source]#

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 implement Index.from_variables(). The (re)implementation of the other methods of this base class is optional but mostly required in order to support operations relying on indexes such as label-based selection or alignment.

The Index API closely follows the Dataset() and DataArray() API, e.g., for an index to support .sel() it needs to implement Index.sel(), to support .stack() and .unstack() it needs to implement Index.stack() and Index.unstack(), etc.

When a method is not (re)implemented, depending on the case the corresponding operation on a Dataset() or DataArray() either will raise a NotImplementedError or will simply drop/pass/copy the index from/to the result.

Do not use this class directly for creating index objects.




concat(indexes, dim[, positions])

Create a new index by concatenating one or more indexes of the same type.


Return a (deep) copy of this index.


Maybe create new coordinate variables from this index.


Compare this index with another index of the same type.

from_variables(variables, *, options)

Create a new index object from one or more coordinate variables.


Maybe returns a new index from the current index itself indexed by positional indexers.

join(other[, how])

Return a new index from the combination of this index with another index of the same type.


Query the index with another index of the same type.

rename(name_dict, dims_dict)

Maybe update the index with new coordinate and dimension names.


Roll this index by an offset along one or more dimensions.


Query the index with arbitrary coordinate label indexers.

stack(variables, dim)

Create a new index by stacking coordinate variables into a single new dimension.


Cast this xarray index to a pandas.Index object or raise a TypeError if this is not supported.


Unstack a (multi-)index into multiple (single) indexes.