Skip to content

Commit a5916c3

Browse files
committed
skip default indexes by default
1 parent 7c7a5f0 commit a5916c3

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

xarray/core/formatting.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,18 @@ def summarize_index(
414414
return pretty_print(f" {name} ", col_width) + f"{repr(index)}"
415415

416416

417+
def nondefault_indexes(indexes):
418+
from .indexes import PandasIndex, PandasMultiIndex
419+
420+
default_indexes = (PandasIndex, PandasMultiIndex)
421+
422+
return {
423+
key: index
424+
for key, index in indexes.items()
425+
if not isinstance(index, default_indexes)
426+
}
427+
428+
417429
def indexes_repr(indexes, col_width=None, max_rows=None):
418430
return _mapping_repr(
419431
indexes,
@@ -598,9 +610,17 @@ def array_repr(arr):
598610
if unindexed_dims_str:
599611
summary.append(unindexed_dims_str)
600612

601-
if arr.xindexes:
613+
display_default_indexes = _get_boolean_with_default(
614+
"display_default_indexes", False
615+
)
616+
if display_default_indexes:
617+
xindexes = arr.xindexes
618+
else:
619+
xindexes = nondefault_indexes(arr.xindexes)
620+
621+
if xindexes:
602622
summary.append(
603-
indexes_repr(arr.xindexes, col_width=col_width, max_rows=max_rows)
623+
indexes_repr(xindexes, col_width=col_width, max_rows=max_rows)
604624
)
605625

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

629649
summary.append(data_vars_repr(ds.data_vars, col_width=col_width, max_rows=max_rows))
630-
if ds.xindexes:
631-
summary.append(
632-
indexes_repr(ds.xindexes, col_width=col_width, max_rows=max_rows)
633-
)
650+
651+
display_default_indexes = _get_boolean_with_default(
652+
"display_default_indexes", False
653+
)
654+
if display_default_indexes:
655+
xindexes = ds.xindexes
656+
else:
657+
xindexes = nondefault_indexes(ds.xindexes)
658+
if xindexes:
659+
summary.append(indexes_repr(xindexes, col_width=col_width, max_rows=max_rows))
634660

635661
if ds.attrs:
636662
summary.append(attrs_repr(ds.attrs, max_rows=max_rows))

xarray/core/options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"display_expand_data_vars",
2424
"display_expand_data",
2525
"display_expand_indexes",
26+
"display_default_indexes",
2627
"enable_cftimeindex",
2728
"file_cache_maxsize",
2829
"keep_attrs",
@@ -44,6 +45,7 @@ class T_Options(TypedDict):
4445
display_expand_data_vars: Literal["default", True, False]
4546
display_expand_data: Literal["default", True, False]
4647
display_expand_indexes: Literal["default", True, False]
48+
display_default_indexes: Literal["default", True, False]
4749
enable_cftimeindex: bool
4850
file_cache_maxsize: int
4951
keep_attrs: Literal["default", True, False]
@@ -65,6 +67,7 @@ class T_Options(TypedDict):
6567
"display_expand_data_vars": "default",
6668
"display_expand_data": "default",
6769
"display_expand_indexes": "default",
70+
"display_default_indexes": False,
6871
"enable_cftimeindex": True,
6972
"file_cache_maxsize": 128,
7073
"keep_attrs": "default",
@@ -92,6 +95,7 @@ def _positive_integer(value: int) -> bool:
9295
"display_expand_data_vars": lambda choice: choice in [True, False, "default"],
9396
"display_expand_data": lambda choice: choice in [True, False, "default"],
9497
"display_expand_indexes": lambda choice: choice in [True, False, "default"],
98+
"display_default_indexes": lambda choice: choice in [True, False, "default"],
9599
"enable_cftimeindex": lambda value: isinstance(value, bool),
96100
"file_cache_maxsize": _positive_integer,
97101
"keep_attrs": lambda choice: choice in [True, False, "default"],

0 commit comments

Comments
 (0)