home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 576424752

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/3709#issuecomment-576424752 https://api.github.com/repos/pydata/xarray/issues/3709 576424752 MDEyOklzc3VlQ29tbWVudDU3NjQyNDc1Mg== 35968931 2020-01-20T20:43:29Z 2020-01-20T20:43:29Z MEMBER

Difficulties with method chaining

Arbitraily long method chaining would be great, i.e. python da.interactive.isel(time=10).mean('time').plot() but I think it will be considerably more complicated.

The problem is that the way the ipywidgets.interactive() function works means that each time a widget value is altered (e.g. a slider dragged to a new position), then the function wrapped by interactive must be recomputed. For single functions that's fine, but for method chaining it means the final .plot() method has to know about all the previous methods back up to the .interactive input.

I've found a way to get around this, but I'd like some feedback on the approach because it might be needlessly complicated.

I would like to do it by subclassing to create an InteractiveDataArray, which you could create with an interactive accessor method like python ida = da.interactive.isel(time=10) This class would store the widgets and decorate it's inherited methods to either propagate them (e.g. through ida.reduce()) or display them (e.g. after ida.plot()). It would define the _ipython_display_() method so that calling display(ida) revealed the widgets.

To allow for the final method to recompute all the previous steps, each inherited computation method would be wrapped by a decorator which records the function used and it's arguments. That way the final method (which really you know will either be .plot(), or __print__()) can revaluate it's whole history when the slider tells it to recompute.

I've got a very rough example of this working, but as I said there might be a much easier way...

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  552500673
Powered by Datasette · Queries took 2.719ms · About: xarray-datasette