Skip to content

Commit 07f8c69

Browse files
authored
doctest package, with some docstrings modifications (#1921)
* first round of changes towards doctesting * docstrings of figure factories * docstring formatting for deprecations * template + conftest * added doctest job in tox.ini * bug fix in conftest * moved doctest to python 3.6 * deps in test * added init in test dirs * moved doctest to ci with orca * typo * more deps for CI * doctest only in pytest command * ignore matplotlylib * test fixes * black * reverted change in tox.ini * reverted changes to table ff
1 parent 3e35a6b commit 07f8c69

27 files changed

+213
-269
lines changed

.circleci/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ jobs:
325325
command: |
326326
. /home/circleci/miniconda/etc/profile.d/conda.sh
327327
conda activate circle_optional
328+
pytest --doctest-modules --ignore packages/python/plotly/plotly/tests --ignore packages/python/plotly/plotly/matplotlylib/mplexporter/tests packages/python/plotly/plotly
328329
pytest --disable-warnings packages/python/plotly/plotly/tests/test_core
329330
pytest packages/python/plotly/plotly/tests/test_orca
330331

.circleci/create_conda_optional_env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [ ! -d $HOME/miniconda/envs/circle_optional ]; then
1616
# Create environment
1717
# PYTHON_VERSION=3.6
1818
$HOME/miniconda/bin/conda create -n circle_optional --yes python=$PYTHON_VERSION \
19-
requests nbformat six retrying psutil pandas decorator pytest mock nose poppler xarray scikit-image ipython
19+
requests nbformat six retrying psutil pandas decorator pytest mock nose poppler xarray scikit-image ipython jupyter ipykernel ipywidgets
2020

2121
# Install orca into environment
2222
$HOME/miniconda/bin/conda install --yes -n circle_optional -c plotly plotly-orca

packages/python/plotly/plotly/basedatatypes.py

+36-13
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,9 @@ def update(self, dict1=None, overwrite=False, **kwargs):
458458
--------
459459
>>> import plotly.graph_objs as go
460460
>>> fig = go.Figure(data=[{'y': [1, 2, 3]}])
461-
>>> fig.update(data=[{'y': [4, 5, 6]}])
462-
>>> fig.to_plotly_json()
461+
>>> fig.update(data=[{'y': [4, 5, 6]}]) # doctest: +ELLIPSIS
462+
Figure(...)
463+
>>> fig.to_plotly_json() # doctest: +SKIP
463464
{'data': [{'type': 'scatter',
464465
'uid': 'e86a7c7a-346a-11e8-8aa8-a0999b0c017b',
465466
'y': array([4, 5, 6], dtype=int32)}],
@@ -468,8 +469,9 @@ def update(self, dict1=None, overwrite=False, **kwargs):
468469
>>> fig = go.Figure(layout={'xaxis':
469470
... {'color': 'green',
470471
... 'range': [0, 1]}})
471-
>>> fig.update({'layout': {'xaxis': {'color': 'pink'}}})
472-
>>> fig.to_plotly_json()
472+
>>> fig.update({'layout': {'xaxis': {'color': 'pink'}}}) # doctest: +ELLIPSIS
473+
Figure(...)
474+
>>> fig.to_plotly_json() # doctest: +SKIP
473475
{'data': [],
474476
'layout': {'xaxis':
475477
{'color': 'pink',
@@ -1128,6 +1130,8 @@ def plotly_restyle(self, restyle_data, trace_indexes=None, **kwargs):
11281130
example, the following command would be used to update the 'x'
11291131
property of the first trace to the list [1, 2, 3]
11301132
1133+
>>> import plotly.graph_objects as go
1134+
>>> fig = go.Figure(go.Scatter(x=[2, 4, 6]))
11311135
>>> fig.plotly_restyle({'x': [[1, 2, 3]]}, 0)
11321136
11331137
trace_indexes : int or list of int
@@ -1586,15 +1590,19 @@ def add_trace(self, trace, row=None, col=None, secondary_y=None):
15861590
Add two Scatter traces to a figure
15871591
15881592
>>> fig = go.Figure()
1589-
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]))
1590-
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]))
1593+
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2])) # doctest: +ELLIPSIS
1594+
Figure(...)
1595+
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2])) # doctest: +ELLIPSIS
1596+
Figure(...)
15911597
15921598
15931599
Add two Scatter traces to vertically stacked subplots
15941600
15951601
>>> fig = subplots.make_subplots(rows=2)
1596-
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1)
1597-
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1)
1602+
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1) # doctest: +ELLIPSIS
1603+
Figure(...)
1604+
>>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1) # doctest: +ELLIPSIS
1605+
Figure(...)
15981606
"""
15991607
# Make sure we have both row and col or neither
16001608
if row is not None and col is None:
@@ -1662,14 +1670,16 @@ def add_traces(self, data, rows=None, cols=None, secondary_ys=None):
16621670
16631671
>>> fig = go.Figure()
16641672
>>> fig.add_traces([go.Scatter(x=[1,2,3], y=[2,1,2]),
1665-
... go.Scatter(x=[1,2,3], y=[2,1,2])])
1673+
... go.Scatter(x=[1,2,3], y=[2,1,2])]) # doctest: +ELLIPSIS
1674+
Figure(...)
16661675
16671676
Add two Scatter traces to vertically stacked subplots
16681677
16691678
>>> fig = subplots.make_subplots(rows=2)
16701679
>>> fig.add_traces([go.Scatter(x=[1,2,3], y=[2,1,2]),
16711680
... go.Scatter(x=[1,2,3], y=[2,1,2])],
1672-
... rows=[1, 2], cols=[1, 1])
1681+
... rows=[1, 2], cols=[1, 1]) # doctest: +ELLIPSIS
1682+
Figure(...)
16731683
"""
16741684

