vega/altair

Improve `alt.LookupData` docs

Closed

#2,323 opened on Oct 20, 2020

 (5 comments) (1 reaction) (0 assignees)Python (865 forks)github user discovery
documentationgood first issue

Repository metrics

Stars
 (10,453 stars)
PR merge metrics
 (Avg merge 6d 9h) (4 merged PRs in 30d)

Description

Hi - I'm not 100% sure if this is an issue with tutorials, how altair handles lookups, or the vega-lite data referenced in tutorials.

I have been working through the Choropleth examples to build a county-level heatmap of data from the United States. One column of my data is the 5-digit FIPS code, encoded in the column id. This is used to map data to shapes drawn using

  counties = alt.topo_feature(data.us_10m.url, 'counties')
  alt.Chart(counties).mark_geoshape(
    alt.Color(alt.repeat("row"), type = "quantitative")
  ).transform_lookup(
    lookup="id",
    from_ = alt.LookupData(data=my_data, key="id", fields=["county_rate"])
)

However, id in dataframe my_data is encoded as a string rather than as an integer. This means that running this without converting the column to an integer type means that counties with ids that have zero padding in front of them (so Alabama, California, Arkansas) the lookup fails.

The problem, from my perspective, is that the lookup doesn't fail for non-zero padded codes. Figuring out why the state of California wasn't showing up took a fair amount of guesswork, as it's not obvious for a beginner at this as to how to debug the lookup from the url data sources used in the tutorial.

I'm filling out this issue for three reasons:

  1. So that other people encountering this issue might find it.

  2. As a feature request: to suggest that it might be useful to be able to view a sample of what the alt.Lookup is matching on and that it might be useful to have an error or a "strict" type checking flag for performing lookups.

  3. As a suggestion about documentation.

As for reason 2, I realize there may be good reasons not to not have either however I just want to raise the possibility.

Contributor guide