Skip to content

Commit 0acd929

Browse files
authored
Fix dict ordering assumption for Python < 3.6.0
1 parent 2984664 commit 0acd929

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Diff for: plotly/basedatatypes.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
import collections
4+
from collections import OrderedDict
45
import re
56
import six
67
from six import string_types
@@ -233,14 +234,14 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
233234
# are suitable as `data` elements of Plotly.animate, but not
234235
# the Plotly.update (See `_build_update_params_from_batch`)
235236
#
236-
# type: typ.Dict[int, typ.Dict[str, typ.Any]]
237-
self._batch_trace_edits = {}
237+
# type: OrderedDict[int, OrderedDict[str, typ.Any]]
238+
self._batch_trace_edits = OrderedDict()
238239

239240
# ### Batch layout edits ###
240241
# Dict from layout properties to new layout values. This dict is
241242
# directly suitable for use in Plotly.animate and Plotly.update
242-
# type: typ.Dict[str, typ.Any]
243-
self._batch_layout_edits = {}
243+
# type: collections.OrderedDict[str, typ.Any]
244+
self._batch_layout_edits = OrderedDict()
244245

245246
# Animation property validators
246247
# -----------------------------
@@ -772,7 +773,7 @@ def _restyle_child(self, child, key_path_str, val):
772773
# Add key_path_str/val to saved batch edits
773774
else:
774775
if trace_index not in self._batch_trace_edits:
775-
self._batch_trace_edits[trace_index] = {}
776+
self._batch_trace_edits[trace_index] = OrderedDict()
776777
self._batch_trace_edits[trace_index][key_path_str] = val
777778

778779
def _normalize_trace_indexes(self, trace_indexes):

Diff for: plotly/tests/test_core/test_graph_objs/test_layout_subplots.py

+17
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,20 @@ def test_create_subplot_with_update_dict(self):
208208
self.assertEqual(self.layout.scene6.dragmode, 'zoom')
209209
self.assertEqual(self.layout.mapbox7.zoom, 2)
210210
self.assertEqual(self.layout.polar8.sector, (0, 90))
211+
212+
def test_bug_1462(self):
213+
# https: // github.com / plotly / plotly.py / issues / 1462
214+
fig = go.Figure(data=[
215+
go.Scatter(x=[1, 2], y=[1, 2], xaxis='x'),
216+
go.Scatter(x=[2, 3], y=[2, 3], xaxis='x2')])
217+
218+
layout_dict = {
219+
'grid': {'xaxes': ['x', 'x2'], 'yaxes': ['y']},
220+
# 'xaxis': {'title': 'total_bill'},
221+
'xaxis2': {'matches': 'x', 'title': {'text': 'total_bill'}}
222+
}
223+
224+
fig.update(layout=layout_dict)
225+
updated_layout_dict = fig.layout.to_plotly_json()
226+
227+
self.assertEqual(updated_layout_dict, layout_dict)

0 commit comments

Comments
 (0)