Skip to content

Commit b57def2

Browse files
fix tests
1 parent f7d537c commit b57def2

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

packages/python/plotly/plotly/express/_core.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1184,20 +1184,22 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
11841184
nrows = ncols = 1
11851185
col_labels = []
11861186
row_labels = []
1187+
trace_name_labels = []
11871188
for group_name in sorted_group_names:
11881189
group = grouped.get_group(group_name if len(group_name) > 1 else group_name[0])
11891190
mapping_labels = OrderedDict()
1190-
trace_name_labels = OrderedDict()
11911191
frame_name = ""
1192+
trace_name = []
11921193
for col, val, m in zip(grouper, group_name, grouped_mappings):
11931194
if col != one_group:
11941195
key = get_label(args, col)
11951196
mapping_labels[key] = str(val)
11961197
if m.show_in_trace_name:
1197-
trace_name_labels[key] = str(val)
1198+
trace_name_labels.append(key)
1199+
trace_name.append(str(val))
11981200
if m.variable == "animation_frame":
11991201
frame_name = val
1200-
trace_name = ", ".join(trace_name_labels.values())
1202+
trace_name = ", ".join(trace_name)
12011203
if frame_name not in trace_names_by_frame:
12021204
trace_names_by_frame[frame_name] = set()
12031205
trace_names = trace_names_by_frame[frame_name]
@@ -1346,7 +1348,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
13461348
for v in ["title", "height", "width"]:
13471349
if args[v]:
13481350
layout_patch[v] = args[v]
1349-
layout_patch["legend"] = dict(tracegroupgap=0, title=", ".join(trace_name_labels))
1351+
layout_patch["legend"] = dict(tracegroupgap=0)
1352+
if trace_name_labels:
1353+
layout_patch["legend"]["title"] = ", ".join(trace_name_labels)
13501354
if "title" not in layout_patch and args["template"].layout.margin.t is None:
13511355
layout_patch["margin"] = {"t": 60}
13521356
if (

packages/python/plotly/plotly/tests/test_core/test_px/test_px.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ def test_labels():
6363
facet_col="day",
6464
color="size",
6565
symbol="sex",
66-
labels={c: c[::-1] for c in tips.columns},
66+
labels={c: c.upper() for c in tips.columns},
6767
)
68-
assert "xes" in fig.data[0].hovertemplate
69-
assert "llib_latot" in fig.data[0].hovertemplate
70-
assert "ezis" in fig.data[0].hovertemplate
71-
assert "yad" in fig.data[0].hovertemplate
72-
assert "emit" in fig.data[0].hovertemplate
73-
assert fig.data[0].name.startswith("xes")
74-
assert fig.layout.xaxis.title.text == "llib_latot"
75-
assert fig.layout.coloraxis.colorbar.title.text == "ezis"
76-
assert fig.layout.annotations[0].text.startswith("yad")
77-
assert fig.layout.annotations[4].text.startswith("emit")
68+
assert "SEX" in fig.data[0].hovertemplate
69+
assert "TOTAL_BILL" in fig.data[0].hovertemplate
70+
assert "SIZE" in fig.data[0].hovertemplate
71+
assert "DAY" in fig.data[0].hovertemplate
72+
assert "TIME" in fig.data[0].hovertemplate
73+
assert fig.layout.legend.title.text.startswith("SEX")
74+
assert fig.layout.xaxis.title.text == "TOTAL_BILL"
75+
assert fig.layout.coloraxis.colorbar.title.text == "SIZE"
76+
assert fig.layout.annotations[0].text.startswith("DAY")
77+
assert fig.layout.annotations[4].text.startswith("TIME")
7878

7979

8080
def test_px_templates():

0 commit comments

Comments
 (0)