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

Availability of geometries for 2008 and 2009 #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion pygris/enumeration_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Kyle Walker <[email protected]"

from .helpers import _load_tiger, validate_state, validate_county, fips_codes
from .helpers import _load_tiger, validate_state, validate_county, fips_codes, get_state_name
import pandas as pd

def counties(state = None, cb = False, resolution = '500k', year = None, cache = False, subset_by = None):
Expand Down Expand Up @@ -181,6 +181,9 @@ def tracts(state = None, county = None, cb = False, year = None, cache = False,
elif year in [2000, 2010]:
suf = str(year)[2:]
url = f"https://www2.census.gov/geo/tiger/TIGER2010/TRACT/{year}/tl_2010_{state}_tract{suf}.zip"
elif year in [2008, 2009]:
state_name = get_state_name(state).upper().replace(' ', '_')
url = f"https://www2.census.gov/geo/tiger/TIGER{year}/{state}_{state_name}/tl_{year}_{state}_tract00.zip"
else:
url = f"https://www2.census.gov/geo/tiger/TIGER{year}/TRACT/tl_{year}_{state}_tract.zip"

Expand Down
22 changes: 22 additions & 0 deletions pygris/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ def validate_state(state, quiet = False):
print(f"Using FIPS code '{state_fips}' for input '{original_input}'")

return state_fips

def get_state_name(state, quiet = False):
# Standardize as lowercase
original_input = state
state = state.lower()
# Get rid of whitespace
state = state.strip()

# Get the FIPS codes dataset
fips = fips_codes()
# If a state name, grab the appropriate info from fips_codes
state_sub = fips.query('state_code == @state')

if state_sub.shape[0] == 0:
raise ValueError("You have likely entered an invalid state code, please revise.")
else:
state_name = state_sub.state_name.unique()[0]

if not quiet:
print(f"Using state name '{state_name}' for input '{original_input}'")

return state_name


def validate_county(state, county, quiet = False):
Expand Down