constructing nested inline reprs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
While implementing the new _repr_inline_ in xarray-contrib/pint-xarray#22, I realized that I designed that method with a single level of nesting in mind, e.g. xarray(pint(x)) or xarray(dask(x)).
From that PR:
@keewis
thinking about this some more, this doesn't work for anything other than
numpy.ndarrayobjects. For now I guess we could use the magnitude's_repr_inline_(falling back to__repr__if that doesn't exist) and only useformat_array_flatif the magnitude is andarray.However, as we nest deeper (e.g.
xarray(pint(uncertainties(dask(sparse(cupy)))))– for argument's sake, let's assume that this actually makes sense) this might break or become really complicated. Does anyone have any ideas how to deal with that?If I'm simply missing something we have that discussion here, otherwise I guess we should open a issue on
xarray's issue tracker.
@jthielen
Yes, I agree that
format_array_flatshould probably just apply to magnitude being anndarray.I think a cascading series of
_repr_inline_should work for nested arrays, so long as* the metadata of the higher nested objects is considered the priority (if not, then we're back to a fully managed solution to the likes of [dask/dask#5329](https://github.com/dask/dask/issues/5329)) * small max lengths are handled gracefully (i.e., a minimum where it is just like `Dask.Array(...)`, then `...`, then nothing) * we're okay with the lowest arrays in large nesting chains not having any information show up in the inline repr (situation where there is not enough characters to even describe the full nesting has to be accounted for somehow) * it can be adopted without too much complaint across the ecosystemAssuming all this, then each layer of the nesting will reduce the max length of the inline repr string available to the layers below it, until a layer reaches a reasonable minimum where it "gives up". At least that's the natural design that I inferred from the simple
_repr_inline_(max_width)API.All that being said, it might still be good to bring up on xarray's end since this is a more general issue with inline reprs of nested duck arrays, with nothing pint-specific other than it being the motivating use-case.
How should we deal with this?
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 with the _repr_inline_(max_width) API described in the issue and review the nested examples involving pint, dask, sparse, cupy, and uncertainties. Investigate how nested duck arrays should allocate inline-representation space and handle small maximum widths. Done means there is an agreed general approach for nested inline reprs rather than a pint-specific workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100