# xarray.Index

### *class* xarray.Index[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/indexes.py#L39-L488)

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()`](xarray.Index.from_variables.html.md#xarray.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()`](xarray.Dataset.html.md#xarray.Dataset) and
[`DataArray()`](xarray.DataArray.html.md#xarray.DataArray) API, e.g., for an index to support `.sel()` it needs
to implement [`Index.sel()`](xarray.Index.sel.html.md#xarray.Index.sel), to support `.stack()` and
`.unstack()` it needs to implement [`Index.stack()`](xarray.Index.stack.html.md#xarray.Index.stack) and
[`Index.unstack()`](xarray.Index.unstack.html.md#xarray.Index.unstack), etc.

When a method is not (re)implemented, depending on the case the
corresponding operation on a [`Dataset()`](xarray.Dataset.html.md#xarray.Dataset) or [`DataArray()`](xarray.DataArray.html.md#xarray.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.

#### \_\_init_\_()

### Methods

| [`__init__`](#xarray.Index.__init__)()                                                                        |                                                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| [`concat`](xarray.Index.concat.html.md#xarray.Index.concat)(indexes, dim[, positions])                             | Create a new index by concatenating one or more indexes of the same type.                        |
| [`copy`](xarray.Index.copy.html.md#xarray.Index.copy)([deep])                                                    | Return a (deep) copy of this index.                                                              |
| [`create_variables`](xarray.Index.create_variables.html.md#xarray.Index.create_variables)([variables])                       | Maybe create new coordinate variables from this index.                                           |
| [`equals`](xarray.Index.equals.html.md#xarray.Index.equals)(other, \*\*kwargs)                                     | Compare this index with another index of the same type.                                          |
| [`from_variables`](xarray.Index.from_variables.html.md#xarray.Index.from_variables)(variables, \*, options)                | Create a new index object from one or more coordinate variables.                                 |
| [`isel`](xarray.Index.isel.html.md#xarray.Index.isel)(indexers)                                                  | Maybe returns a new index from the current index itself indexed by positional indexers.          |
| [`join`](xarray.Index.join.html.md#xarray.Index.join)(other[, how])                                              | Return a new index from the combination of this index with another index of the same type.       |
| [`reindex_like`](xarray.Index.reindex_like.html.md#xarray.Index.reindex_like)(other)                                     | Query the index with another index of the same type.                                             |
| [`rename`](xarray.Index.rename.html.md#xarray.Index.rename)(name_dict, dims_dict)                                  | Maybe update the index with new coordinate and dimension names.                                  |
| [`roll`](xarray.Index.roll.html.md#xarray.Index.roll)(shifts)                                                    | Roll this index by an offset along one or more dimensions.                                       |
| [`sel`](xarray.Index.sel.html.md#xarray.Index.sel)(labels)                                                      | Query the index with arbitrary coordinate label indexers.                                        |
| [`should_add_coord_to_array`](xarray.Index.should_add_coord_to_array.html.md#xarray.Index.should_add_coord_to_array)(name, var, dims) | Define whether or not an index coordinate variable should be added to a new DataArray.           |
| [`stack`](xarray.Index.stack.html.md#xarray.Index.stack)(variables, dim)                                          | Create a new index by stacking coordinate variables into a single new dimension.                 |
| [`to_pandas_index`](xarray.Index.to_pandas_index.html.md#xarray.Index.to_pandas_index)()                                    | Cast this xarray index to a pandas.Index object or raise a `TypeError` if this is not supported. |
| [`unstack`](xarray.Index.unstack.html.md#xarray.Index.unstack)()                                                    | Unstack a (multi-)index into multiple (single) indexes.                                          |
