Skip to content

Commit 385854d

Browse files
authored
[WIP] fix for figure factory import when scipy not installed (#1423)
Fix for figure factory import when scipy not installed
1 parent 5a41c59 commit 385854d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

plotly/figure_factory/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from plotly import optional_imports
44

55
# Require that numpy exists for figure_factory
6-
import numpy
6+
np = optional_imports.get_module('numpy')
7+
if np is None:
8+
raise ImportError("""\
9+
The figure factory module requires the numpy package""")
10+
711

812
from plotly.figure_factory._2d_density import create_2d_density
913
from plotly.figure_factory._annotated_heatmap import create_annotated_heatmap

plotly/figure_factory/_ternary_contour.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import absolute_import
2-
import numpy as np
3-
from scipy.interpolate import griddata
2+
from plotly import optional_imports
43
from plotly.graph_objs import graph_objs as go
5-
import warnings
4+
5+
import numpy as np
6+
interpolate = optional_imports.get_module('scipy.interpolate')
67

78

89
def _pl_deep():
@@ -415,8 +416,8 @@ def _compute_grid(coordinates, values, tooltip_mode):
415416
gr_x = np.linspace(x_min, x_max, n_interp)
416417
gr_y = np.linspace(y_min, y_max, n_interp)
417418
grid_x, grid_y = np.meshgrid(gr_x, gr_y)
418-
grid_z = griddata(cartes_coord_points[:2].T, values, (grid_x, grid_y),
419-
method='cubic')
419+
grid_z = interpolate.griddata(
420+
cartes_coord_points[:2].T, values, (grid_x, grid_y), method='cubic')
420421
bar_coords = np.einsum('ik, kmn -> imn', invM,
421422
np.stack((grid_x, grid_y, np.ones(grid_x.shape))))
422423
# invalidate the points outside of the reference triangle
@@ -495,6 +496,10 @@ def create_ternary_contour(coordinates, values, pole_labels=['a', 'b', 'c'],
495496
496497
fig = ff.create_ternary_contour(np.stack((a, b)), z, coloring='lines')
497498
"""
499+
if interpolate is None:
500+
raise ImportError("""\
501+
The create_ternary_contour figure factory requires the scipy package""")
502+
498503
grid_z, gr_x, gr_y, tooltip = _compute_grid(coordinates, values,
499504
tooltip_mode)
500505

0 commit comments

Comments
 (0)