Skip to content

Commit 32e044b

Browse files
committed
update county to msa
1 parent 9eb518c commit 32e044b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

doctor_visits/delphi_doctor_visits/geo_maps.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import pandas as pd
1414
import numpy as np
15+
from delphi_utils.geomap import GeoMapper
1516

1617
from .config import Config
1718
from .sensor import DoctorVisitsSensor
@@ -22,6 +23,7 @@ class GeoMaps:
2223

2324
def __init__(self, geo_filepath):
2425
self.geo_filepath = geo_filepath
26+
self.gmpr = GeoMapper()
2527

2628
@staticmethod
2729
def convert_fips(x):
@@ -43,9 +45,12 @@ def county_to_msa(self, data):
4345
converters={"fips": GeoMaps.convert_fips},
4446
)
4547
msa_map.drop_duplicates(inplace=True)
46-
data = data.merge(msa_map, how="left", left_on="PatCountyFIPS", right_on="fips")
47-
data.dropna(inplace=True)
48-
data.drop(columns=["fips", "PatCountyFIPS"], inplace=True)
48+
data = self.gmpr.add_geocode(data,
49+
"fips",
50+
"msa",
51+
from_col="PatCountyFIPS",
52+
new_col="cbsa_id")
53+
data.drop(columns="PatCountyFIPS", inplace=True)
4954
data = data.groupby(["ServiceDate", "cbsa_id"]).sum().reset_index()
5055

5156
return data.groupby("cbsa_id"), "cbsa_id"

doctor_visits/tests/test_geomap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_county_to_msa(self):
2626

2727
out, name = GM.county_to_msa(DATA)
2828
assert name == "cbsa_id"
29-
assert set(out.groups.keys()) == set([11500.0, 13820.0, 19300.0, 33860.0])
29+
assert set(out.groups.keys()) == {"11500", "13820", "19300", "33860"}
3030

3131
def test_county_to_state(self):
3232

0 commit comments

Comments
 (0)