From ec8258907be9fba8fb6ecdecc3e60d02c4b734dc Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 6 Jul 2021 10:49:42 -0500 Subject: [PATCH 1/2] DEPS: use importlib for backend discovery #41815 --- doc/source/getting_started/install.rst | 1 - doc/source/whatsnew/v1.4.0.rst | 2 -- pandas/plotting/_core.py | 5 +++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index 6c245a0668394..e5c6a69ce0e30 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -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`_) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 764a50e13586a..2daea368af3b6 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -82,8 +82,6 @@ If installed, we now require: +-----------------+-----------------+----------+---------+ | mypy (dev) | 0.910 | | X | +-----------------+-----------------+----------+---------+ -| setuptools | 38.6.0 | | | -+-----------------+-----------------+----------+---------+ For `optional libraries `_ 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. diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 302d5ede0ae86..8cc42ea33c312 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -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, @@ -1759,7 +1759,8 @@ def _load_backend(backend: str) -> types.ModuleType: found_backend = False - for entry_point in pkg_resources.iter_entry_points("pandas_plotting_backends"): + eps = entry_points() + for entry_point in eps.get("pandas_plotting_backends"): found_backend = entry_point.name == backend if found_backend: module = entry_point.load() From f8d836798b7981e34c3eb3a458911081f67449d8 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 6 Jul 2021 12:36:51 -0500 Subject: [PATCH 2/2] fix mypy error --- pandas/plotting/_core.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 8cc42ea33c312..268d336325db4 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1760,11 +1760,12 @@ def _load_backend(backend: str) -> types.ModuleType: found_backend = False eps = entry_points() - for entry_point in eps.get("pandas_plotting_backends"): - found_backend = entry_point.name == backend - if found_backend: - module = entry_point.load() - break + 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.