Skip to content

Commit 200d534

Browse files
Merge pull request #2455 from grisaitis/issue/markdown-syntax-updating-figures
Fix markdown syntax, typo in docs
2 parents 7e8d8af + f6a29af commit 200d534

File tree

18 files changed

+149
-55
lines changed

18 files changed

+149
-55
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [4.7.1] - 2020-05-08
6+
7+
### Fixed
8+
9+
- Fix `AttributeError: module 'plotly.graph_objs' has no attribute 'FigureWidget'` exception on `from plotly.graph_objs import *` when `ipywidgets` is not installed. Error also occurred when importing `plotly.figure_factor`. It is now possible to import `plotly.graph_objs.FigureWidget` when `ipywidgets` is not installed, and an informative `ImportError` exception will be raised in the `FigureWidget` constructor ([#2443](https://github.com/plotly/plotly.py/issues/2443), [#1111](https://github.com/plotly/plotly.py/issues/1111)).
10+
- Fix `TypeError: unhashable type: 'Template'` during `Figure` construction when `plotly.io.templates.default` is set to a `Template` object rather than a string.
11+
12+
513
## [4.7.0] - 2020-05-06
614

715
### Updated

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
## Quickstart
3535

36-
`pip install plotly==4.7.0`
36+
`pip install plotly==4.7.1`
3737

3838
Inside [Jupyter notebook](https://jupyter.org/install) (installable with `pip install "notebook>=5.3" "ipywidgets>=7.2"`):
3939

@@ -82,13 +82,13 @@ Built on top of [plotly.js](https://github.com/plotly/plotly.js), `plotly.py` is
8282
plotly.py may be installed using pip...
8383

8484
```
85-
pip install plotly==4.7.0
85+
pip install plotly==4.7.1
8686
```
8787

8888
or conda.
8989

9090
```
91-
conda install -c plotly plotly=4.7.0
91+
conda install -c plotly plotly=4.7.1
9292
```
9393

9494
### Jupyter Notebook Support
@@ -125,10 +125,10 @@ Then run the following commands to install the required JupyterLab extensions (n
125125

126126
```
127127
# Basic JupyterLab renderer support
128-
jupyter labextension install jupyterlab-plotly@4.7.0
128+
jupyter labextension install jupyterlab-plotly@4.7.1
129129
130130
# OPTIONAL: Jupyter widgets extension for FigureWidget support
131-
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.7.0
131+
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.7.1
132132
```
133133

134134
Please check out our [Troubleshooting guide](https://plotly.com/python/troubleshooting/) if you run into any problems with JupyterLab.

doc/python/creating-and-updating-figures.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -613,20 +613,22 @@ There are also `for_each_xaxis()` and `for_each_yaxis()` methods that are analog
613613
### Other Update Methods
614614

615615
Figures created with the plotly.py graphing library also support:
616-
- the `update_layout_images()` method in order to [update background layout images](/python/images/),
617-
- `update_annotations()` in order to [update annotations](/python/text-and-annotations/#multiple-annotations),
618-
- and `update-shapes()` in order to [update shapes](/python/shapes/).
616+
617+
- the `update_layout_images()` method in order to [update background layout images](/python/images/),
618+
- `update_annotations()` in order to [update annotations](/python/text-and-annotations/#multiple-annotations),
619+
- and `update_shapes()` in order to [update shapes](/python/shapes/).
619620

620621
#### Chaining Figure Operations
621622

622623
All of the figure update operations described above are methods that return a reference to the figure being modified. This makes it possible the chain multiple figure modification operations together into a single expression.
623624

624625
Here is an example of a chained expression that creates:
625-
- a faceted scatter plot with OLS trend lines using Plotly Express,
626-
- sets the title font size using `update_layout()`,
627-
- disables vertical grid lines using `update_xaxes()`,
628-
- updates the width and dash pattern of the trend lines using `update_traces()`,
629-
- and then displays the figure using `show()`.
626+
627+
- a faceted scatter plot with OLS trend lines using Plotly Express,
628+
- sets the title font size using `update_layout()`,
629+
- disables vertical grid lines using `update_xaxes()`,
630+
- updates the width and dash pattern of the trend lines using `update_traces()`,
631+
- and then displays the figure using `show()`.
630632

631633
```python
632634
import plotly.express as px

doc/python/getting-started.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ Thanks to deep integration with the [orca](https://github.com/plotly/orca) image
4949
plotly.py may be installed using pip...
5050

5151
```
52-
$ pip install plotly==4.7.0
52+
$ pip install plotly==4.7.1
5353
```
5454

5555
or conda.
5656

5757
```
58-
$ conda install -c plotly plotly=4.7.0
58+
$ conda install -c plotly plotly=4.7.1
5959
```
6060

6161
This package contains everything you need to write figures to standalone HTML files.
@@ -134,10 +134,10 @@ Then run the following commands to install the required JupyterLab extensions (n
134134

135135
```
136136
# JupyterLab renderer support
137-
jupyter labextension install jupyterlab-plotly@4.7.0
137+
jupyter labextension install jupyterlab-plotly@4.7.1
138138
139139
# OPTIONAL: Jupyter widgets extension
140-
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.7.0
140+
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.7.1
141141
```
142142

143143
These packages contain everything you need to run JupyterLab...

packages/javascript/jupyterlab-plotly/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/javascript/jupyterlab-plotly/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyterlab-plotly",
3-
"version": "4.7.0",
3+
"version": "4.7.1",
44
"description": "The plotly JupyterLab extension",
55
"author": "The plotly.py team",
66
"license": "MIT",

packages/javascript/plotlywidget/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/javascript/plotlywidget/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plotlywidget",
3-
"version": "4.7.0",
3+
"version": "4.7.1",
44
"description": "The plotly JupyterLab extension",
55
"author": "The plotly.py team",
66
"license": "MIT",

packages/python/plotly/codegen/__init__.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,14 @@ def perform_codegen():
269269
optional_figure_widget_import = f"""
270270
if sys.version_info < (3, 7):
271271
try:
272-
import ipywidgets
273-
from distutils.version import LooseVersion
274-
if LooseVersion(ipywidgets.__version__) >= LooseVersion('7.0.0'):
272+
import ipywidgets as _ipywidgets
273+
from distutils.version import LooseVersion as _LooseVersion
274+
if _LooseVersion(_ipywidgets.__version__) >= _LooseVersion("7.0.0"):
275275
from ..graph_objs._figurewidget import FigureWidget
276-
del LooseVersion
277-
del ipywidgets
278-
except ImportError:
279-
pass
276+
else:
277+
raise ImportError()
278+
except Exception:
279+
from ..missing_ipywidgets import FigureWidget
280280
else:
281281
__all__.append("FigureWidget")
282282
orig_getattr = __getattr__
@@ -285,12 +285,17 @@ def __getattr__(import_name):
285285
try:
286286
import ipywidgets
287287
from distutils.version import LooseVersion
288-
if LooseVersion(ipywidgets.__version__) >= LooseVersion('7.0.0'):
288+
289+
if LooseVersion(ipywidgets.__version__) >= LooseVersion("7.0.0"):
289290
from ..graph_objs._figurewidget import FigureWidget
291+
290292
return FigureWidget
291-
except ImportError:
292-
pass
293-
293+
else:
294+
raise ImportError()
295+
except Exception:
296+
from ..missing_ipywidgets import FigureWidget
297+
return FigureWidget
298+
294299
return orig_getattr(import_name)
295300
"""
296301
# ### __all__ ###

packages/python/plotly/plotly/_widget_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# for automated dev builds
33
#
44
# It is edited by hand prior to official releases
5-
__frontend_version__ = "4.7.0"
5+
__frontend_version__ = "4.7.1"

packages/python/plotly/plotly/basedatatypes.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1951,8 +1951,14 @@ def _initialize_layout_template(self):
19511951
if self._allow_disable_validation:
19521952
self._layout_obj._validate = False
19531953
try:
1954-
template_dict = pio.templates[pio.templates.default]
1955-
self._layout_obj.template = template_dict
1954+
if isinstance(pio.templates.default, BasePlotlyType):
1955+
# Template object. Don't want to actually import `Template`
1956+
# here for performance so we check against `BasePlotlyType`
1957+
template_object = pio.templates.default
1958+
else:
1959+
# Name of registered template object
1960+
template_object = pio.templates[pio.templates.default]
1961+
self._layout_obj.template = template_object
19561962
finally:
19571963
self._layout_obj._validate = self._validate
19581964

packages/python/plotly/plotly/graph_objects/__init__.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@
261261

262262
if sys.version_info < (3, 7):
263263
try:
264-
import ipywidgets
265-
from distutils.version import LooseVersion
264+
import ipywidgets as _ipywidgets
265+
from distutils.version import LooseVersion as _LooseVersion
266266

267-
if LooseVersion(ipywidgets.__version__) >= LooseVersion("7.0.0"):
267+
if _LooseVersion(_ipywidgets.__version__) >= _LooseVersion("7.0.0"):
268268
from ..graph_objs._figurewidget import FigureWidget
269-
del LooseVersion
270-
del ipywidgets
271-
except ImportError:
272-
pass
269+
else:
270+
raise ImportError()
271+
except Exception:
272+
from ..missing_ipywidgets import FigureWidget
273273
else:
274274
__all__.append("FigureWidget")
275275
orig_getattr = __getattr__
@@ -284,7 +284,11 @@ def __getattr__(import_name):
284284
from ..graph_objs._figurewidget import FigureWidget
285285

286286
return FigureWidget
287-
except ImportError:
288-
pass
287+
else:
288+
raise ImportError()
289+
except Exception:
290+
from ..missing_ipywidgets import FigureWidget
291+
292+
return FigureWidget
289293

290294
return orig_getattr(import_name)

packages/python/plotly/plotly/graph_objs/__init__.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@
261261

262262
if sys.version_info < (3, 7):
263263
try:
264-
import ipywidgets
265-
from distutils.version import LooseVersion
264+
import ipywidgets as _ipywidgets
265+
from distutils.version import LooseVersion as _LooseVersion
266266

267-
if LooseVersion(ipywidgets.__version__) >= LooseVersion("7.0.0"):
267+
if _LooseVersion(_ipywidgets.__version__) >= _LooseVersion("7.0.0"):
268268
from ..graph_objs._figurewidget import FigureWidget
269-
del LooseVersion
270-
del ipywidgets
271-
except ImportError:
272-
pass
269+
else:
270+
raise ImportError()
271+
except Exception:
272+
from ..missing_ipywidgets import FigureWidget
273273
else:
274274
__all__.append("FigureWidget")
275275
orig_getattr = __getattr__
@@ -284,7 +284,11 @@ def __getattr__(import_name):
284284
from ..graph_objs._figurewidget import FigureWidget
285285

286286
return FigureWidget
287-
except ImportError:
288-
pass
287+
else:
288+
raise ImportError()
289+
except Exception:
290+
from ..missing_ipywidgets import FigureWidget
291+
292+
return FigureWidget
289293

290294
return orig_getattr(import_name)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .basedatatypes import BaseFigure
2+
3+
4+
class FigureWidget(BaseFigure):
5+
"""
6+
FigureWidget stand-in for use when ipywidgets is not installed. The only purpose
7+
of this class is to provide something to import as
8+
`plotly.graph_objs.FigureWidget` when ipywidgets is not installed. This class
9+
simply raises an informative error message when the constructor is called
10+
"""
11+
12+
def __init__(self, *args, **kwargs):
13+
raise ImportError(
14+
"Please install ipywidgets>=7.0.0 to use the FigureWidget class"
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
3+
# Use wildcard import to make sure FigureWidget is always included
4+
from plotly.graph_objects import *
5+
from plotly.missing_ipywidgets import FigureWidget as FigureWidgetMissingIPywidgets
6+
7+
try:
8+
import ipywidgets as _ipywidgets
9+
from distutils.version import LooseVersion as _LooseVersion
10+
11+
if _LooseVersion(_ipywidgets.__version__) >= _LooseVersion("7.0.0"):
12+
missing_ipywidgets = False
13+
else:
14+
raise ImportError()
15+
except Exception:
16+
missing_ipywidgets = True
17+
18+
19+
if missing_ipywidgets:
20+
21+
def test_import_figurewidget_without_ipywidgets():
22+
assert FigureWidget is FigureWidgetMissingIPywidgets
23+
24+
with pytest.raises(ImportError):
25+
# ipywidgets import error raised on construction, not import
26+
FigureWidget()
27+
28+
29+
else:
30+
31+
def test_import_figurewidget_with_ipywidgets():
32+
from plotly.graph_objs._figurewidget import (
33+
FigureWidget as FigureWidgetWithIPywidgets,
34+
)
35+
36+
assert FigureWidget is FigureWidgetWithIPywidgets
37+
fig = FigureWidget()
38+
assert isinstance(fig, FigureWidgetWithIPywidgets)

packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
import plotly.graph_objs as go
33
import pytest
44

5+
try:
6+
go.FigureWidget()
7+
figure_widget_available = True
8+
except ImportError:
9+
figure_widget_available = False
10+
511

612
class TestNoFrames(TestCase):
7-
if "FigureWidget" in go.__dict__.keys():
13+
if figure_widget_available:
814

915
def test_no_frames_in_constructor_kwarg(self):
1016
with pytest.raises(ValueError):

packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py

+6
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ def test_template_in(self):
175175
def test_template_iter(self):
176176
self.assertIn("test_template", set(pio.templates))
177177

178+
def test_template_default_as_object(self):
179+
template = go.layout.Template({"layout": {"font": {"family": "Rockwell"}}})
180+
pio.templates.default = template
181+
fig = go.Figure()
182+
self.assertEqual(fig.layout.template, template)
183+
178184

179185
class TestToTemplated(TestCaseNoTemplate):
180186
def test_move_layout_nested_properties(self):

packages/python/plotly/plotlywidget/static/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)