question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

constructing nested inline reprs

See original GitHub issue

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 use format_array_flat if the magnitude is a ndarray.

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_flat should probably just apply to magnitude being an ndarray.

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?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jthielencommented, Aug 20, 2020

I brought this up at the meeting, and if I remember correctly, the recommendation was to take a step back and solve nested duck arrays in general (e.g. by writing a design doc – a NEP?). Correct me if I’m wrong, @shoyer, but I think the hope was that after that it would be easier to design nested reprs.

Sounds good! Would it make sense to discuss that over on https://github.com/dask/dask/issues/5329, the pre-existing issue for this larger problem of nested duck array reprs/meta?

Also, since _repr_inline_ is already implemented, I’d still like to see a basic version of https://github.com/xarray-contrib/pint-xarray/pull/22 merged in, so at least we have good results in the “easy” case of xarray > Pint > NumPy.

0reactions
keewiscommented, Sep 14, 2020

see also dask/dask#6637

Read more comments on GitHub >

github_iconTop Results From Across the Web

reprs of nested duck arrays · Issue #6637 · dask/dask · GitHub
construct a repr that includes the metadata from all levels of nesting? Simply including the repr of the wrapped array usually results in...
Read more >
nested-inlines and django-suit - python - Stack Overflow
Nested inlines is something that isn't supported across the board, as it's not really part of the Django forms system (which is what...
Read more >
9025 (Nested Inline Support in Admin) - Django's bug tracker
I attached a patch to enable nested inlines with a depth level of 3 on the change_view of ModelAdmin depth level of 3...
Read more >
Use nested and repeated fields | BigQuery - Google Cloud
The recommended way to denormalize data in BigQuery is to use nested and repeated fields. ... Nesting data lets you represent foreign entities...
Read more >
CSS Nesting Module - W3C
There are two closely-related syntaxes for creating nested style ... and (min-inline-size > 1024px) { .foo { max-inline-size: 1024px; } } */.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found