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

BUG: properly propagate context in multiply-specified encodings #1587

Merged
merged 2 commits into from
Jul 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: 1 addition & 1 deletion altair/vegalite/v2/schema/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def to_dict(self, validate=True, ignore=(), context=None):
# If given a list of shorthands, then transform it to a list of classes
kwds = self._kwds.copy()
kwds.pop('shorthand')
return [self.__class__(shorthand, **kwds).to_dict()
return [self.__class__(shorthand, **kwds).to_dict(validate=validate, ignore=ignore, context=context)
for shorthand in self.shorthand]
elif isinstance(self.shorthand, six.string_types):
kwds = parse_shorthand(self.shorthand, data=context.get('data', None))
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v3/schema/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def to_dict(self, validate=True, ignore=(), context=None):
# If given a list of shorthands, then transform it to a list of classes
kwds = self._kwds.copy()
kwds.pop('shorthand')
return [self.__class__(shorthand, **kwds).to_dict()
return [self.__class__(shorthand, **kwds).to_dict(validate=validate, ignore=ignore, context=context)
for shorthand in self.shorthand]
elif isinstance(self.shorthand, six.string_types):
kwds = parse_shorthand(self.shorthand, data=context.get('data', None))
Expand Down
43 changes: 23 additions & 20 deletions altair/vegalite/v3/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
selenium = None


def getargs(*args, **kwargs):
return args, kwargs


OP_DICT = {
'layer': operator.add,
'hconcat': operator.or_,
Expand Down Expand Up @@ -111,28 +115,27 @@ def _check_encodings(chart):
assert dct['encoding']['y']['type'] == 'ordinal'


def test_multiple_encodings():
@pytest.mark.parametrize('args, kwargs', [
getargs(detail=['value:Q', 'name:N'], tooltip=['value:Q', 'name:N']),
getargs(detail=['value', 'name'], tooltip=['value', 'name']),
getargs(alt.Detail(['value:Q', 'name:N']), alt.Tooltip(['value:Q', 'name:N'])),
getargs(alt.Detail(['value', 'name']), alt.Tooltip(['value', 'name'])),
getargs([alt.Detail('value:Q'), alt.Detail('name:N')],
[alt.Tooltip('value:Q'), alt.Tooltip('name:N')]),
getargs([alt.Detail('value'), alt.Detail('name')],
[alt.Tooltip('value'), alt.Tooltip('name')]),
])
def test_multiple_encodings(args, kwargs):
df = pd.DataFrame({
'value': [1, 2, 3],
'name': ['A', 'B', 'C'],
})
encoding_dct = [{'field': 'value', 'type': 'quantitative'},
{'field': 'name', 'type': 'nominal'}]
chart1 = alt.Chart('data.csv').mark_point().encode(
detail=['value:Q', 'name:N'],
tooltip=['value:Q', 'name:N']
)

chart2 = alt.Chart('data.csv').mark_point().encode(
alt.Detail(['value:Q', 'name:N']),
alt.Tooltip(['value:Q', 'name:N'])
)

chart3 = alt.Chart('data.csv').mark_point().encode(
[alt.Detail('value:Q'), alt.Detail('name:N')],
[alt.Tooltip('value:Q'), alt.Tooltip('name:N')]
)

for chart in [chart1, chart2, chart3]:
dct = chart.to_dict()
assert dct['encoding']['detail'] == encoding_dct
assert dct['encoding']['tooltip'] == encoding_dct
chart = alt.Chart(df).mark_point().encode(*args, **kwargs)
dct = chart.to_dict()
assert dct['encoding']['detail'] == encoding_dct
assert dct['encoding']['tooltip'] == encoding_dct


def test_chart_operations():
Expand Down
2 changes: 1 addition & 1 deletion tools/generate_schema_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def to_dict(self, validate=True, ignore=(), context=None):
# If given a list of shorthands, then transform it to a list of classes
kwds = self._kwds.copy()
kwds.pop('shorthand')
return [self.__class__(shorthand, **kwds).to_dict()
return [self.__class__(shorthand, **kwds).to_dict(validate=validate, ignore=ignore, context=context)
for shorthand in self.shorthand]
elif isinstance(self.shorthand, six.string_types):
kwds = parse_shorthand(self.shorthand, data=context.get('data', None))
Expand Down