xarray-contrib / datatree

WIP implementation of a tree-like hierarchical data structure for xarray.
https://xarray-datatree.readthedocs.io
Apache License 2.0
161 stars 43 forks source link

Collapse by default the "Attributes" section in rich display #332

Open eschalkargans opened 1 month ago

eschalkargans commented 1 month ago

Motive

When opening a Zarr file with many attributes, the Attributes section is unwrapped by default. It can make the notebook rendering crash in VSCode.

It would be preferable to collapse the Attributes section by default, as it is already done for the Groups section, for instance.

Screenshot from 2024-05-16 17-20-39

Suggestions

1) Always collapse and h ave a global option to control the default behaviour (collapsed or unwrapped by default)


2) Print "up to N" attribute keys (like for pandas dataframe, when the row count is high, only the heading and ending rows are displayed with an ellipsis in the middle. For attribute values, also use Ellipsis for long values. The current issue seems that only the N (amount of keys) is used to collapse or unwrap by default:

N=10

Screenshot from 2024-05-16 17-30-32

N=9

Screenshot from 2024-05-16 17-30-56

Conclusion: N is not sufficient to determine the default state of the Attributes section (collapsed or closed). The attributes length also must be shortened. This is not trivial as the value can be a string, a list, a dict... Evaluating the length of the string representation of the value is probably a way to measure its length.

Screenshot from 2024-05-16 17-34-29


3) Since attributes are JSON, they could also be displayed in an interactive tree (like the Groups section, where the nodes can be opened and closed). It would be the best to be able to navigate the attributes.