Skip to content

Commit 04f6dae

Browse files
authored
Show the right style options with the help function (#754)
1 parent b2e0a2a commit 04f6dae

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ nosetests.xml
4545
coverage.xml
4646
*.cover
4747
.hypothesis/
48+
.pytest_cache
4849

4950
# Translations
5051
*.mo

hvplot/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _get_doc_and_signature(
4242
formatter += "{options}"
4343

4444
# Bokeh is the default backend
45-
backend = hvplot_extension.compatibility or 'bokeh'
45+
backend = hvplot_extension.compatibility or Store.current_backend
4646
if eltype in Store.registry[backend]:
4747
valid_opts = Store.registry[backend][eltype].style_opts
4848
if style:

hvplot/tests/testhelp.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import hvplot.pandas
2+
import pytest
3+
4+
from holoviews.core import Store
5+
from holoviews.element import Curve
6+
7+
8+
@pytest.fixture
9+
def reset_default_backend():
10+
yield
11+
hvplot.extension('bokeh')
12+
hvplot.extension.compatibility = None
13+
14+
15+
def test_help_style_extension_output(reset_default_backend):
16+
# default, after e.g. import hvplot.pandas
17+
docstring, signature = hvplot._get_doc_and_signature(
18+
cls=hvplot.hvPlot,
19+
kind='line',
20+
completions=False,
21+
docstring=False,
22+
generic=False,
23+
style=True,
24+
signature=None,
25+
)
26+
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['bokeh'][Curve].style_opts))
27+
28+
# The current backend becomes matplotlib
29+
hvplot.extension('matplotlib', 'plotly')
30+
docstring, signature = hvplot._get_doc_and_signature(
31+
cls=hvplot.hvPlot,
32+
kind='line',
33+
completions=False,
34+
docstring=False,
35+
generic=False,
36+
style=True,
37+
signature=None,
38+
)
39+
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['matplotlib'][Curve].style_opts))
40+
41+
# The current backend becomes plotly
42+
hvplot.output(backend='plotly')
43+
docstring, signature = hvplot._get_doc_and_signature(
44+
cls=hvplot.hvPlot,
45+
kind='line',
46+
completions=False,
47+
docstring=False,
48+
generic=False,
49+
style=True,
50+
signature=None,
51+
)
52+
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['plotly'][Curve].style_opts))
53+
54+
def test_help_style_compatibility(reset_default_backend):
55+
# The current backend is plotly but the style options are those of matplotlib
56+
hvplot.extension('plotly', 'matplotlib', compatibility='matplotlib')
57+
docstring, signature = hvplot._get_doc_and_signature(
58+
cls=hvplot.hvPlot,
59+
kind='line',
60+
completions=False,
61+
docstring=False,
62+
generic=False,
63+
style=True,
64+
signature=None,
65+
)
66+
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['matplotlib'][Curve].style_opts))

0 commit comments

Comments
 (0)