diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 4f3380084e3..5ecd18827a2 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -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, @@ -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: @@ -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)) diff --git a/xarray/core/options.py b/xarray/core/options.py index a96cce08b24..865d0755a01 100644 --- a/xarray/core/options.py +++ b/xarray/core/options.py @@ -23,6 +23,7 @@ "display_expand_data_vars", "display_expand_data", "display_expand_indexes", + "display_default_indexes", "enable_cftimeindex", "file_cache_maxsize", "keep_attrs", @@ -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] @@ -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", @@ -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"],