vega/altair

Improve `alt.LookupData` docs

Chiusa

#2323 aperta il 20 ott 2020

 (5 commenti) (1 reazione) (0 assegnatari)Python (865 fork)github user discovery
documentationgood first issue

Metriche repository

Star
 (10.455 stelle)
Metriche merge PR
 (Merge medio 6g 9h) (4 PR mergiate in 30 g)

Descrizione

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.

Guida contributor