Speed up import and load hvplot lazily#1541
Conversation
Small change which reduces time for "import uxarray" on my machine from 1.7 seconds to 0.7 seconds. Also avoids the strange gray bars in Jupyter until actually making a plot for the first time, instead of immediately when importing uxarray. (The bars apparently came from "import hvplot.pandas" and "import hvplot.xarray"). See also: UXARRAY#1260 This also means hvplot import is lazy, which means we should be able to move hvplot to be an optional dependency instead of a requirement. See also: UXARRAY#1224
Co-authored-by: Rajeev Jain <rajeeja@gmail.com>
|
We might want to delay merging; I just discovered that import hvplot.pandas and import hvplot.xarray always change the backend to bokeh. Thus, with these changes, lazily importing hvplot means the first plot you make from uxarray will be forced into having bokeh backend, regardless of the backend you tried to set originally. I am creating a bug report on hvplot repository now about this. |
|
I'm very confused about why my latest changes would cause those crashes… I only added an additional Any guesses on how my changes might have led to this? A quick attempt to reproduce it didn't lead me anywhere either, e.g.: uxds = ux.tutorial.open_dataset("outCSne30-vortex")
hasattr(uxds, 'plot')gives True. I can chase this down more if I should prioritize it, but wanted to check in first in case you have a guess already. Seems like it might be related to the |
…on test The lazy hvplot import must not clobber the user's plotting backend. import hvplot.pandas/xarray always switch the backend to bokeh (hvplot #1735). The previous workaround referenced hvplot.Store, which does not exist, so the save/restore silently no-opped and the backend was still forced to bokeh. Use holoviews.Store (the real location of current_backend) to save and restore the backend around the lazy import, and add test_lazy_hvplot_import_preserves_backend which reproduces the notebook flow (set matplotlib -> trigger lazy import -> assert backend unchanged) in a fresh subprocess.
Closes #1539
Overview
Speeds up
import uxarrayfrom ~1.7 seconds to ~0.7 seconds, by makinghvplot.pandasandhvplot.xarrayimports lazy, i.e. only import them when actually initializing a PlotAccessor object for the first time.PR Checklist
General
Testing