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

improve feedback to user with "." in column #3451

Open
Sprocketer opened this issue Jun 30, 2024 · 6 comments
Open

improve feedback to user with "." in column #3451

Sprocketer opened this issue Jun 30, 2024 · 6 comments
Labels

Comments

@Sprocketer
Copy link

Sprocketer commented Jun 30, 2024

What happened?

Had a pandas dataframe with columns with "." (without quotes) in name (was using a string of a floating point number as part of a key name). Tried to plot, nothing shows up. 2 hours of debugging later realised that if you truncate the numbers to before the "." then it works fine.

What would you like to happen instead?

Columns should properly plot

P.S. - not 100% if this is an Altair-specific problem or a Vega-lite problem - I have no clue how to replicate 100% accurately there. This should be easily reproducible though anyways.

Which version of Altair are you using?

5.3.0

@Sprocketer Sprocketer added the bug label Jun 30, 2024
@Sprocketer Sprocketer changed the title Columns with "." (without quotes) in dataframe don't plot Columns with "." in dataframe don't plot Jun 30, 2024
@mattijn
Copy link
Contributor

mattijn commented Jun 30, 2024

Thanks for raising. You will have to escape special characters in Altair or replace them, see https://altair-viz.github.io/user_guide/encodings/index.html#escaping-special-characters-in-column-names

@mattijn mattijn closed this as completed Jun 30, 2024
@Sprocketer
Copy link
Author

Thanks for raising. You will have to escape special characters in Altair or replace them, see https://altair-viz.github.io/user_guide/encodings/index.html#escaping-special-characters-in-column-names

@mattijn Alright sure - but this should 100% have its own error message. It would be as simple as just checking the column names for special characters and then raising an error if there are any. Would save tons of time for I imagine lots of people who might run in to this

@Sprocketer
Copy link
Author

@mattijn If you don't mind it'd be good to reopen or make a new issue for making an error message for this - would be super useful
Also, you could mention in the docs how you can use U+2024 (․) instead of U+002E (.) to bypass this for full stops / periods

@mattijn mattijn changed the title Columns with "." in dataframe don't plot improve feedback to user with "." in column Jun 30, 2024
@mattijn mattijn reopened this Jun 30, 2024
@mattijn
Copy link
Contributor

mattijn commented Jun 30, 2024

Always open for ideas to improve the user experience, see also #2824

@Sprocketer
Copy link
Author

Also just making clear the error message should be for all special characters not just "." - thank you for the help!

@mattijn
Copy link
Contributor

mattijn commented Jun 30, 2024

If you have a clear approach in mind to improve this, please feel free to contribute.
Keep in mind that these special characters are used to access nested attributes within the data. For example:

import pandas as pd
import altair as alt

df = pd.DataFrame(data=[
    {"type": "Feature", "properties": {"location": "left"}, "geometry": {"type": "Polygon", "coordinates": [[[1.45, 3.75], [1.45, 0], [0, 0], [1.45, 3.75]]]}},
    {"type": "Feature", "properties": {"location": "middle-left"}, "geometry": {"type": "Polygon", "coordinates": [[[1.45, 0], [1.45, 3.75], [2.57, 3.75], [2.57, 0], [2.33, 0], [1.45, 0]]]}},
    {"type": "Feature", "properties": {"location": "middle-right"}, "geometry": {"type": "Polygon", "coordinates": [[[2.33, 0], [2.33, 2.5], [3.47, 2.5], [3.47, 0], [3.2, 0], [2.57, 0], [2.33, 0]]]}},
    {"type": "Feature", "properties": {"location": "right"}, "geometry": {"type": "Polygon", "coordinates": [[[3.2, 0], [3.2, 1.25], [4.32, 1.25], [4.32, 0], [3.47, 0], [3.2, 0]]]}}
])
df

image

alt.Chart(df).mark_geoshape().encode(
    alt.Color("properties.location:O").scale(scheme='magma')
).project(type="identity", reflectY=True)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants