Skip to content

"[" Brackets can't appear in field name #219

@FlorianFritz

Description

@FlorianFritz

Description

Hi! I tried to generate a x-y-Line-Graph with altair from a pandas DataFrame with two columns named "Force in [N]" and "Travel in [inches]".

When I use the default altair renderer in a JupyterLab Notebook it fails with a Javascript error very similar to this bug report vega/vega-lite#8153

When I use the png renderer (which uses vl-convert) the graph does not render, just the canvas without a line.
Image

This is the SPEC: with_brackets.json

Excerpt of SPEC:

{
  // OMITTED //
  "encoding": {
    "x": {
      "field": "Travel in [inches]",
      "type": "quantitative"
    },
    "y": {
      "field": "Force in [N]",
      "type": "quantitative"
    }
  },
  // OMITTED //
}

When I remove all brackets the graph renders as expected. SPEC: without_brackets.json

Excerpt of SPEC:

{
  // EVERYTHING LIKE ABOVE //
  "encoding": {
    "x": {
      "field": "Travel in inches",
      "type": "quantitative"
    },
    "y": {
      "field": "Force in N",
      "type": "quantitative"
    }
  },
  // OMITTED //
}

Image

When I escape the brackets [ ] with \\[ and \\] in the encoding section (like mentioned in the vega-lite issue) the graph renders as expected but the axis labels contain one escaping backslash: Force in \[N\]

SPEC: with_brackets_escaped.json

Excerpt of SPEC:

{
  // EVERYTHING LIKE ABOVE //
  "encoding": {
    "x": {
      "field": "Travel in \\[inches\\]",
      "type": "quantitative"
    },
    "y": {
      "field": "Force in \\[N\\]",
      "type": "quantitative"
    }
  },
  // OMITTED //
}

Image

Used Versions

Sourcecode: VegaError.ipynb.txt

pandas 2.3.0
altair 5.5.0
vl_convert 1.7.0
RendererRegistry.enable('png')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions