-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
API: Add entrypoint for plotting #27488
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
Changes from 8 commits
853bd66
3dc341a
d84b672
61b5aac
f81800d
60f2cce
466b96c
9c56054
9a2f283
dab6ac3
69c3069
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import sys | ||
import types | ||
|
||
import pkg_resources | ||
import pytest | ||
|
||
import pandas.util._test_decorators as td | ||
|
||
import pandas | ||
|
||
|
||
|
@@ -36,3 +42,44 @@ def test_backend_is_correct(monkeypatch): | |
pandas.set_option("plotting.backend", "matplotlib") | ||
except ImportError: | ||
pass | ||
|
||
|
||
@td.skip_if_no_mpl | ||
def test_register_entrypoint(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is failing for me locally There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you seeing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I'm guessing it's a You'll need to re-run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep that does fix it, thanks |
||
mod = types.ModuleType("my_backend") | ||
mod.plot = lambda *args, **kwargs: 1 | ||
|
||
backends = pkg_resources.get_entry_map("pandas") | ||
my_entrypoint = pkg_resources.EntryPoint( | ||
"pandas_plotting_backend", | ||
mod.__name__, | ||
dist=pkg_resources.get_distribution("pandas"), | ||
) | ||
backends["pandas_plotting_backends"]["my_backend"] = my_entrypoint | ||
# TODO: the docs recommend importlib.util.module_from_spec. But this works for now. | ||
sys.modules["my_backend"] = mod | ||
|
||
result = pandas.plotting._core._get_plot_backend("my_backend") | ||
assert result is mod | ||
|
||
# TODO: https://github.com/pandas-dev/pandas/issues/27517 | ||
# Remove the td.skip_if_no_mpl | ||
with pandas.option_context("plotting.backend", "my_backend"): | ||
result = pandas.plotting._core._get_plot_backend() | ||
|
||
assert result is mod | ||
|
||
|
||
def test_register_import(): | ||
mod = types.ModuleType("my_backend2") | ||
mod.plot = lambda *args, **kwargs: 1 | ||
sys.modules["my_backend2"] = mod | ||
|
||
result = pandas.plotting._core._get_plot_backend("my_backend2") | ||
assert result is mod | ||
|
||
|
||
@td.skip_if_mpl | ||
def test_no_matplotlib_ok(): | ||
with pytest.raises(ImportError): | ||
pandas.plotting._core._get_plot_backend("matplotlib") |
Uh oh!
There was an error while loading. Please reload this page.