Skip to content

Commit 417fc6d

Browse files
authoredMay 27, 2019
In 'trace_uids' future mode, don't initialize trace uids for Figure (#1580)
But always initialize uids for FigureWidget traces
1 parent 2cc3727 commit 417fc6d

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed
 

Diff for: ‎_plotly_future_/trace_uids.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from __future__ import absolute_import
2+
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3+
4+
_assert_plotly_not_imported()
5+
_future_flags.add('trace_uids')

Diff for: ‎_plotly_future_/v4.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
remove_deprecations,
77
v4_subplots,
88
orca_defaults,
9+
trace_uids,
910
)
1011

Diff for: ‎plotly/basedatatypes.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from plotly.utils import ElidedPrettyPrinter
2727
from .validators import (DataValidator, LayoutValidator, FramesValidator)
2828

29+
from _plotly_future_ import _future_flags
30+
2931
# Create Undefined sentinel value
3032
# - Setting a property to None removes any existing value
3133
# - Setting a property to Undefined leaves existing value unmodified
@@ -49,6 +51,8 @@ class BaseFigure(object):
4951
'plot_bgcolor': 'plot-bgcolor'
5052
}
5153

54+
_set_trace_uid = 'trace_uids' not in _future_flags
55+
5256
# Constructor
5357
# -----------
5458
def __init__(self,
@@ -145,7 +149,7 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
145149
# ### Construct data validator ###
146150
# This is the validator that handles importing sequences of trace
147151
# objects
148-
self._data_validator = DataValidator(set_uid=True)
152+
self._data_validator = DataValidator(set_uid=self._set_trace_uid)
149153

150154
# ### Import traces ###
151155
data = self._data_validator.validate_coerce(data,
@@ -513,9 +517,9 @@ def data(self, new_data):
513517

514518
# Validate new_data
515519
# -----------------
516-
err_header = ('The data property of a figure may only be assigned '
520+
err_header = ('The data property of a figure may only be assigned \n'
517521
'a list or tuple that contains a permutation of a '
518-
'subset of itself\n')
522+
'subset of itself.\n')
519523

520524
# ### Check valid input type ###
521525
if not isinstance(new_data, (list, tuple)):
@@ -531,16 +535,14 @@ def data(self, new_data):
531535
.format(typ=type(trace)))
532536
raise ValueError(err_msg)
533537

534-
# ### Check UIDs ###
535-
# Require that no new uids are introduced
536-
orig_uids = [_trace['uid'] for _trace in self._data]
537-
new_uids = [trace.uid for trace in new_data]
538+
# ### Check trace objects ###
539+
# Require that no new traces are introduced
540+
orig_uids = [id(trace) for trace in self.data]
541+
new_uids = [id(trace) for trace in new_data]
538542

539543
invalid_uids = set(new_uids).difference(set(orig_uids))
540544
if invalid_uids:
541-
err_msg = (
542-
err_header + ' Invalid trace(s) with uid(s): {invalid_uids}'
543-
.format(invalid_uids=invalid_uids))
545+
err_msg = err_header
544546

545547
raise ValueError(err_msg)
546548

@@ -551,8 +553,7 @@ def data(self, new_data):
551553
]
552554
if duplicate_uids:
553555
err_msg = (
554-
err_header + ' Received duplicated traces with uid(s): ' +
555-
'{duplicate_uids}'.format(duplicate_uids=duplicate_uids))
556+
err_header + ' Received duplicated traces')
556557

557558
raise ValueError(err_msg)
558559

@@ -562,8 +563,8 @@ def data(self, new_data):
562563
delete_inds = []
563564

564565
# ### Unparent removed traces ###
565-
for i, _trace in enumerate(self._data):
566-
if _trace['uid'] in remove_uids:
566+
for i, trace in enumerate(self.data):
567+
if id(trace) in remove_uids:
567568
delete_inds.append(i)
568569

569570
# Unparent trace object to be removed
@@ -575,7 +576,7 @@ def data(self, new_data):
575576
# ### Compute trace props / defaults after removal ###
576577
traces_props_post_removal = [t for t in self._data]
577578
traces_prop_defaults_post_removal = [t for t in self._data_defaults]
578-
uids_post_removal = [trace_data['uid'] for trace_data in self._data]
579+
uids_post_removal = [id(trace_data) for trace_data in self.data]
579580

580581
for i in reversed(delete_inds):
581582
del traces_props_post_removal[i]

Diff for: ‎plotly/basewidget.py

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class BaseFigureWidget(BaseFigure, widgets.DOMWidget):
113113
_last_layout_edit_id = Integer(0).tag(sync=True)
114114
_last_trace_edit_id = Integer(0).tag(sync=True)
115115

116+
_set_trace_uid = True
117+
116118
# Constructor
117119
# -----------
118120
def __init__(self,

0 commit comments

Comments
 (0)
Please sign in to comment.