Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d06f31b

Browse filesBrowse files
authored
Make update methods return self to support update chaining (plotly#1383)
1 parent bd50b4a commit d06f31b
Copy full SHA for d06f31b

File tree

Expand file treeCollapse file tree

2 files changed

+12
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-5
lines changed

‎plotly/basedatatypes.py

Copy file name to clipboardExpand all lines: plotly/basedatatypes.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,6 +3023,8 @@ def update(self, dict1=None, **kwargs):
30233023
BaseFigure._perform_update(self, dict1)
30243024
BaseFigure._perform_update(self, kwargs)
30253025

3026+
return self
3027+
30263028
@property
30273029
def _in_batch_mode(self):
30283030
"""

‎plotly/tests/test_core/test_graph_objs/test_update.py

Copy file name to clipboardExpand all lines: plotly/tests/test_core/test_graph_objs/test_update.py
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,40 @@ def setUp(self):
1515
def test_update_dict(self):
1616
title = 'this'
1717
fig = Figure()
18-
fig.update(layout=Layout(title=title))
18+
update_res1 = fig.update(layout=Layout(title=title))
1919
assert fig == Figure(layout=Layout(title=title))
20-
fig['layout'].update(xaxis=XAxis())
20+
update_res2 = fig['layout'].update(xaxis=XAxis())
2121
assert fig == Figure(layout=Layout(title=title, xaxis=XAxis()))
22+
assert update_res1 is fig
23+
assert update_res2 is fig.layout
2224

2325

2426
def test_update_list(self):
2527
trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2])
2628
trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1])
2729
fig = Figure([trace1, trace2])
2830
update = dict(x=[2, 3, 4], y=[1, 2, 3])
29-
fig.data[0].update(update)
30-
fig.data[1].update(update)
31+
update_res1 = fig.data[0].update(update)
32+
update_res2 = fig.data[1].update(update)
3133

3234
d1, d2 = strip_dict_params(fig.data[0], Scatter(x=[2, 3, 4], y=[1, 2, 3]))
3335
assert d1 == d2
3436
d1, d2 = strip_dict_params(fig.data[1], Scatter(x=[2, 3, 4], y=[1, 2, 3]))
3537
assert d1 == d2
38+
assert update_res1 is fig.data[0]
39+
assert update_res2 is fig.data[1]
3640

3741

3842
def test_update_dict_empty(self):
3943
trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2])
4044
trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1])
4145
fig = Figure([trace1, trace2])
42-
fig.update({})
46+
update_res = fig.update({})
4347
d1, d2 = strip_dict_params(fig.data[0], Scatter(x=[1, 2, 3], y=[2, 1, 2]))
4448
assert d1 == d2
4549
d1, d2 = strip_dict_params(fig.data[1], Scatter(x=[1, 2, 3], y=[3, 2, 1]))
4650
assert d1 == d2
51+
assert update_res is fig
4752

4853

4954
def test_update_list_empty(self):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.