Skip to content

Commit

Permalink
skip default indexes by default
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Jul 26, 2022
1 parent 7c7a5f0 commit a5916c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
38 changes: 32 additions & 6 deletions xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,18 @@ def summarize_index(
return pretty_print(f" {name} ", col_width) + f"{repr(index)}"


def nondefault_indexes(indexes):
from .indexes import PandasIndex, PandasMultiIndex

default_indexes = (PandasIndex, PandasMultiIndex)

return {
key: index
for key, index in indexes.items()
if not isinstance(index, default_indexes)
}


def indexes_repr(indexes, col_width=None, max_rows=None):
return _mapping_repr(
indexes,
Expand Down Expand Up @@ -598,9 +610,17 @@ def array_repr(arr):
if unindexed_dims_str:
summary.append(unindexed_dims_str)

if arr.xindexes:
display_default_indexes = _get_boolean_with_default(
"display_default_indexes", False
)
if display_default_indexes:
xindexes = arr.xindexes
else:
xindexes = nondefault_indexes(arr.xindexes)

if xindexes:
summary.append(
indexes_repr(arr.xindexes, col_width=col_width, max_rows=max_rows)
indexes_repr(xindexes, col_width=col_width, max_rows=max_rows)
)

if arr.attrs:
Expand All @@ -627,10 +647,16 @@ def dataset_repr(ds):
summary.append(unindexed_dims_str)

summary.append(data_vars_repr(ds.data_vars, col_width=col_width, max_rows=max_rows))
if ds.xindexes:
summary.append(
indexes_repr(ds.xindexes, col_width=col_width, max_rows=max_rows)
)

display_default_indexes = _get_boolean_with_default(
"display_default_indexes", False
)
if display_default_indexes:
xindexes = ds.xindexes
else:
xindexes = nondefault_indexes(ds.xindexes)
if xindexes:
summary.append(indexes_repr(xindexes, col_width=col_width, max_rows=max_rows))

if ds.attrs:
summary.append(attrs_repr(ds.attrs, max_rows=max_rows))
Expand Down
4 changes: 4 additions & 0 deletions xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"display_expand_data_vars",
"display_expand_data",
"display_expand_indexes",
"display_default_indexes",
"enable_cftimeindex",
"file_cache_maxsize",
"keep_attrs",
Expand All @@ -44,6 +45,7 @@ class T_Options(TypedDict):
display_expand_data_vars: Literal["default", True, False]
display_expand_data: Literal["default", True, False]
display_expand_indexes: Literal["default", True, False]
display_default_indexes: Literal["default", True, False]
enable_cftimeindex: bool
file_cache_maxsize: int
keep_attrs: Literal["default", True, False]
Expand All @@ -65,6 +67,7 @@ class T_Options(TypedDict):
"display_expand_data_vars": "default",
"display_expand_data": "default",
"display_expand_indexes": "default",
"display_default_indexes": False,
"enable_cftimeindex": True,
"file_cache_maxsize": 128,
"keep_attrs": "default",
Expand Down Expand Up @@ -92,6 +95,7 @@ def _positive_integer(value: int) -> bool:
"display_expand_data_vars": lambda choice: choice in [True, False, "default"],
"display_expand_data": lambda choice: choice in [True, False, "default"],
"display_expand_indexes": lambda choice: choice in [True, False, "default"],
"display_default_indexes": lambda choice: choice in [True, False, "default"],
"enable_cftimeindex": lambda value: isinstance(value, bool),
"file_cache_maxsize": _positive_integer,
"keep_attrs": lambda choice: choice in [True, False, "default"],
Expand Down

0 comments on commit a5916c3

Please sign in to comment.