You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a tiny change we can make to speed up import uxarray. On my machine the import takes 1.7 seconds before this change, and 0.7 seconds after it. See also: #1260
The change is to import hvplot.pandas and hvplot.xarray lazily in uxarray.plot.accessor.py, i.e. only import them the first time any of the PlotAccessor objects' __init__ methods actually get called. These lazy imports should also make it easier to move hvplot to be an optional dependency instead of a required dependency later (see #1224).
This also delays when these strange gray bars appear in Jupyter (they are apparently caused by import hvplot.pandas and hvplot.xarray). Now they only appear the first time you plot something, instead of immediately upon importing uxarray for the first time.
Previous behavior:
(with first cell taking ~1.7s, second cell ~0.1s)
New behavior:
(first cell faster, second cell slower. Rerunning the second cell takes ~0.1s and does not produce the gray bars.)
Thanks @Sevans711 — I've been meaning to look into this too, as I've found the import times to be pretty high again. hvplot is the biggest single chunk (~0.8s, ~40%), so this is the right core fix, and it also unblocks making hvplot optional (#1224).
Some history: #1265 (with @philipc2) did an earlier import-time pass but deliberately left hvplot at module top, so your change picks up where that left off. A couple of those wins have since regressed too — cartopy got re-added at module top by later viz features (#1271, #1454), and re-deferring it (plus holoviews/pyproj) is worth another ~0.5s. Locally I see import uxarray drop from ~2.0s to ~1.0s with all of it.
One suggestion so it doesn't rot again: a small test asserting cartopy/hvplot/holoviews aren't in sys.modules after import uxarray would have caught those regressions.
@rajeeja it looks like the test fails in #1541, but it is failing before even reaching the uxarray import. The code looks like this:
importsysdeftest_hvplot_optional():
"""Test that hvplot is actually optional and not imported by default. (hvplot in particular is "slow" to import (~1s to import hvplot.pandas), so it should not be imported until actually plotting something.) """assert"hvplot"notinsys.modules# else, it's a test environment issue..?importuxarrayasuxassert"hvplot"notinsys.modules
and the failure is at the first assert statement, before the import uxarray as ux line. When I run pytest locally, with just this file (pytest test/test_dependencies.py) it passes, but when I run it locally for all tests (pytest test/) it crashes. Maybe it's related to pytest fixtures? I can try running this down a bit more but also wanted to check, do you have any guesses here?
Activity
rajeeja commentedon Jun 30, 2026
Thanks @Sevans711 — I've been meaning to look into this too, as I've found the import times to be pretty high again.
hvplotis the biggest single chunk (~0.8s, ~40%), so this is the right core fix, and it also unblocks making hvplot optional (#1224).Some history: #1265 (with @philipc2) did an earlier import-time pass but deliberately left hvplot at module top, so your change picks up where that left off. A couple of those wins have since regressed too —
cartopygot re-added at module top by later viz features (#1271, #1454), and re-deferring it (plusholoviews/pyproj) is worth another ~0.5s. Locally I seeimport uxarraydrop from ~2.0s to ~1.0s with all of it.One suggestion so it doesn't rot again: a small test asserting
cartopy/hvplot/holoviewsaren't insys.modulesafterimport uxarraywould have caught those regressions.test hvplot import is lazy
Sevans711 commentedon Jun 30, 2026
@rajeeja it looks like the test fails in #1541, but it is failing before even reaching the uxarray import. The code looks like this:
and the failure is at the first assert statement, before the
import uxarray as uxline. When I run pytest locally, with just this file (pytest test/test_dependencies.py) it passes, but when I run it locally for all tests (pytest test/) it crashes. Maybe it's related to pytest fixtures? I can try running this down a bit more but also wanted to check, do you have any guesses here?