Skip to content

DEPS: use importlib for backend discovery #41815 #42410

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

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/source/getting_started/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ Visualization
========================= ================== =============================================================
Dependency Minimum Version Notes
========================= ================== =============================================================
setuptools 38.6.0 Utils for entry points of plotting backend
matplotlib 3.3.2 Plotting library
Jinja2 2.11 Conditional formatting with DataFrame.style
tabulate 0.8.7 Printing in Markdown-friendly format (see `tabulate`_)
Expand Down
2 changes: 0 additions & 2 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ If installed, we now require:
+-----------------+-----------------+----------+---------+
| mypy (dev) | 0.910 | | X |
+-----------------+-----------------+----------+---------+
| setuptools | 38.6.0 | | |
+-----------------+-----------------+----------+---------+

For `optional libraries <https://pandas.pydata.org/docs/getting_started/install.html>`_ the general recommendation is to use the latest version.
The following table lists the lowest version per library that is currently being tested throughout the development of pandas.
Expand Down
14 changes: 8 additions & 6 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ def _load_backend(backend: str) -> types.ModuleType:
types.ModuleType
The imported backend.
"""
import pkg_resources
from importlib.metadata import entry_points

if backend == "matplotlib":
# Because matplotlib is an optional dependency and first-party backend,
Expand All @@ -1759,11 +1759,13 @@ def _load_backend(backend: str) -> types.ModuleType:

found_backend = False

for entry_point in pkg_resources.iter_entry_points("pandas_plotting_backends"):
found_backend = entry_point.name == backend
if found_backend:
module = entry_point.load()
break
eps = entry_points()
if "pandas_plotting_backends" in eps:
for entry_point in eps["pandas_plotting_backends"]:
found_backend = entry_point.name == backend
if found_backend:
module = entry_point.load()
break

if not found_backend:
# Fall back to unregistered, module name approach.
Expand Down