Skip to content

speed up import and load hvplot lazily #1539

Description

@Sevans711

Proposed new feature or change:

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:
Image
(with first cell taking ~1.7s, second cell ~0.1s)

New behavior:
Image
(first cell faster, second cell slower. Rerunning the second cell takes ~0.1s and does not produce the gray bars.)

Metadata

Metadata

Assignees

Labels

new featureNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
🏗 In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions