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

Print number of variables in repr #4762

Merged
Merged
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
4 changes: 3 additions & 1 deletion xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ def _mapping_repr(mapping, title, summarizer, col_width=None, max_rows=None):
max_rows = OPTIONS["display_max_rows"]
summary = [f"{title}:"]
if mapping:
if len(mapping) > max_rows:
len_mapping = len(mapping)
if len_mapping > max_rows:
summary = [f"{summary[0]} ({max_rows}/{len_mapping})"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this no longer get the title though?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be +=?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets the title via summary[0] in the f-string. I did this because I want the number to be displayed on the same row as title, Attributes: (12/25). If we do += the numbers would be shown on a new line.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah sorry I missed that

first_rows = max_rows // 2 + max_rows % 2
items = list(mapping.items())
summary += [summarizer(k, v, col_width) for k, v in items[:first_rows]]
Expand Down