Skip to content

Commit e43887c

Browse files
committed
Simplify _load_crosswalk_from_file method
1 parent 6a44805 commit e43887c

File tree

1 file changed

+15
-59
lines changed

1 file changed

+15
-59
lines changed

_delphi_utils_python/delphi_utils/geomap.py

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -135,65 +135,21 @@ def __init__(self):
135135

136136
def _load_crosswalk_from_file(self, from_code, to_code, data_path):
137137
stream = pkg_resources.resource_stream(__name__, data_path)
138-
usecols = None
139-
dtype = None
140-
# Weighted crosswalks
141-
if (from_code, to_code) in [
142-
("zip", "fips"),
143-
("fips", "zip"),
144-
("jhu_uid", "fips"),
145-
("zip", "msa"),
146-
("fips", "hrr"),
147-
("zip", "hhs")
148-
]:
149-
dtype = {
150-
from_code: str,
151-
to_code: str,
152-
"weight": float,
153-
}
154-
155-
# Unweighted crosswalks
156-
elif (from_code, to_code) in [
157-
("zip", "hrr"),
158-
("fips", "msa"),
159-
("fips", "hhs"),
160-
("state_code", "hhs")
161-
]:
162-
dtype = {from_code: str, to_code: str}
163-
164-
# Special table of state codes, state IDs, and state names
165-
elif (from_code, to_code) == ("state", "state"):
166-
dtype = {
167-
"state_code": str,
168-
"state_id": str,
169-
"state_name": str,
170-
}
171-
elif (from_code, to_code) == ("zip", "state"):
172-
dtype = {
173-
"zip": str,
174-
"weight": float,
175-
"state_code": str,
176-
"state_id": str,
177-
"state_name": str,
178-
}
179-
elif (from_code, to_code) == ("fips", "state"):
180-
dtype = {
181-
"fips": str,
182-
"state_code": str,
183-
"state_id": str,
184-
"state_name": str,
185-
}
186-
187-
# Population tables
188-
elif to_code == "pop":
189-
dtype = {
190-
from_code: str,
191-
"pop": int,
192-
}
193-
usecols = [
194-
from_code,
195-
"pop"
196-
]
138+
dtype = {
139+
from_code: str,
140+
to_code: str,
141+
"fips": str,
142+
"zip": str,
143+
"hrr": str,
144+
"hhs": str,
145+
"msa": str,
146+
"state_code": str,
147+
"state_id": str,
148+
"state_name": str,
149+
"pop": int,
150+
"weight": float
151+
}
152+
usecols = [from_code, "pop"] if to_code == "pop" else None
197153
return pd.read_csv(stream, dtype=dtype, usecols=usecols)
198154

199155
def _load_geo_values(self, geo_type):

0 commit comments

Comments
 (0)