Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dict ordering assumption for Python < 3.6.0 #1464

Merged
merged 1 commit into from Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions plotly/basedatatypes.py
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import collections
from collections import OrderedDict
import re
import six
from six import string_types
Expand Down Expand Up @@ -233,14 +234,14 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
# are suitable as `data` elements of Plotly.animate, but not
# the Plotly.update (See `_build_update_params_from_batch`)
#
# type: typ.Dict[int, typ.Dict[str, typ.Any]]
self._batch_trace_edits = {}
# type: OrderedDict[int, OrderedDict[str, typ.Any]]
self._batch_trace_edits = OrderedDict()

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

# Animation property validators
# -----------------------------
Expand Down Expand Up @@ -772,7 +773,7 @@ def _restyle_child(self, child, key_path_str, val):
# Add key_path_str/val to saved batch edits
else:
if trace_index not in self._batch_trace_edits:
self._batch_trace_edits[trace_index] = {}
self._batch_trace_edits[trace_index] = OrderedDict()
self._batch_trace_edits[trace_index][key_path_str] = val

def _normalize_trace_indexes(self, trace_indexes):
Expand Down
17 changes: 17 additions & 0 deletions plotly/tests/test_core/test_graph_objs/test_layout_subplots.py
Expand Up @@ -208,3 +208,20 @@ def test_create_subplot_with_update_dict(self):
self.assertEqual(self.layout.scene6.dragmode, 'zoom')
self.assertEqual(self.layout.mapbox7.zoom, 2)
self.assertEqual(self.layout.polar8.sector, (0, 90))

def test_bug_1462(self):
# https: // github.com / plotly / plotly.py / issues / 1462
fig = go.Figure(data=[
go.Scatter(x=[1, 2], y=[1, 2], xaxis='x'),
go.Scatter(x=[2, 3], y=[2, 3], xaxis='x2')])

layout_dict = {
'grid': {'xaxes': ['x', 'x2'], 'yaxes': ['y']},
# 'xaxis': {'title': 'total_bill'},
'xaxis2': {'matches': 'x', 'title': {'text': 'total_bill'}}
}

fig.update(layout=layout_dict)
updated_layout_dict = fig.layout.to_plotly_json()

self.assertEqual(updated_layout_dict, layout_dict)