Skip to content

Commit

Permalink
Merge pull request #1525 from jakevdp/properties-data
Browse files Browse the repository at this point in the history
BUG: make it possible to pass data as a property
  • Loading branch information
jakevdp authored May 22, 2019
2 parents 6d33ed7 + 74a908d commit 0d191e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion altair/vegalite/v3/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ def properties(self, **kwargs):
# For backward compatibility with old selection interface.
setattr(copy, key, {val.name: val.selection})
else:
self.validate_property(key, val)
# Don't validate data, because it hasn't been processed.
if key != 'data':
self.validate_property(key, val)
setattr(copy, key, val)
return copy

Expand Down
8 changes: 8 additions & 0 deletions altair/vegalite/v3/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,11 @@ def test_repeat():
assert 'columns' not in dct2
assert dct2['spec']['encoding']['x']['field'] == {'repeat': 'row'}
assert dct2['spec']['encoding']['y']['field'] == {'repeat': 'column'}


def test_data_property():
data = pd.DataFrame({'x': [1, 2, 3], 'y': list('ABC')})
chart1 = alt.Chart(data).mark_point()
chart2 = alt.Chart().mark_point().properties(data=data)

assert chart1.to_dict() == chart2.to_dict()

0 comments on commit 0d191e7

Please sign in to comment.