Feature Request: First-class representation of nested attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Is your feature request related to a problem?
Formats such as Zarr store group attributes in JSON (e.g. .zattrs), so attributes can be deeply nested (objects and arrays). The current xarray APIs and built-in representations (e.g. repr(), HTML repr in Jupyter) typically expose attributes in a flat or single-level way. That makes it hard to inspect or document complex metadata in the IDE or in notebooks. Users either see a flattened view, truncated output, or have to manually traverse raw attribute dicts instead of seeing the structure xarray actually has at hand.
Xarray current HTML representation (only top-level attributes are shown, with full content):
Describe the solution you'd like
First-class support for nested attributes in xarray’s APIs and/or representations, for example:
- Repr / HTML repr: Optionally render nested attributes as an expandable/collapsible tree (or at least with clear indentation/structure) instead of a single-level or flattened dump, so users can see the full hierarchy in Jupyter and other environments that rely on xarray’s built-in repr.
The goal is that opening a dataset with rich nested metadata (e.g. from Zarr) feels natural in xarray: the repr and APIs should reflect that nesting rather than flattening or hiding it.
Describe alternatives you've considered
- Manual traversal: Users can already walk
ds.attrs(or group attrs) and pretty-print themselves. This doesn’t improve the default experience in Jupyter or the consistency of tooling. - Downstream-only handling: Some tools (e.g. Scientific Data Viewer) can render nested attributes in a tree view on the viewer side. That helps when using those tools but doesn’t improve the experience for users who only use xarray’s built-in repr or other consumers that follow xarray’s representation.
- Leaving attributes as “opaque” dicts: Keeps implementation simple but under-serves users and formats (like Zarr) where nested metadata is the norm.
Example: Scientific Data Viewer nested representation of nested attributes with collapsible sections:
Additional context
- This would benefit anyone opening Zarr (or similar) datasets with rich
.zattrs-style metadata in Jupyter or scripts. - Downstream projects (e.g. Scientific Data Viewer) could align their UIs with xarray’s representation for consistency when the same dataset is opened in xarray and in other tools.
- Reference: Scientific Data Viewer – xarray and nested attributes (doc that motivated this request).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing xarray's repr() and HTML repr paths in Jupyter, then inspect how ds.attrs and group attributes are currently displayed. Define the representation scope before implementation; done should make deeply nested objects and arrays visibly structured, with any requested expandable behavior covered by representation tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100