Skip to content

Make update methods return self to support update chaining #1383

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

Merged
merged 1 commit into from
Jan 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3023,6 +3023,8 @@ def update(self, dict1=None, **kwargs):
BaseFigure._perform_update(self, dict1)
BaseFigure._perform_update(self, kwargs)

return self

@property
def _in_batch_mode(self):
"""
Expand Down
15 changes: 10 additions & 5 deletions plotly/tests/test_core/test_graph_objs/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,40 @@ def setUp(self):
def test_update_dict(self):
title = 'this'
fig = Figure()
fig.update(layout=Layout(title=title))
update_res1 = fig.update(layout=Layout(title=title))
assert fig == Figure(layout=Layout(title=title))
fig['layout'].update(xaxis=XAxis())
update_res2 = fig['layout'].update(xaxis=XAxis())
assert fig == Figure(layout=Layout(title=title, xaxis=XAxis()))
assert update_res1 is fig
assert update_res2 is fig.layout


def test_update_list(self):
trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2])
trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1])
fig = Figure([trace1, trace2])
update = dict(x=[2, 3, 4], y=[1, 2, 3])
fig.data[0].update(update)
fig.data[1].update(update)
update_res1 = fig.data[0].update(update)
update_res2 = fig.data[1].update(update)

d1, d2 = strip_dict_params(fig.data[0], Scatter(x=[2, 3, 4], y=[1, 2, 3]))
assert d1 == d2
d1, d2 = strip_dict_params(fig.data[1], Scatter(x=[2, 3, 4], y=[1, 2, 3]))
assert d1 == d2
assert update_res1 is fig.data[0]
assert update_res2 is fig.data[1]


def test_update_dict_empty(self):
trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2])
trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1])
fig = Figure([trace1, trace2])
fig.update({})
update_res = fig.update({})
d1, d2 = strip_dict_params(fig.data[0], Scatter(x=[1, 2, 3], y=[2, 1, 2]))
assert d1 == d2
d1, d2 = strip_dict_params(fig.data[1], Scatter(x=[1, 2, 3], y=[3, 2, 1]))
assert d1 == d2
assert update_res is fig


def test_update_list_empty(self):
Expand Down