cenpy-devs / cenpy

Explore and download data from Census APIs
Other
183 stars 44 forks source link

Error in "from_place" #158

Open Nik4002 opened 1 year ago

Nik4002 commented 1 year ago

When using the from_place method in the ACS object, some cities cause errors if the user does not specify the place_type, that city will not produce any results. This issue occurs for cities that have both an Incorporated Place and a County Subdivision that represent exactly the same place with the same geometries, place ID, etc. For example, Detroit has this problem. When I try to run acs.from_place("Detroit, MI") (acs being an API connection to the ACS), this error is produced:

/usr/local/lib/python3.10/dist-packages/cenpy/products.py:993: UserWarning: Cannot disambiguate placename Detroit. Picking the shortest, best matched placename, Detroit city, from Detroit city, Detroit city
  warn(
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/cenpy/tiger.py](https://localhost:8080/#) in query(self, raw, strict, **kwargs)
    191         try:
--> 192             features = datadict["features"]
    193         except KeyError:

KeyError: 'features'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
3 frames
[/usr/local/lib/python3.10/dist-packages/cenpy/tiger.py](https://localhost:8080/#) in query(self, raw, strict, **kwargs)
    196             if details is []:
    197                 details = "Mapserver provided no detailed error"
--> 198             raise KeyError(
    199                 (
    200                     r"Response from API is malformed. You may have "

KeyError: 'Response from API is malformed. You may have submitted too many queries, formatted the request incorrectly, or experienced significant network connectivity issues. Check to make sure that your inputs, like placenames, are spelled correctly, and that your geographies match the level at which you intend to query. The original error from the Census is:\\n(API ERROR 400:Unable to complete operation.([]))'

Although this error is solvable by specifying the desired place_type in the from_place function call, it could be more user-friendly to remove duplicate places in the table that result from fuzzy-string-matching the name to the master place table.