Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible indexes: add Index base class and xindexes properties #5102

Merged
merged 23 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ Internal Changes
``pytest.raises(Exception, match="foo")``;
(:pull:`5188`), (:pull:`5191`).
By `Maximilian Roos <https://github.com/max-sixty>`_.

- Explicit indexes refactor: add an ``xarray.Index`` base class and
``Dataset.xindexes`` / ``DataArray.xindexes`` properties. Also rename
``PandasIndexAdapter`` to ``PandasIndex``, which now inherits from
``xarray.Index`` (:pull:`5102`). By `Benoit Bovy <https://github.com/benbovy>`_.
benbovy marked this conversation as resolved.
Show resolved Hide resolved

.. _whats-new.0.17.0:

Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def encoding(self, value: Mapping[Hashable, Any]) -> None:
def indexes(self) -> Indexes:
"""Mapping of pandas.Index objects used for label based indexing.

Raises an error in case where this Dataset has indexes that cannot be coerced
Raises an error if this Dataset has indexes that cannot be coerced
to pandas.Index objects.

See Also
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ def identical(self, other: "Dataset") -> bool:
def indexes(self) -> Indexes:
"""Mapping of pandas.Index objects used for label based indexing.

Raises an error in case where this Dataset has indexes that cannot be coerced
Raises an error if this Dataset has indexes that cannot be coerced
to pandas.Index objects.

See Also
Expand Down
6 changes: 2 additions & 4 deletions xarray/core/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class Index:
"""Base class inherited by all xarray-compatible indexes."""

__slots__ = "coord_names"
__slots__ = ("coord_names",)

def __init__(self, coord_names: Union[Hashable, Iterable[Hashable]]):
if isinstance(coord_names, Iterable) and not isinstance(coord_names, str):
Expand Down Expand Up @@ -183,9 +183,7 @@ def transpose(self, order) -> pd.Index:
return self.array # self.array should be always one-dimensional

def __repr__(self) -> str:
return "{}(array={!r}, dtype={!r})".format(
type(self).__name__, self.array, self.dtype
)
return f"{type(self).__name__}(array={self.array!r}, dtype={self.dtype!r})"

def copy(self, deep: bool = True) -> "PandasIndex":
# Not the same as just writing `self.array.copy(deep=deep)`, as
Expand Down