jtleider / censusdata

Download data from Census API
MIT License
139 stars 29 forks source link

Wrong url(?) #2

Closed tomahawklin closed 5 years ago

tomahawklin commented 5 years ago

Hi I'm not sure if this is an issue about the module itself, but when I try to retrieve 2013 ACS 5-year estimates data, I used a following code:

g = censusdata.censusgeo([('state', '25'), ('county', '017'), ('block group', '*')])
d = censusdata.download('acs5', year, g, features)

However I got an value error unknown/unsupported geography heirarchy

I notice the url requested is

https://api.census.gov/data/2013/acs/acs5?get=NAME,B25001_001E,B19013_001E&for=block+group:*&in=state:25+county:017

And if I remove /acs in the url, it actually worked:

https://api.census.gov/data/2013/acs5?get=NAME,B25001_001E,B19013_001E&for=block+group:*&in=state:25+county:017
tomahawklin commented 5 years ago

BTW the original code can work with 2016 acs5 data. Probably the census side is not making it consistent across different years? If we don't count on them making the correction, is there any workaround we can try in the module itself? Many thanks!

jtleider commented 5 years ago

Hi, the module is trying to use the recent updated Census API endpoints. It looks like the updated endpoints do not work consistently for all geographies, at least in this case. For instance, the code above works for 2013 with county-level data; the error is only at the block group level. I will investigate this further and update the _download function accordingly to fix the error.

jtleider commented 5 years ago

Hi, I could not find documentation indicating which geographies still fall under the old endpoints. As a workaround, I have added an option to the download function in censusdata to force use of the old endpoint. This resolves your problem:

year = 2013 g = censusdata.censusgeo([('state', '25'), ('county', '017'), ('block group', '*')]) features = ['B25001_001E', 'B19013_001E'] d = censusdata.download('acs5', year, g, features, endpt='old')