-
-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow options for non-enabled backends #6196
Conversation
This was tested in jupyterlab with: # Cell 1
import holoviews as hv
hv.extension('bokeh')
hv.extension('matplotlib')
x = hv.Curve([0,1])
# Cell 2
y = x.options(color='green', backend='matplotlib').options(color='red', backend='bokeh')
y
# Cell 3
x.options(color='red', backend='bokeh').options(color='green', backend='matplotlib')
# Cell 4
# Switch to the other backend and re-display an already-built plot. As long as the backend was enabled (even if not the one in use), this works
hv.extension('bokeh')
y Note that the code in the original issue #3587 still fails, I'll see if I can fix that as well: import holoviews as hv
from holoviews import opts
hv.extension('matplotlib')
hv.Curve([1,2])\
.opts(opts.Curve(backend='matplotlib', fig_size=400)) \
.opts(opts.Curve(backend='bokeh', height=300, width=400)) |
c065c40
to
8fccfdd
Compare
Updated PR with fixes for the original issue as well |
This seems like a fabulous idea if we can make it work. |
491d4ca
to
d141366
Compare
d141366
to
3b05ebe
Compare
Updated with PR rebased on |
+1 for this feature when you want to delay the choice of backend to later stages for different contexts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks right to me, but the proof is really in the pudding. A few things we need to check here:
- Will validation of options still work after the backend is imported (I think so)
- What happens to invalid options that were set when validation wasn't available
- How do we test this? Unloading a backend is difficult, so we may have to test it with a fake custom backend.
From my experiment, if you set an option for a backend that is not imported yet, the option is just discarded, e.g. if you use
They are not set, they are discarded. If you enable the backend in question later on, the plot will just have the default styling, none of your previous options will have been saved. Maybe it would be possible to save the unvalidated options, but I'm not sure how useful that would be. Our jupyter use-case is like that: import holoviews as hv
hv.extension('bokeh')
# the_library_func() returns a plot styled for all backends,
# so the user can choose any backend and don't need to
# import backends they won't use.
plot = the_library_func()
plot In that scenario, it's not hard for the user to just pick a backend before calling any library code.
I was also thinking it would be a problem. As it stands I see two solutions:
I'd say that 2. is only reasonable if it saves a lot of re-import of other modules that can be kept as they are. Otherwise, 1. is much likely to work without troubles. I tried 2. with |
For checking, I would propose having the test as strings and then running the command with a subprocess, like what I have done in this test. |
I would just register a new backend and test with that. We already have other tests doing that.
I would say that I would expect them to persist but for them to be validated and perhaps raise warnings if it detects invalid options. |
What area should host that feature ? I'm not familiar with the rendering infrastructure, so it's easy to discard what cannot be validated, and it would be rather easy to hang on to the unexpanded options, but I have no idea where these options should be actually processed |
BREAKING CHANGE Remove the matplotlib options for holoviews plot as that currently requires the matplotlib backend to be enabled just to validate the options. If and when this gets merged, this commit can be reverted: holoviz/holoviews#6196
BREAKING CHANGE Remove the matplotlib options for holoviews plot as that currently requires the matplotlib backend to be enabled just to validate the options. If and when this gets merged, this commit can be reverted: holoviz/holoviews#6196
I'm okay with merging this as is. We'll be doing some work on making the options system more easily testable and we will follow up by allowing the options to be transferred when the backend is eventually imported. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6196 +/- ##
==========================================
- Coverage 88.39% 88.38% -0.01%
==========================================
Files 323 323
Lines 67609 67613 +4
==========================================
+ Hits 59761 59763 +2
- Misses 7848 7850 +2 ☔ View full report in Codecov by Sentry. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
An attempt at fixing: #3587
This allows passing options for backends that have not been enabled, so that it becomes possible for a library to return plots that have been styled for multiple backends, leaving the choice of what backend to use to the end user.
This change seems to work, but options passed to non-enabled backends are discarded. If the user subsequently changes the backend and tries to plot the object, the styling for that backend is just the default. However, if multiple backends are already enabled when the
.options()
is called, everything works as expected.Note that I'm not very familiar with the internals of the Options system of holoviews, so this PR was hacked together until it worked, rather than being really planned by knowing how it should work.