xarray.Index#
- 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 likeDataset.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
IndexAPI closely follows theDataset()andDataArray()API, e.g., for an index to support.sel()it needs to implementIndex.sel(), to support.stack()and.unstack()it needs to implementIndex.stack()andIndex.unstack(), etc.When a method is not (re)implemented, depending on the case the corresponding operation on a
Dataset()orDataArray()either will raise aNotImplementedErroror will simply drop/pass/copy the index from/to the result.Do not use this class directly for creating index objects.
- __init__()#
Methods
__init__()concat(indexes, dim[, positions])Create a new index by concatenating one or more indexes of the same type.
copy([deep])Return a (deep) copy of this index.
create_variables([variables])Maybe create new coordinate variables from this index.
equals(other, **kwargs)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.
isel(indexers)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.
reindex_like(other)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(shifts)Roll this index by an offset along one or more dimensions.
sel(labels)Query the index with arbitrary coordinate label indexers.
should_add_coord_to_array(name, var, dims)Define whether or not an index coordinate variable should be added to a new DataArray.
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
TypeErrorif this is not supported.unstack()Unstack a (multi-)index into multiple (single) indexes.