Skip to content

Commit 44cdece

Browse files
committed
Styling and imports
1 parent b7d3d31 commit 44cdece

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

plotly/tools.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
from plotly import exceptions
2121
from plotly import session
2222

23-
from plotly.graph_objs import graph_objs
24-
from plotly.graph_objs import Scatter, Marker, Line, Data
23+
from plotly.graph_objs import graph_objs, Scatter, Marker, Line, Data
2524

2625

2726
# Warning format
@@ -52,13 +51,23 @@ def warning_on_one_line(message, category, filename, lineno,
5251

5352
try:
5453
import scipy as scp
55-
import scipy.spatial as scs
56-
import scipy.cluster.hierarchy as sch
57-
5854
_scipy_imported = True
5955
except ImportError:
6056
_scipy_imported = False
6157

58+
try:
59+
import scipy.spatial as scs
60+
_scipy__spatial_imported = True
61+
except ImportError:
62+
_scipy__spatial_imported = False
63+
64+
try:
65+
import scipy.cluster.hierarchy as sch
66+
_scipy__cluster__hierarchy_imported = True
67+
except ImportError:
68+
_scipy__cluster__hierarchy_imported = False
69+
70+
6271
PLOTLY_DIR = os.path.join(os.path.expanduser("~"), ".plotly")
6372
CREDENTIALS_FILE = os.path.join(PLOTLY_DIR, ".credentials")
6473
CONFIG_FILE = os.path.join(PLOTLY_DIR, ".config")
@@ -2323,10 +2332,12 @@ def create_dendrogram(X, orientation="bottom", labels=None,
23232332
py.iplot(dendro_X, validate=False, height=1000, width=300)
23242333
```
23252334
"""
2326-
2327-
if _scipy_imported is False:
2328-
raise ImportError("FigureFactory.create_dendrogram requires scipy,
2329-
scipy.spatial and scipy.hierarchy")
2335+
dependencies = (_scipy_imported and _scipy__spatial_imported and
2336+
_scipy__cluster__hierarchy_imported)
2337+
2338+
if dependencies is False:
2339+
raise ImportError("FigureFactory.create_dendrogram requires scipy, \
2340+
scipy.spatial and scipy.hierarchy")
23302341

23312342
s = X.shape
23322343
if len(s) != 2:
@@ -2934,14 +2945,15 @@ def get_candle_decrease(self):
29342945
return (decrease_x, decrease_close, decrease_dif,
29352946
stick_decrease_y, stick_decrease_x)
29362947

2948+
29372949
class _Dendrogram(FigureFactory):
2938-
2950+
29392951
"""
29402952
Refer to FigureFactory.create_dendrogram() for docstring.
29412953
"""
29422954

2943-
def __init__(self, X, orientation='bottom', labels=None, colorscale=None, \
2944-
width="100%", height="100%", xaxis='xaxis', yaxis='yaxis' ):
2955+
def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
2956+
width="100%", height="100%", xaxis='xaxis', yaxis='yaxis'):
29452957
self.orientation = orientation
29462958
self.labels = labels
29472959
self.xaxis = xaxis
@@ -2961,8 +2973,8 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None, \
29612973
else:
29622974
self.sign[self.yaxis] = -1
29632975

2964-
dd_traces, xvals, yvals,
2965-
ordered_labels, leaves = self.get_dendrogram_traces(X, colorscale)
2976+
(dd_traces, xvals, yvals,
2977+
ordered_labels, leaves) = self.get_dendrogram_traces(X, colorscale)
29662978

29672979
self.labels = ordered_labels
29682980
self.leaves = leaves

0 commit comments

Comments
 (0)