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.

ENH: Build vega_datasets into altair?

See original GitHub issue

This is something that @palewire mentioned a while ago, and the idea has been growing on me.

Currently, many of our examples are like this:

import altair as alt
from vega_datasets import data

cars = data.cars()
alt.Chart(cars)...

What if we were to import vega_datasets into Altair’s namespace by default, so instead it would be

import altair as alt

cars = alt.datasets.cars()
alt.Chart(cars)...

The advantage is fewer imports and less boilerplate.

A minor disadvantage is that vega_datasets would become a hard requirement for Altair (unless we did some kind of lazy import mechanism, which would add complication).

A more major disadvantage is that it would obscure the fact that vega_datasets is a separate package, rather than a part of Altair, which might confuse people.

Thoughts?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:24 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
jakevdpcommented, May 3, 2018

I really appreciate everyone weighing in here. Overall, I think the key points on either side are:

Pros

  • fewer imports would lead to an easier learning curve for beginners
  • even beyond beginners, some datasets (e.g. geoshape data for choropleth maps) would be useful to have more readily available/built-in to the Altair API

Cons

  • more hard dependencies could add friction for companies hoping to use Altair
  • marginally larger installation footprint (200KB)
  • obscuring the existence of the vega_datasets package makes it less clear how to debug issues that arise, particularly for beginners

With those in mind, how about a compromise: make vega_datasets a soft requirement accessible from the Altair namespace. We could add a datasets object at the top-level of the module which provides access to everything in vega-datasets (if it is installed) and raises an informative error (if it is not). I’d imagine something like this:

# in altair/__init__.py

class VegaDatasetsUnavailable(object):
    def __getattr__(self, attr):
        raise ImportError("To use datasets in Altair requires installing the vega_datasets package: "
                          "See https://github.com/altair-viz/vega_datasets")
    __call__ = __getattr__

try:
    from vega_datasets import data as datasets
except ImportError:
    datasets = VegaDatasetsUnavailable()

Then the hard dependencies of Altair would not change, but it would make the following available to users who do have vega_datasets installed:

import altair as alt
cars = alt.datasets.cars()
alt.Chart(cars).mark_point()#etc.

If vega_datasets is installed, this will work as expected. If not, it will give the user an informative error.

We could then adjust all our “getting started” installation instructions to include installation of vega_datasets (as they probably already should).

1reaction
jakevdpcommented, May 8, 2018

The more I think about it, the more I like the compromise I mentioned above, particularly as I develop the Altair tutorial.

After PyCon, I’m going to look at implementing this unless people have objections (@ellisonbg – I’d love to hear your thoughts)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installation — Altair 4.2.0 documentation
Installation . Altair can be installed, along with the example datasets in vega_datasets, using: $ pip install altair vega_datasets.
Read more >
Learning Observable Plot via Altair / Eitan Lees
Before we make any plots we need data. Most of the Altair examples utilize the Vega Datasets repository, which can easily be integrated...
Read more >
Taking Data Visualization to Another Level | HackerNoon
Altair is a declarative statistical visualization library and it is based on Vega and Vega-Lite. Altair enables you to build a wide range...
Read more >
Altair Python Vega Dataset Example | How to Install Altair
Learn how to install Altair, work with vega datasetsinstall Altair ViewerWork with the vega dataset. Altair charts like bar charts, ...
Read more >
Enhancement Shaman DPS Spec, Builds, and Talents
Find out the best talents in each tier for your Enhancement Shaman in WoW Dragonflight 10.0.2.
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