You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
plotnine's color aesthetic accepts NA-like values. In this case, NAs are colored grey, and sometimes there are special scale arguments to change the color of NA values, etc..
However, if a None is passed directly to aes, it raises an error:
# Works ----# could also replace pd.Series(...) with np.nan, pd.NA, etc..
(
ggplot(mpg2, aes("displ", "hwy", color=pd.Series([None])))
+geom_point()
)
# Raises error ----
(
ggplot(mpg2, aes("displ", "hwy", color=None))
+geom_point()
)
Error:
File [~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:463](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:463), inLayers.compute_aesthetics(self, plot)
[461](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:461) defcompute_aesthetics(self, plot: ggplot):
[462](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:462) forlinself:
--> [463](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:463) l.compute_aesthetics(plot)
File [~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:260](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:260), inlayer.compute_aesthetics(self, plot)
[253](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:253) defcompute_aesthetics(self, plot: ggplot):
[254](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:254) """ [255](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:255) Return a dataframe where the columns match the aesthetic mappings [256](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:256) [257](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:257) Transformations like 'factor(cyl)' and other [258](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:258) expression evaluation are made in here [259](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:259) """--> [260](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:260) evaled=evaluate(self.mapping._starting, self.data, plot.environment)
[261](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:261) evaled_aes=aes(**{str(col): colforcolinevaled})
[262](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/layer.py:262) plot.scales.add_defaults(evaled, evaled_aes)
File [~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/mapping/evaluation.py:251](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/mapping/evaluation.py:251), inevaluate(aesthetics, data, env)
[249](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/mapping/evaluation.py:249) else:
[250](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/mapping/evaluation.py:250) msg=f"Do not know how to deal with aesthetic '{ae}'"--> [251](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/mapping/evaluation.py:251) raisePlotnineError(msg)
[253](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/mapping/evaluation.py:253) # Using `type` preserves the subclass of pd.DataFrame
[254](https://file+.vscode-resource.vscode-cdn.net/Users/machow/repos/plotnine-guide/~/.virtualenvs/plotnine-guide/lib/python3.9/site-packages/plotnine/mapping/evaluation.py:254) index=data.indexiflen(data.index) andevaledelseNonePlotnineError: "Do not know how to deal with aesthetic 'color'"
Note on None in other aesthetics
It looks like passing a None directly to an aesthetic mapping doesn't work for other aesthetics (e.g. aes(shape=None)). But this seems like it would be highly unusual for people to do.
The text was updated successfully, but these errors were encountered:
plotnine's color aesthetic accepts NA-like values. In this case, NAs are colored grey, and sometimes there are special scale arguments to change the color of NA values, etc..
However, if a None is passed directly to aes, it raises an error:
Error:
Note on None in other aesthetics
It looks like passing a None directly to an aesthetic mapping doesn't work for other aesthetics (e.g.
aes(shape=None)
). But this seems like it would be highly unusual for people to do.The text was updated successfully, but these errors were encountered: