Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove python-us dependency #386

Merged
merged 2 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 65 additions & 5 deletions lux/vislib/altair/Choropleth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from lux.vislib.altair.AltairChart import AltairChart
import altair as alt
import us
import pandas as pd
from iso3166 import countries

alt.data_transformers.disable_max_rows()
Expand Down Expand Up @@ -148,12 +148,72 @@ def get_geomap(self, feature):

def get_us_fips_code(self, attribute):
"""Returns FIPS code given a US state"""
usa = pd.DataFrame(
[
{"fips": 1, "state": "alabama", "abbrev": "al"},
{"fips": 2, "state": "alaska", "abbrev": "ak"},
{"fips": 4, "state": "arizona", "abbrev": "az"},
{"fips": 5, "state": "arkansas", "abbrev": "ar"},
{"fips": 6, "state": "california", "abbrev": "ca"},
{"fips": 8, "state": "colorado", "abbrev": "co"},
{"fips": 9, "state": "connecticut", "abbrev": "ct"},
{"fips": 10, "state": "delaware", "abbrev": "de"},
{"fips": 11, "state": "district of columbia", "abbrev": "dc"},
{"fips": 12, "state": "florida", "abbrev": "fl"},
{"fips": 13, "state": "georgia", "abbrev": "ga"},
{"fips": 15, "state": "hawaii", "abbrev": "hi"},
{"fips": 16, "state": "idaho", "abbrev": "id"},
{"fips": 17, "state": "illinois", "abbrev": "il"},
{"fips": 18, "state": "indiana", "abbrev": "in"},
{"fips": 19, "state": "iowa", "abbrev": "ia"},
{"fips": 20, "state": "kansas", "abbrev": "ks"},
{"fips": 21, "state": "kentucky", "abbrev": "ky"},
{"fips": 22, "state": "louisiana", "abbrev": "la"},
{"fips": 23, "state": "maine", "abbrev": "me"},
{"fips": 24, "state": "maryland", "abbrev": "md"},
{"fips": 25, "state": "massachusetts", "abbrev": "ma"},
{"fips": 26, "state": "michigan", "abbrev": "mi"},
{"fips": 27, "state": "minnesota", "abbrev": "mn"},
{"fips": 28, "state": "mississippi", "abbrev": "ms"},
{"fips": 29, "state": "missouri", "abbrev": "mo"},
{"fips": 30, "state": "montana", "abbrev": "mt"},
{"fips": 31, "state": "nebraska", "abbrev": "ne"},
{"fips": 32, "state": "nevada", "abbrev": "nv"},
{"fips": 33, "state": "new hampshire", "abbrev": "nh"},
{"fips": 34, "state": "new jersey", "abbrev": "nj"},
{"fips": 35, "state": "new mexico", "abbrev": "nm"},
{"fips": 36, "state": "new york", "abbrev": "ny"},
{"fips": 37, "state": "north carolina", "abbrev": "nc"},
{"fips": 38, "state": "north dakota", "abbrev": "nd"},
{"fips": 39, "state": "ohio", "abbrev": "oh"},
{"fips": 40, "state": "oklahoma", "abbrev": "ok"},
{"fips": 41, "state": "oregon", "abbrev": "or"},
{"fips": 42, "state": "pennsylvania", "abbrev": "pa"},
{"fips": 44, "state": "rhode island", "abbrev": "ri"},
{"fips": 45, "state": "south carolina", "abbrev": "sc"},
{"fips": 46, "state": "south dakota", "abbrev": "sd"},
{"fips": 47, "state": "tennessee", "abbrev": "tn"},
{"fips": 48, "state": "texas", "abbrev": "tx"},
{"fips": 49, "state": "utah", "abbrev": "ut"},
{"fips": 50, "state": "vermont", "abbrev": "vt"},
{"fips": 51, "state": "virginia", "abbrev": "va"},
{"fips": 53, "state": "washington", "abbrev": "wa"},
{"fips": 54, "state": "west virginia", "abbrev": "wv"},
{"fips": 55, "state": "wisconsin", "abbrev": "wi"},
{"fips": 56, "state": "wyoming", "abbrev": "wy"},
]
)
attribute = attribute.lower()
if not isinstance(attribute, str):
return attribute
try:
return int(us.states.lookup(attribute).fips)
except:
return attribute
match = usa[(usa.state == attribute) | (usa.abbrev == attribute)]
if len(match) == 1:
return match["fips"].values[0]
else:
if attribute in ["washington d.c.", "washington dc", "d.c.", "d.c"]:
return 11
else:
return attribute

def get_country_iso_code(self, attribute):
"""Returns country ISO code given a country"""
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ pandas>=1.2.0
scikit-learn>=0.22
matplotlib>=3.0.0
lux-widget>=0.1.4
us
iso3166