API change proposal for ipywidget's interact

71 views
Skip to first unread message

Sylvain Corlay

unread,
Jan 12, 2016, 2:34:59 PM1/12/16
to jup...@googlegroups.com

Hello,

Brian and Fernando advised that I send a message to the mailing list regarding this change.

Both Jupyter and Sage's interactive widget libraries provide an `@interact` function decorator which introspects the arguments of the function to create a simple GUI for interacting with it. Sage and Jupyter APIs for `@interact` are very similar, but differ in how they use abbreviations.

Abbreviations are a way to map default values to a type of widget. For example in both cases the following case

    @interact
    def foo(x=(0, 100, 2)):
        print(x)

both Jupyter and Sage will create a slider with from 0 to 100 with a step of 2. 

In fact, Jupyter and Sage's uses of abbreviations differ in the following way:

  • With Sage: When passing a list of items, the generated widget is always a selection widget.
    When passing a tuple of 2 or 3 numerical values, a slider is created and the values are interpreted as(min, max[, step])

  • With Jupyter, a selection widget is only used when passing sequence (tuple or list) of strings. 
    A slider is used when passing a sequence of 2 or 3 numerical values, and these values are interpreted as (min, max[, step]).

I personally prefer the API of Sage over the one of Jupyter. In my opinion, the type mapping `tuple -> slider` and `list -> selection` is simpler to reason about than a behavior that depends on the type of the items in a sequence.

Obviously, since the two APIs are not compatible, we cannot support them both at the same time. If we decide that we eventually want to adopt the Sage approach, I proposed a way to achieve a smooth transition in the pull request https://github.com/ipython/ipywidgets/pull/288The proposed change is backward compatible with the Jupyter approach and introduces deprecation warnings when using a list of 2/3 numerical values to create a slider or if the user creates a selection widget with a tuple of strings.

The question to the list is: what do you think of adopting the same type abbreviations as Sage in Jupyter's interact?

Thanks,

Sylvain 

Matthias Bussonnier

unread,
Jan 12, 2016, 2:57:21 PM1/12/16
to Project Jupyter, IPython developers list
Hi all, 

This was sent on jupyter ML, but as it’s a Python-kernel only change, it might be good to CC IPython-dev, 
which I do there. 

Please keep a single thread, preferably on Jupyter groups as the thread was started there. 

Thanks
-- 
M


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/CAK%3DPhk6NfcwyaCagm%3DRLBVTbh1oZ0YdYr8ncM1ZLH-JV%3Dz_gYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages