Skip to content

Commit 842fea0

Browse files
committed
Test fixes
1 parent 9f357fa commit 842fea0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

packages/python/plotly/plotly/basedatatypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,7 @@ def __getitem__(self, prop):
33483348
raise KeyError(prop)
33493349

33503350
validator = self._get_validator(prop)
3351+
self._init_props()
33513352

33523353
if isinstance(validator, CompoundValidator):
33533354
if self._compound_props.get(prop, None) is None:

packages/python/plotly/plotly/io/_templates.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def walk_push_to_template(fig_obj, template_obj, skip):
304304
fig_val = fig_obj[prop]
305305
template_val = template_obj[prop]
306306

307-
validator = fig_obj._validators[prop]
307+
validator = fig_obj._get_validator(prop)
308308

309309
if isinstance(validator, CompoundValidator):
310310
walk_push_to_template(fig_val, template_val, skip)
@@ -483,10 +483,17 @@ def to_templated(fig, skip=("title", "text")):
483483
trace_type_indexes[trace.type] = template_index + 1
484484

485485
# Remove useless trace arrays
486+
any_non_empty = False
486487
for trace_type in templated_fig.layout.template.data:
487488
traces = templated_fig.layout.template.data[trace_type]
488489
is_empty = [trace.to_plotly_json() == {"type": trace_type} for trace in traces]
489490
if all(is_empty):
490491
templated_fig.layout.template.data[trace_type] = None
492+
else:
493+
any_non_empty = True
494+
495+
# Check if we can remove the data altogether key
496+
if not any_non_empty:
497+
templated_fig.layout.template.data = None
491498

492499
return templated_fig

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_move_layout_nested_properties(self):
195195
"layout": {
196196
"font": {"family": "Courier New"},
197197
"paper_bgcolor": "yellow",
198-
}
198+
},
199199
},
200200
"title": "Hello",
201201
}

0 commit comments

Comments
 (0)