question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Javascript error when plotting a column with special characters

See original GitHub issue

The following code throws an error (tested with Altair 2.0.1):

import pandas
import altair
df = pandas.DataFrame({"A column name with 'quotes'" : [1, 2, 3, 4], "A column name without quotes" : [5, 6, 7, 8]})
altair.Chart(df).mark_bar().encode(
    altair.X(df.columns[0], bin=True),
    y='count()',
)

It fails with the error:

Javascript Error: Access path missing closing bracket: A column name with 'quotes'. This usually means there's a typo in your chart specification. See the JavaScript console for the full traceback.

This does not happen when using a column name without quotes (e.g., if I use df.columns[1] instead of df.columns[0]). If I put only one quote instead of two, the error is different:

Javascript Error: Access path missing closing quote: A column name with 'quotes. This usually means there's a typo in your chart specification. See the JavaScript console for the full traceback.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Jun 6, 2018

Because the escaped version of the field name does not match the pandas column name, Altair cannot infer the type of the column – so you’ll have to specify the type explicitly (just as you do when passing data by URL rather than by dataframe):

iris.columns = ['a', 'b[]', 'c.0', 'd', 'e']
alt.Chart(iris).mark_point().encode(
    x='a',
    y='c\\.0:Q'
)
1reaction
jakevdpcommented, May 23, 2018

I don’t think Altair should automatically escape quotes: the reason they need to be escaped is that they have special meaning within field strings when not escaped, and I would not want Altair to prevent that use.

I think it would be worth raising an appropriate warning when single quotes, double quotes, square brackets, dots, or back-slashes are used.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to translate special characters in Javascript - Stack Overflow
From your link I see this. let dataString = `Lot ID,Wafer_ID,Probe Count,Unit Number,X,Y,Head Number,Site Number,Die Pass/Fail,Hard Bin No ...
Read more >
Errors using special characters in Access databases - Office
Lists the special characters to avoid using when you work with the database object names or the field names in all versions of...
Read more >
Appearance of Grouped graphs - GraphPad Prism 9 User Guide
Select a data set from the list, and choose the symbols, lines, and error bars ... If you choose to plot your data...
Read more >
Visualization: Column Chart - Google Developers
Overview. A column chart is a vertical bar chart rendered in the browser using SVG or VML, whichever is appropriate for the user's...
Read more >
[Solved]-Unknown characters in column name-Pandas,Python
[Solved]-Unknown characters in column name-Pandas,Python ... You can pass encoding='utf-8' to read_csv as a kwarg so it decodes the BOM correctly. ... This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found