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

speed up the repr for big MultiIndex objects #4846

Merged
merged 6 commits into from
Jan 29, 2021
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
18 changes: 18 additions & 0 deletions asv_bench/benchmarks/repr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pandas as pd

import xarray as xr


class ReprMultiIndex:
def setup(self, key):
index = pd.MultiIndex.from_product(
[range(10000), range(10000)], names=("level_0", "level_1")
)
series = pd.Series(range(100000000), index=index)
self.da = xr.DataArray(series)

def time_repr(self):
repr(self.da)

def time_repr_html(self):
self.da._repr_html_()
11 changes: 9 additions & 2 deletions xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,18 @@ def _summarize_coord_multiindex(coord, col_width, marker):


def _summarize_coord_levels(coord, col_width, marker="-"):
if len(coord) > 100 and col_width < len(coord):
n_values = col_width
indices = list(range(0, n_values)) + list(range(-n_values, 0))
subset = coord[indices]
else:
subset = coord

return "\n".join(
summarize_variable(
lname, coord.get_level_variable(lname), col_width, marker=marker
lname, subset.get_level_variable(lname), col_width, marker=marker
)
for lname in coord.level_names
for lname in subset.level_names
)


Expand Down