Skip to content

Commit

Permalink
Merge pull request #397 from knaaptime/lodescodes
Browse files Browse the repository at this point in the history
expose lodes codebook
  • Loading branch information
knaaptime authored Feb 29, 2024
2 parents 91eebfd + 33ca0ea commit 9b93509
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ available quickly with no configuration by accessing methods on the class.
DataStore.codebook
DataStore.counties
DataStore.ejscreen
DataStore.lodes_codebook
DataStore.ltdb
DataStore.msa_definitions
DataStore.msas
Expand Down
17 changes: 15 additions & 2 deletions geosnap/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __dir__(self):
"codebook",
"counties",
"ejscreen",
"lodes_codebook",
"ltdb",
"msa_definitions",
"msas",
Expand Down Expand Up @@ -107,6 +108,18 @@ def show_data_dir(self, verbose=True):
print(self.data_dir)
return self.data_dir

def lodes_codebook(self):
"""_summary_
Returns
-------
pandas.DataFrame
decription of variables returned with LODES/LEHD data.
"""
return pd.read_csv(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "io/lodes.csv")
)

def bea_regions(self):
"""Table that maps states to their respective BEA regions
Expand All @@ -119,7 +132,7 @@ def bea_regions(self):
os.path.join(
os.path.dirname(os.path.abspath(__file__)), "io/bea_regions.csv"
),
converters={'stfips':str}
converters={"stfips": str},
)

def acs(self, year=2018, level="tract", states=None):
Expand Down Expand Up @@ -208,7 +221,7 @@ def seda(
"gcs",
"cs",
], "`standardize` argument must be either 'cs' for cohort-standardized or 'gcs' for grade-cohort-standardized"
if pooling=='poolsub':
if pooling == "poolsub":
fn = f"seda_{level}_{pooling}_{standardize}_4.1_corrected"
else:
fn = f"seda_{level}_{pooling}_{standardize}_4.1"
Expand Down
28 changes: 24 additions & 4 deletions geosnap/tests/test_datastore.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,81 @@
from geosnap import DataStore
datasets=DataStore()

datasets = DataStore()


def test_data_dir():
loc = datasets.show_data_dir()
assert len(loc) > 5


def test_acs():
df = datasets.acs(year=2012, states=["11"])
assert df.shape == (179, 104)


def test_tracts90():
df = datasets.tracts_1990(states=["11"])
assert df.shape == (192, 164)


def test_tracts00():
df = datasets.tracts_2000(states=["11"])
assert df.shape == (188, 192)


def test_tracts10():
df = datasets.tracts_2010(states=["11"])
assert df.shape == (179, 194)


def test_tracts20():
df = datasets.tracts_2020(states=["11"])
assert df.shape == (206, 15)


def test_counties():
assert datasets.counties().shape == (3233, 2)


def test_states():
assert datasets.states().shape == (51, 3)


def test_msas():
df = datasets.msas()
assert df.shape == (939, 4)


def test_msa_defs():
df = datasets.msa_definitions()
assert df.shape == (1916, 13)


def test_codebook():
df = datasets.codebook()
assert df.shape == (194, 12)


def test_bea():
df = datasets.bea_regions()
assert df.shape == (51, 4)


def test_blocks_2000():
df = datasets.blocks_2000(states=['11'])
df = datasets.blocks_2000(states=["11"])
assert df.shape == (5674, 3)


def test_blocks_2010():
df = datasets.blocks_2010(states=['11'])
df = datasets.blocks_2010(states=["11"])
assert df.shape == (6507, 5)


def test_blocks_2020():
df = datasets.blocks_2020(states=['11'])
df = datasets.blocks_2020(states=["11"])
assert df.shape == (6012, 7)


def test_lodes_codebook():
df = datasets.lodes_codebook()
assert df.shape == (42, 4)

0 comments on commit 9b93509

Please sign in to comment.