altair-viz / altair_notebooks

Tutorial and Examples Jupyter Notebooks for Altair
BSD 3-Clause "New" or "Revised" License
221 stars 93 forks source link

Layered charts notebook not working #1

Closed synw closed 6 years ago

synw commented 6 years ago

The layered chart fails to render in the notebook 7 at input [17] giving an error:

'LayeredChart' object has no attribute 'encoding'

[Edit]: using Altair 1.2.1

Traceback:

AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/dataenv/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    962                 d['include'] = include
    963                 d['exclude'] = exclude
--> 964                 return method(**d)
    965             return None
    966         else:

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/altair/v1/api.py in _repr_mimebundle_(self, include, exclude, **kwargs)
     80 def _repr_mimebundle_(self, include, exclude, **kwargs):
     81     """Return a MIME-bundle for rich display in the Jupyter Notebook."""
---> 82     spec = self.to_dict(validate_columns=True)
     83     bundle = create_vegalite_mime_bundle(spec)
     84     return bundle

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/altair/v1/api.py in to_dict(self, data, validate_columns)
    287             The JSON specification of the chart object.
    288         """
--> 289         dct = super(TopLevelMixin, self.clone()).to_dict(data=data, validate_columns=validate_columns)
    290         dct['$schema'] = schema.vegalite_schema_url
    291         return dct

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/altair/v1/schema/_interface/jstraitlets.py in to_dict(self, **kwargs)
    151     def to_dict(self, **kwargs):
    152         """Output a (nested) dict encoding the contents of this instance"""
--> 153         self._finalize(**kwargs)
    154         Visitor = self._converter_registry.get('to_dict', ToDict)
    155         return Visitor().visit(self, **kwargs)

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/altair/v1/api.py in _finalize(self, **kwargs)
    503         # and the Chart allows it.
    504         if validate_columns and self.validate_columns:
--> 505             self._validate_columns()
    506 
    507     def _finalize_data(self):

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/altair/v1/api.py in _validate_columns(self)
    569             # Find columns with visual encodings
    570             encoded_columns = set()
--> 571             encoding = self.encoding
    572             if encoding is not jst.undefined:
    573                 for channel_name in encoding.channel_names:

AttributeError: 'LayeredChart' object has no attribute 'encoding'

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-ee0bf9ea2fe3> in <module>()
----> 1 chart

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/IPython/core/displayhook.py in __call__(self, result)
    255             self.start_displayhook()
    256             self.write_output_prompt()
--> 257             format_dict, md_dict = self.compute_format_data(result)
    258             self.update_user_ns(result)
    259             self.fill_exec_result(result)

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/IPython/core/displayhook.py in compute_format_data(self, result)
    149 
    150         """
--> 151         return self.shell.display_formatter.format(result)
    152 
    153     # This can be set to True by the write_output_prompt method in a subclass

~/anaconda3/envs/dataenv/lib/python3.6/site-packages/IPython/core/formatters.py in format(self, obj, include, exclude)
    148             return {}, {}
    149 
--> 150         format_dict, md_dict = self.mimebundle_formatter(obj, include=include, exclude=exclude)
    151 
    152         if format_dict or md_dict:

TypeError: 'NoneType' object is not iterable

Same output for the second chart.

Btw thanks for these notebooks: very useful!

jakevdp commented 6 years ago

Related to https://github.com/altair-viz/altair/issues/424

jakevdp commented 6 years ago

Fixed in v2