I found this issue when working through Chapter 3 of the "R for Data Science" book (using plotnine). I was working within a Jupyter notebook, using Python 3.6.
%matplotlib inline from plotnine import * from plotnine.data import * ggplot(data=mpg) + geom_point(mapping=aes(x='displ', y='hwy')) + facet_wrap('~class')
I get the interesting error:
File "", line 1
class
^
SyntaxError: unexpected EOF while parsing
Replacing '~class' with '~cyl' gives me a lovely plot, and no error.
To see if Jupyter was contributing to the problem, I created a simple script:
# foo.py from plotnine import * from plotnine.data import * (ggplot(data=mpg) + geom_point(mapping=aes(x='displ', y='hwy')) + facet_wrap('~class')).save('foo.png')
I get a somewhat more involved traceback, but essentially the same error:
$ python foo.py
/home/grant/Envs/py36/lib64/python3.6/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools
Traceback (most recent call last):
File "foo.py", line 5, in
+ facet_wrap('~class')).save('foo.png')
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/ggplot.py", line 571, in save
raise err
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/ggplot.py", line 568, in save
_save()
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/ggplot.py", line 533, in _save
fig = figure[0] = self.draw()
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/ggplot.py", line 141, in draw
self._build()
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/ggplot.py", line 222, in _build
layout.setup(layers, self)
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/facets/layout.py", line 59, in setup
self.layout = self.facet.compute_layout(data)
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/facets/facet_wrap.py", line 73, in compute_layout
self.vars, drop=self.drop)
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/facets/facet.py", line 519, in combine_vars
for df in data if df is not None]
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/facets/facet.py", line 519, in
for df in data if df is not None]
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/plotnine/facets/facet.py", line 630, in eval_facet_vars
res = env.eval(name, inner_namespace=data)
File "/home/grant/Envs/py36/lib64/python3.6/site-packages/patsy/eval.py", line 164, in eval
code = compile(expr, source_name, "eval", self.flags, False)
File "", line 1
class
^
SyntaxError: unexpected EOF while parsing
Again, if I replace facet_wrap('~class') with facet_wrap('~cyl'), I get a lovely plot and no error.
I'm really looking forward to using plotnine (and finally learning ggplot). Thanks for all of your hard work!