pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.57k stars 1.07k forks source link

Fancy reprs #8171

Open benbovy opened 1 year ago

benbovy commented 1 year ago

What is your issue?

In Xarray we already have the plain-text and html reprs, which is great.

Recently, I've tried anywidget and I think that it has potential to overcome some of the limitations of the current repr and possibly go well beyond it.

The main advantages of anywidget:

I don't think we should replace the current html repr (it is still useful to have a basic, pure HTML/CSS version), but having a new widget could improve some aspects like not including the whole CSS each time an object repr is displayed, removing some HTML/CSS hacks... and actually has much more potential since we would have the whole javascript ecosystem at our fingertips (quick plots, etc.). Also bi-directional communication with Python is possible.

I'm opening this issue to brainstorm about what would be nice to have in widget-based Xarray reprs:

cc @pydata/xarray

shoyer commented 1 year ago

This sounds exciting! Assuming the minimal dependencies are not too painful to add, this sounds like a nice way to add optional dynamic effects.

Do you understand how they solve JavaScript sandboxing issue? Or maybe that only works on particular notebook implementations?

TomNicholas commented 1 year ago

Great idea. One thing this could be useful for is interactively visualizing the structure of DataTree objects. https://github.com/xarray-contrib/datatree/issues/207

benbovy commented 1 year ago

Perhaps this would better be implemented in a third party package that xarray would optionally depend on, and fallback to the pure html/css repr if it is not installed.

Anywidget relies on standard ES modules, which I think makes it more easily front-end agnostic.

benbovy commented 1 year ago

@TomNicholas yes we have just talked about that with @keewis !

benbovy commented 1 year ago

I started experimenting with this in https://github.com/benbovy/xarray-fancy-repr

benbovy commented 1 year ago

started experimenting with this in https://github.com/benbovy/xarray-fancy-repr

First release is now available on PyPI: pip install xarray-fancy-repr !

It has reprs for Dataset, DataArray, Coordinates and Variable (copied from the Xarray html reprs). For now it also implements a basic search tool to filter variables and attributes (by name, dimension and/or attributes). I opened a few issues for other ideas.

xarray-fancy-repr2

dcherian commented 1 year ago

Now that's pretty cool!

rabernat commented 1 year ago

One really cool direction to take this would be to add automatic visualization of the data variables. Like, rather than just showing the dask repr or a bunch of numbers, could we make an interactive plot appear?

benbovy commented 1 year ago

One really cool direction to take this would be to add automatic visualization of the data variables. Like, rather than just showing the dask repr or a bunch of numbers, could we make an interactive plot appear?

Yes there is room for adding another few icons next to each variable inline repr for that.

max-sixty commented 1 year ago

Very cool!