Skip to content

Commit efde794

Browse files
committed
Remove KeyError handling in _Dendrogram.get_color_dict
new_old_color_map is hardcoded, and default_colors has a minimal key set that includes all the values. Drive-by: simplify the overlay of rgb_colorscale onto default_colors. Closes plotly#2806
1 parent 2c47686 commit efde794

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

packages/python/plotly/plotly/figure_factory/_dendrogram.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ def get_color_dict(self, colorscale):
223223
else:
224224
rgb_colorscale = colorscale
225225

226-
for i in range(len(default_colors.keys())):
227-
k = list(default_colors.keys())[i] # PY3 won't index keys
228-
if i < len(rgb_colorscale):
229-
default_colors[k] = rgb_colorscale[i]
226+
for i, k in enumerate(default_colors.keys()):
227+
if i >= len(rgb_colorscale):
228+
break
229+
default_colors[k] = rgb_colorscale[i]
230230

231231
# add support for cyclic format colors as introduced in scipy===1.5.0
232232
# before this, the colors were named 'r', 'b', 'y' etc., now they are
@@ -248,13 +248,7 @@ def get_color_dict(self, colorscale):
248248
("C9", "c"),
249249
]
250250
for nc, oc in new_old_color_map:
251-
try:
252-
default_colors[nc] = default_colors[oc]
253-
except KeyError:
254-
# it could happen that the old color isn't found (if a custom
255-
# colorscale was specified), in this case we set it to an
256-
# arbitrary default.
257-
default_colors[n] = "rgb(0,116,217)"
251+
default_colors[nc] = default_colors[oc]
258252

259253
return default_colors
260254

0 commit comments

Comments
 (0)