vega-lite: plotting a column name with '.' in it eventually leads to a vega error
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.)
undefined:3
return x["gpuinfo"]["name"];
^
TypeError: Cannot read property 'name' of undefined
at Object.eval [as get] (eval at <anonymous> (/Users/jowens/Documents/working/vega/node_modules/datalib/src/util.js:147:20), <anonymous>:3:20)
at Facetor.proto._cellkey (/Users/jowens/Documents/working/vega/node_modules/datalib/src/aggregate/aggregator.js:106:23)
at Facetor.proto._cell (/Users/jowens/Documents/working/vega/node_modules/datalib/src/aggregate/aggregator.js:114:38)
at Facetor.proto._add (/Users/jowens/Documents/working/vega/node_modules/datalib/src/aggregate/aggregator.js:151:19)
at add (/Users/jowens/Documents/working/vega/src/transforms/Aggregate.js:174:31)
at Array.forEach (native)
at Aggregate.prototype.transform (/Users/jowens/Documents/working/vega/src/transforms/Aggregate.js:190:13)
at Aggregate.prototype.evaluate (/Users/jowens/Documents/working/vega/src/transforms/Transform.js:48:15)
at Node.dataRef (/Users/jowens/Documents/working/vega/src/scene/Scale.js:387:15)
at Node.ordinal (/Users/jowens/Documents/working/vega/src/scene/Scale.js:127:20)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (9 by maintainers)
I found some related issues in Vega 3, and just published an updated version of vega-util that resolves them. By default, Vega will try to parse field names like
"a.a"into nested lookups (datum['a']['a']). However, you can indicate non-nested field names by wrapping the name in brackets. For example, the field names[a.a]and['a.a']will both map todatum['a.a']. It is also legal to use escape characters:a\\.a->datum['a.a'].If you are referring to such fields within an expression, simply use standard JavaScript bracket notation:
datum['a.a'].Vega-Lite probably needs to perform a check to see if the
.character is in the field name, and if so, wrap the field name in brackets.@willium this toy spec should (WIP) work:
@jowens still doesn’t work. For debugging purpose.