Open MaxGhenis opened 4 years ago
Hey, not currently. The way this is implemented is by manually defining the levels that work across the product API.
You should've hit a more informative error, but I can take a look as to why that's not happening. And, if that level can be validate, I'm happy to add it!
Further, I'll need to figure out why that doesn't work, given the fact that 'county'
was explicitly enabled in the _layer_lookup
. I get correct data with acs.from_state('AZ', level='county')
for 2017. What year are you doing?
Confirmed an issue with 2018 changing the column identifiers:
import cenpy
acs2017 = cenpy.products.ACS(year=2017)
acs2018 = cenpy.products.ACS(year=2018)
acs2017.from_state('AZ', level='county') # returns the counties in AZ
acs2018.from_state('AZ', level='county') # fails on the error described
It looks like this is due to differences between tigerWMS_ACS2017
and tigerWMS_ACS2018
map services coupled with a hard-coded _layer_lookup
. Basically just querying the wrong layer from TIGER depending on the year.
Map Service | "Census Tract" Index | "Counties" Index | Link |
---|---|---|---|
tigerWMS_ACS2017 | 8 | 84* | Link |
tigerWMS_ACS2018 | 8 | 86* | Link |
tigerWMS_ACS2019 | 8 | 86 | Link |
cenpy.products.ACS
is always checking layer at index 84 for counties, but that layer is now at index 86 for 2018 and 2019.
class ACS(_Product):
"""The American Community Survey (5-year vintages) from the Census Bueau"""
_layer_lookup = {"county": 84, "tract": 8}
cenpy.products.ACS
needs to become year-aware in order to account for the change in indexes.
Avoiding editing the base class to not interfere with Decennial2010
since it's year-aware by default.
class ACS(_Product):
"""The American Community Survey (5-year vintages) from the Census Bueau"""
_supported_layer_lookup = {
2017: {'county': 84, 'tract': 8},
2018: {'county': 86, 'tract': 8},
2019: {'county': 86, 'tract': 8},
}
def __init__(self, year="latest"):
self._cache = dict()
if year == "latest":
year = 2019
if year < 2017:
raise NotImplementedError(
"The requested year {} is too early. "
"Only 2017 and onwards is supported.".format(year)
)
self._year = year
self._api = APIConnection("ACSDT{}Y{}".format(5, year))
self._api.set_mapservice("tigerWMS_ACS{}".format(year))
@property
def _layer_lookup(self):
pass
@_layer_lookup.getter
def _layer_lookup(self):
return self._supported_layer_lookup[self._year]
Looking at the code it seems like it should be, but I get the following error: