|
9 | 9 | """
|
10 | 10 | # pylint: disable=too-many-lines
|
11 | 11 | from os.path import join
|
| 12 | +from collections import defaultdict |
12 | 13 |
|
13 | 14 | import pandas as pd
|
14 | 15 | import pkg_resources
|
15 | 16 | from pandas.api.types import is_string_dtype
|
16 |
| -from collections import defaultdict |
17 | 17 |
|
18 | 18 |
|
19 | 19 | class GeoMapper: # pylint: disable=too-many-public-methods
|
@@ -121,11 +121,11 @@ def __init__(self, census_year=2020):
|
121 | 121 | # Include all unique geos from first-level and second-level keys in
|
122 | 122 | # CROSSWALK_FILENAMES, with a few exceptions
|
123 | 123 | self._geos = {
|
124 |
| - subkey for mainkey in self.CROSSWALK_FILENAMES.keys() |
125 |
| - for subkey in self.CROSSWALK_FILENAMES[mainkey].keys() |
126 |
| - }.union({ |
127 |
| - mainkey for mainkey in self.CROSSWALK_FILENAMES.keys() |
128 |
| - }) - set(["state", "pop", "jhu_uid"]) |
| 124 | + subkey for mainkey in self.CROSSWALK_FILENAMES |
| 125 | + for subkey in self.CROSSWALK_FILENAMES[mainkey] |
| 126 | + }.union( |
| 127 | + set(self.CROSSWALK_FILENAMES.keys()) |
| 128 | + ) - set(["state", "pop", "jhu_uid"]) |
129 | 129 |
|
130 | 130 | for from_code, to_codes in self.CROSSWALK_FILENAMES.items():
|
131 | 131 | for to_code, file_path in to_codes.items():
|
@@ -590,17 +590,13 @@ def get_geos_within(self, container_geocode, contained_geocode_type, container_g
|
590 | 590 | crosswalk_state = self._crosswalks["fips"]["state"]
|
591 | 591 | fips_hhs = crosswalk_hhs[crosswalk_hhs["hhs"] == container_geocode]["fips"]
|
592 | 592 | return set(crosswalk_state[crosswalk_state["fips"].isin(fips_hhs)]["state_id"])
|
593 |
| - elif ( |
594 |
| - ( |
595 |
| - contained_geocode_type == "county" or |
596 |
| - contained_geocode_type == "fips" or |
597 |
| - contained_geocode_type == "popsafe-fips" |
598 |
| - ) and |
599 |
| - container_geocode_type == "state" |
600 |
| - ): |
| 593 | + elif (contained_geocode_type in ("county", "fips", "popsafe-fips") and |
| 594 | + container_geocode_type == "state"): |
601 | 595 | contained_geocode_type = self.as_mapper_name(contained_geocode_type)
|
602 | 596 | crosswalk = self._crosswalks[contained_geocode_type]["state"]
|
603 |
| - return set(crosswalk[crosswalk["state_id"] == container_geocode][contained_geocode_type]) |
| 597 | + return set( |
| 598 | + crosswalk[crosswalk["state_id"] == container_geocode][contained_geocode_type] |
| 599 | + ) |
604 | 600 | raise ValueError("(contained_geocode_type, container_geocode_type) was "
|
605 | 601 | f"({contained_geocode_type}, {container_geocode_type}), but "
|
606 | 602 | "must be one of (state, nation), (state, hhs), (county, state)"
|
|
0 commit comments