cenpy.products.ACS.check_match

ACS.check_match(self, name, level, return_level=False, return_table=False, cache_name=None)

A helper function to verify the match used by the product API.

Parameters
namestr

the name of the place/query string to be searched. Should be in the form “placename, stateabbreviation” (like “Los Angeles, CA”). For multiply-named locations, the format should be town1-town2, state1-state2, like Kansas City, KS-MO.

levelstr

the name of the census hierarchy in which the name should be searched. Should be something like “Incorporated Places” or “States”.

return_level: bool

Whether to return the level match. If you are uncertain as to which level the name is matching, set this flag to True to see the Census API layer that matches.

return_table: bool

Whether to return the full table of possible matches for the queried name or level. If this is true, the return values are converted to be tuples, containing (match, table), where “match” is the entity in the Census API that matches the requested name or level, and table is the set of all possible values that could have been matched. If the matching fails for your first run, try inspecting table using return_table=True. Find the place/name you intend to match, and then input exactly that string.

Returns
——-
int

the row of the match table that records the matched name. If return_table is True, this becomes a tuple of (row, table). If return_level is True, the result is returned for both the match on the name and on the level. If both return_table and return_level are true, then two tuples are returned. The first contains the match for the name and the full table of possible names, and the second contains the match of the level and

the full table of possible levels.

Notes

matches are made based on the partial_ratio and ratio scorings from the fuzzywuzzy package. The partial_ratio prioritizes the “target” being fully contained in the match. So, a string like Chicago, IL would be a perfect match for Chicago, IL as well as ‘North Chicago, IL’ or Chicago Heights, IL. If there are ties (which happens often), the ratio percentage is used to break them. This considers the full string similarity, so that the closest full strings are matched. This ensures that Chicago, IL is matched to Chicago, IL, and not West Chicago, IL.

Consult the fuzzywuzzy package documentation for more information on the partial_ratio and ratio matches.