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.ndarray
objects. 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_flat
if 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.
Yes, I agree that
format_array_flat
should 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 ecosystem
Assuming 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?