16751685
# Validate traces
@@ -2152,11 +2162,12 @@ def _build_dispatch_plan(key_path_strs):
21522162
21532163
Examples
21542164
--------
2165+
21552166
>>> key_path_strs = ['xaxis.rangeselector.font.color',
21562167
... 'xaxis.rangeselector.bgcolor']
21572168
2158-
>>> BaseFigure._build_dispatch_plan(key_path_strs)
2159-
{(): {('xaxis',),
2169+
>>> BaseFigure._build_dispatch_plan(key_path_strs) # doctest: +SKIP
2170+
{(): {'xaxis',
21602171
('xaxis', 'rangeselector'),
21612172
('xaxis', 'rangeselector', 'bgcolor'),
21622173
('xaxis', 'rangeselector', 'font'),
@@ -2589,7 +2600,7 @@ def batch_animate(self, duration=500, easing="cubic-in-out"):
25892600
2) Animate a change in the size and color of the trace's markers
25902601
over 2 seconds using the elastic-in-out easing method
25912602
2592-
>>> with fig.batch_update(duration=2000, easing='elastic-in-out'):
2603+
>>> with fig.batch_animate(duration=2000, easing='elastic-in-out'):
25932604
... fig.data[0].marker.color = 'green'
25942605
... fig.data[0].marker.size = 20
25952606
"""
@@ -4088,6 +4099,8 @@ def on_change(self, callback, *args, **kwargs):
40884099
Register callback that prints out the range extents of the xaxis and
40894100
yaxis whenever either either of them changes.
40904101
4102+
>>> import plotly.graph_objects as go
4103+
>>> fig = go.Figure(go.Scatter(x=[1, 2], y=[1, 0]))
40914104
>>> fig.layout.on_change(
40924105
... lambda obj, xrange, yrange: print("%s-%s" % (xrange, yrange)),
40934106
... ('xaxis', 'range'), ('yaxis', 'range'))
@@ -4572,13 +4585,15 @@ def on_hover(self, callback, append=False):
45724585
Examples
45734586
--------
45744587
4588+
>>> import plotly.graph_objects as go
45754589
>>> from plotly.callbacks import Points, InputDeviceState
45764590
>>> points, state = Points(), InputDeviceState()
45774591
45784592
>>> def hover_fn(trace, points, state):
45794593
... inds = points.point_inds
45804594
... # Do something
45814595
4596+
>>> trace = go.Scatter(x=[1, 2], y=[3, 0])
45824597
>>> trace.on_hover(hover_fn)
45834598
45844599
Note: The creation of the `points` and `state` objects is optional,
@@ -4632,13 +4647,15 @@ def on_unhover(self, callback, append=False):
46324647
Examples
46334648
--------
46344649
4650+
>>> import plotly.graph_objects as go
46354651
>>> from plotly.callbacks import Points, InputDeviceState
46364652
>>> points, state = Points(), InputDeviceState()
46374653
46384654
>>> def unhover_fn(trace, points, state):
46394655
... inds = points.point_inds
46404656
... # Do something
46414657
4658+
>>> trace = go.Scatter(x=[1, 2], y=[3, 0])
46424659
>>> trace.on_unhover(unhover_fn)
46434660
46444661
Note: The creation of the `points` and `state` objects is optional,
@@ -4692,13 +4709,15 @@ def on_click(self, callback, append=False):
46924709
Examples
46934710
--------
46944711
4712+
>>> import plotly.graph_objects as go
46954713
>>> from plotly.callbacks import Points, InputDeviceState
46964714
>>> points, state = Points(), InputDeviceState()
46974715
46984716
>>> def click_fn(trace, points, state):
46994717
... inds = points.point_inds
47004718
... # Do something
47014719
4720+
>>> trace = go.Scatter(x=[1, 2], y=[3, 0])
47024721
>>> trace.on_click(click_fn)
47034722
47044723
Note: The creation of the `points` and `state` objects is optional,
@@ -4751,13 +4770,15 @@ def on_selection(self, callback, append=False):
47514770
Examples
47524771
--------
47534772
4773+
>>> import plotly.graph_objects as go
47544774
>>> from plotly.callbacks import Points
47554775
>>> points = Points()
47564776
47574777
>>> def selection_fn(trace, points, selector):
47584778
... inds = points.point_inds
47594779
... # Do something
47604780
4781+
>>> trace = go.Scatter(x=[1, 2], y=[3, 0])
47614782
>>> trace.on_selection(selection_fn)
47624783
47634784
Note: The creation of the `points` object is optional,
@@ -4817,13 +4838,15 @@ def on_deselect(self, callback, append=False):
48174838
Examples
48184839
--------
48194840
4841+
>>> import plotly.graph_objects as go
48204842
>>> from plotly.callbacks import Points
48214843
>>> points = Points()
48224844
48234845
>>> def deselect_fn(trace, points):
48244846
... inds = points.point_inds
48254847
... # Do something
48264848
4849+
>>> trace = go.Scatter(x=[1, 2], y=[3, 0])
48274850
>>> trace.on_deselect(deselect_fn)
48284851
48294852
Note: The creation of the `points` object is optional,
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
import os
3+
4+
5+
def pytest_ignore_collect(path):
6+
# Ignored files, most of them are raising a chart studio error
7+
ignored_paths = [
8+
"exploding_module.py",
9+
"chunked_requests.py",
10+
"v2.py",
11+
"v1.py",
12+
"presentation_objs.py",
13+
"widgets.py",
14+
"dashboard_objs.py",
15+
"grid_objs.py",
16+
"config.py",
17+
"presentation_objs.py",
18+
"session.py",
19+
]
20+
if (
21+
os.path.basename(str(path)) in ignored_paths
22+
or "plotly/plotly/plotly/__init__.py" in str(path)
23+
or "plotly/api/utils.py" in str(path)
24+
):
25+
return True

packages/python/plotly/plotly/figure_factory/_2d_density.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def create_2d_density(
3232
width=600,
3333
):
3434
"""
35-
Returns figure for a 2D density plot
35+
**deprecated**, use instead
36+
:func:`plotly.express.density_heatmap`.
3637
3738
:param (list|array) x: x-axis data for plot generation
3839
:param (list|array) y: y-axis data for plot generation
@@ -56,8 +57,7 @@ def create_2d_density(
5657
5758
Example 1: Simple 2D Density Plot
5859
59-
>>> from plotly.figure_factory create_2d_density
60-
60+
>>> from plotly.figure_factory import create_2d_density
6161
>>> import numpy as np
6262
6363
>>> # Make data points
@@ -66,14 +66,14 @@ def create_2d_density(
6666
>>> y = (t**6)+(0.3*np.random.randn(2000))
6767
6868
>>> # Create a figure
69-
>>> fig = create_2D_density(x, y)
69+
>>> fig = create_2d_density(x, y)
7070
7171
>>> # Plot the data
7272
>>> fig.show()
7373
7474
Example 2: Using Parameters
7575
76-
>>> from plotly.figure_factory create_2d_density
76+
>>> from plotly.figure_factory import create_2d_density
7777
7878
>>> import numpy as np
7979
@@ -87,7 +87,7 @@ def create_2d_density(
8787
... (1, 1, 0.2), (0.98,0.98,0.98)]
8888
8989
>>> # Create a figure
90-
>>> fig = create_2D_density(x, y, colorscale=colorscale,
90+
>>> fig = create_2d_density(x, y, colorscale=colorscale,
9191
... hist_color='rgb(255, 237, 222)', point_size=3)
9292
9393
>>> # Plot the data

packages/python/plotly/plotly/figure_factory/_annotated_heatmap.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_annotated_heatmap(
5959
**kwargs
6060
):
6161
"""
62-
BETA function that creates annotated heatmaps
62+
Function that creates annotated heatmaps
6363
6464
This function adds annotations to each cell of the heatmap.
6565
@@ -94,7 +94,6 @@ def create_annotated_heatmap(
9494
9595
>>> fig = ff.create_annotated_heatmap(z)
9696
>>> fig.show()
97-
```
9897
"""
9998

10099
# Avoiding mutables in the call signature

packages/python/plotly/plotly/figure_factory/_bullet.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def create_bullet(
198198
**layout_options
199199
):
200200
"""
201-
Returns figure for bullet chart.
201+
**deprecated**, use instead the plotly.graph_objects trace
202+
:class:`plotly.graph_objects.Indicator`.
202203
203204
:param (pd.DataFrame | list | tuple) data: either a list/tuple of
204205
dictionaries or a pandas DataFrame.

0 commit comments

Comments
 (0)