Skip to content

Fix Index._repr_inline_() signature #10415

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

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def inherited_coords_repr(node: DataTree, col_width=None, max_rows=None):
)


def inline_index_repr(index: pd.Index, max_width=None):
def inline_index_repr(index: pd.Index, max_width: int) -> str:
if hasattr(index, "_repr_inline_"):
repr_ = index._repr_inline_(max_width=max_width)
else:
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def summarize_index(coord_names, index) -> str:
name = "<br>".join([escape(str(n)) for n in coord_names])

index_id = f"index-{uuid.uuid4()}"
preview = escape(inline_index_repr(index))
preview = escape(inline_index_repr(index, max_width=70))
details = short_index_repr_html(index)

data_icon = _icon("icon-database")
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def _copy(self, deep: bool = True, memo: dict[int, Any] | None = None) -> Self:
def __getitem__(self, indexer: Any) -> Self:
raise NotImplementedError()

def _repr_inline_(self, max_width):
def _repr_inline_(self, max_width: int) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is max_width a required arg?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It is also called only from within Xarray.

return self.__class__.__name__


Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_range_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,6 @@ def test_range_index_repr() -> None:

def test_range_index_repr_inline() -> None:
index = RangeIndex.arange(0.0, 1.0, 0.1, dim="x")
actual = index._repr_inline_(max_width=None)
actual = index._repr_inline_(max_width=70)
expected = "RangeIndex (start=0, stop=1, step=0.1)"
assert actual == expected
Loading