-
Notifications
You must be signed in to change notification settings - Fork 795
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
plotting a column name with '.' in it eventually leads to a vega error #284
Comments
If open an issue in Vega-Lite. Altair has no control over these sorts of details. |
No prob. On it. |
Just for completeness sake here are the related vega-lite issues:
I think the relevant part from the first issue is: |
Altair currently (v2.X) is built on Vega-Lite 2 and Vega 3, so those fixes should work. |
I'm afraid that is not the case. Columns with a dot in it are not treated properly. Code to reproduce: import altair as alt
import pandas as pd
import numpy as np
df = pd.DataFrame({
"x.x": np.arange(10),
"x_x": np.arange(10),
})
# what you expect, a simple line
alt.Chart(df).mark_line().encode(x="x_x", y="x_x")
# this is an empty plot
alt.Chart(df).mark_line().encode(x="x.x", y="x.x") That being said, I have the js warning: |
This is expected: alt.Chart(df).mark_line().encode(x=r"x\.x:Q", y="x\.x:Q") This is true regardless of the Altair/Vega-Lite version you are using. For more information, see field under Encoding Channel Options |
I was aware of that. Thanks. (I assume y should also be an r-string?) I tried escaping the field names with the dot but it still produces an empty chart. import altair as alt
import pandas as pd
import numpy as np
df = pd.DataFrame({
"x.x": np.arange(10),
"x_x": np.arange(10),
})
(
alt.Chart(df).mark_line().encode(x=r"x\.x:Q", y=r"x\.x:Q") |
alt.Chart(df).mark_line().encode(x="x_x:Q", y="x_x:Q")
) |
That code works for me.
|
I installed everything via conda.
>>> import altair as alt
>>> print(alt.__version__)
2.3.0
>>>import vega
>>> print(vega.__version__)
1.4.0 If I'm not mistaken this is too old. I'll try with a clean conda env and get back to you. |
Wow, this is freaky. New conda env, same version of jupyter lab, altair, and vega. Now it works. Sorry for the noise! Thanks @jakevdp and great work with altair! Does altair offer an escape function that turns |
Great, glad you got it working. Regarding auto-escaping, there's no functionality built-in for that... it would be a useful feature to have. |
I'm doing an Altair chart with a color given by
color=Color('gpuinfo.name:N', ...
. This produces an eventual Vega error.(Why do I have a column with a period in its name? Reading nested JSONs into pandas is nicely handled by
json_normalize
, which flattens nested JSON levels into dot-separated column names.)The text was updated successfully, but these errors were encountered: