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.

Include clearer warning regarding about preferred data input

See original GitHub issue

As a new user of altair I’ve been regularly surprised/confused by the preferred data format being pandas. Gradually I’ve gotten the hang of it, but it would be really great if the warning message that describes altair not supporting JSON was a little bit clearer (or if json was supported (maybe it is I am a new user?)).

For instance this innocous code chunk


alt.Chart(
  [{"x": 1, "y": 2}, {"x": 2, "y": 3}, {"x": 3, "y": 1}]
).mark_circle(
  size=50, color='steelblue', opacity=1
).encode(
  x='x',
  y='y',
)

yields a pretty long error:

/usr/local/lib/python3.6/dist-packages/altair/vegalite/v3/api.py:97: UserWarning: data of type <class 'list'> not recognized
  warnings.warn("data of type {} not recognized".format(type(data)))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/altair/vegalite/v3/api.py in to_dict(self, *args, **kwargs)
    367 
    368         try:
--> 369             dct = super(TopLevelMixin, copy).to_dict(*args, **kwargs)
    370         except jsonschema.ValidationError:
    371             dct = None

8 frames
/usr/local/lib/python3.6/dist-packages/altair/vegalite/v3/schema/channels.py in to_dict(self, validate, ignore, context)
     46                                      "the type cannot be automatically inferred because "
     47                                      "the data is not specified as a pandas.DataFrame."
---> 48                                      "".format(self.shorthand))
     49         else:
     50             # Shorthand is not a string; we pass the definition to field,

ValueError: x encoding field is specified without a type; the type cannot be automatically inferred because the data is not specified as a pandas.DataFrame.
Chart({
  data: [{'x': 1, 'y': 2}, {'x': 2, 'y': 3}, {'x': 3, 'y': 1}],
  encoding: FacetedEncoding({
    x: X({
      shorthand: 'x'
    }),
    y: Y({
      shorthand: 'y'
    })
  }),
  mark: MarkDef({
    color: 'steelblue',
    opacity: 1,
    size: 50,
    type: 'circle'
  })
})

While it is true that the error lists “list” as unsupported, it would be cool if the error also included a hint on how to fix it (eg "list is unsupported, please use a pandas dataframe).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Jun 20, 2019

You can use JSON directly if you specify that the data are values:

alt.Chart(
  {'values': [{"x": 1, "y": 2}, {"x": 2, "y": 3}, {"x": 3, "y": 1}]}
).mark_circle(
  size=50, color='steelblue', opacity=1
).encode(
  x='x:Q',
  y='y:Q',
)

If you can think of a way that the warning and error shown in the output above could be made clearer, I’d happily review a pull request!

0reactions
mcnuttandrewcommented, Jun 21, 2019

Amazing!!! That was so quick!

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input>: The Input (Form Input) element - HTML
May include a delete icon in supporting browsers that can be used to clear the field. Displays a search icon instead of enter...
Read more >
Law Enforcement Solutions | CLEAR | Thomson Reuters
CLEAR for law enforcement · Use the most current data to ensure community safety · Access a single platform that delivers data you...
Read more >
Requesting access to location in the background
If your app uses location in the background, your privacy policy must contain appropriate related disclosures, reference location data, and provide information ...
Read more >
Fanuc 16i-18i-21i Data Input and Output Settings
After the parameters have been input, set PARAMETER WRITE on the SETTING screen to 0. ... Be sure that data output cannot be...
Read more >
Check Code for Errors and Warnings Using the Code Analyzer
The MATLAB ® Code Analyzer can automatically check your code for coding problems. You can view warning and error messages about your code,...
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