ENH: load plotting entry point only when necessary · Issue #41492 · pandas-dev/pandas (original) (raw)
Is your feature request related to a problem?
All installed plotting backends are loaded on the first DataFrame.plot
call of a kernel, resulting in a potentially unnecessary module loading time, although quite minor, as it's only done on the very first call. However, if the number of pluggable backends out there increases in the future, this could become a real nuisance for users who installed many of them in their environment.
Describe the solution you'd like
In pandas.plotting._core._find_backend
, entry_point.load()
should only be done for the solicited backend. This is straightforward to implement, I could write the PR myself.
API breaking implications
None as far as I know.
Describe alternatives you've considered
Additional context
With just hvPlot installed, the following
for entry_point in pkg_resources.iter_entry_points("pandas_plotting_backends"): if entry_point.name == "matplotlib": # matplotlib is an optional dependency. When # missing, this would raise. continue entry_point.load()
takes ~2s , while
for entry_point in pkg_resources.iter_entry_points("pandas_plotting_backends"): if entry_point.name == "matplotlib": # matplotlib is an optional dependency. When # missing, this would raise. continue
takes a few ms. As one would expect, entry_point.load()
is the slowest part to execute by far.