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

Issue #59 - Inflation Adjustment #157

Closed
wants to merge 3 commits into from
Closed
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
47 changes: 36 additions & 11 deletions geosnap/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DataStore(object):

def __init__(self):
"""Instantiate a new DataStore object."""
try: # if any of these aren't found, stream them insteead
try: # if any of these aren't found, stream them instead
from quilt3.data.census import tracts_cartographic, administrative
except ImportError:
warn(
Expand Down Expand Up @@ -94,7 +94,7 @@ def blocks_2000(self, states=None, convert=True):
Parameters
----------
states : list-like
list of state fips codes to return as a datafrrame.
list of state fips codes to return as a dataframe.
convert : bool
if True, return geodataframe, else return dataframe (the default is True).

Expand All @@ -107,7 +107,7 @@ def blocks_2000(self, states=None, convert=True):

"""

try: # if any of these aren't found, stream them insteead
try: # if any of these aren't found, stream them instead
from quilt3.data.census import blocks_2000
except ImportError:
warn(
Expand Down Expand Up @@ -148,7 +148,7 @@ def blocks_2010(self, states=None, convert=True):
Parameters
----------
states : list-like
list of state fips codes to return as a datafrrame.
list of state fips codes to return as a dataframe.
convert : bool
if True, return geodataframe, else return dataframe (the default is True).

Expand All @@ -160,7 +160,7 @@ def blocks_2010(self, states=None, convert=True):
stored as well-known binary on the 'wkb' column.

"""
try: # if any of these aren't found, stream them insteead
try: # if any of these aren't found, stream them instead
from quilt3.data.census import blocks_2010
except ImportError:
warn(
Expand Down Expand Up @@ -367,7 +367,7 @@ def ncdb(self):

Returns
-------
pandas.DataFrarme
pandas.DataFrame
NCDB as a long-form dataframe

"""
Expand Down Expand Up @@ -675,6 +675,31 @@ def store_ncdb(filepath):

df = df.set_index("geoid")

#### Beginning of New Code ####
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove these comments?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.


year = df["year"]

# Inflation logic for ncdb.
inflate_cols = [
"MDVALHS",
"MDGRENT",
"MDHHY",
]
# Five rows have missing ncdb labels in variables.csv.
# per capita income, missing
# median household income white, missing
# median household income black, missing
# median household income hispanic, missing
# median household income asian, missing

inflate_available = list(set(df.columns).intersection(set(inflate_cols)))

if len(inflate_available):
df = adjust_inflation(df, inflate_available, year)
return df

#### End of New Code ####
Comment on lines +680 to +701
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need to work a little bit differently from the ltdb example. Unlike in the store_ltdb function, we've only got a single dataframe here, so we need to slice the ncdb dataframe by year and apply the adjust_inflation to each slice

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will take a look.


for row in data_store.codebook["formula"].dropna().tolist():
try:
df.eval(row, inplace=True)
Expand Down Expand Up @@ -771,7 +796,7 @@ class Community(object):
boundaries (e.g. census tracts, or blocks in the US), and tabular data
which describe the composition of each neighborhood (e.g. data from
surveys, sensors, or geocoded misc.). A Community can be large (e.g. a
metropolitan region), or small (e.g. a handfull of census tracts) and
metropolitan region), or small (e.g. a handful of census tracts) and
may have data pertaining to multiple discrete points in time.

Parameters
Expand Down Expand Up @@ -1163,7 +1188,7 @@ def from_ltdb(
):
"""Create a new Community from LTDB data.

Instiantiate a new Community from pre-harmonized LTDB data. To use
Instantiate a new Community from pre-harmonized LTDB data. To use
you must first download and register LTDB data with geosnap using
the `store_ltdb` function. Pass lists of states, counties, or any
arbitrary FIPS codes to create a community. All fips code arguments
Expand Down Expand Up @@ -1239,7 +1264,7 @@ def from_ncdb(
):
"""Create a new Community from NCDB data.

Instiantiate a new Community from pre-harmonized NCDB data. To use
Instantiate a new Community from pre-harmonized NCDB data. To use
you must first download and register LTDB data with geosnap using
the `store_ncdb` function. Pass lists of states, counties, or any
arbitrary FIPS codes to create a community. All fips code arguments
Expand Down Expand Up @@ -1314,7 +1339,7 @@ def from_census(
):
"""Create a new Community from original vintage US Census data.

Instiantiate a new Community from . To use
Instantiate a new Community from . To use
you must first download and register census data with geosnap using
the `store_census` function. Pass lists of states, counties, or any
arbitrary FIPS codes to create a community. All fips code arguments
Expand Down Expand Up @@ -1419,7 +1444,7 @@ def from_lodes(
):
"""Create a new Community from Census LEHD/LODES data.

Instiantiate a new Community from LODES data.
Instantiate a new Community from LODES data.
Pass lists of states, counties, or any
arbitrary FIPS codes to create a community. All fips code arguments
are additive, so geosnap will include the largest unique set.
Expand Down
Loading