census icon indicating copy to clipboard operation
census copied to clipboard

Census.ALL does not function

Open poulson opened this issue 6 years ago • 1 comments

It appears that using Census.ALL instead of something of the form {'for': 'state:*'} does not work, even on the core example in the README:

>>> c.acs5.get('B01001_004E', Census.ALL)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/poulson/miniconda3/lib/python3.6/site-packages/census/core.py", line 298, in get
    return super(ACSClient, self).get(*args, **kwargs)
  File "/home/poulson/miniconda3/lib/python3.6/site-packages/census/core.py", line 155, in get
    merged_results = [merge(result) for result in zip(*all_results)]
  File "/home/poulson/miniconda3/lib/python3.6/site-packages/census/core.py", line 154, in <genexpr>
    for fifty_fields in chunks(fields, 50))
  File "/home/poulson/miniconda3/lib/python3.6/site-packages/census/core.py", line 64, in wrapper
    result = func(self, *args, **kwargs)
  File "/home/poulson/miniconda3/lib/python3.6/site-packages/census/core.py", line 170, in query
    'for': geo['for'],
TypeError: string indices must be integers

I installed the census API via pip: is it possible that this issue has already been fixed in master?

poulson avatar May 03 '19 18:05 poulson

Looking at the code, I think Census.ALL has to be used with a geographic convenience method. For example, the equivalent query using the state method works:

In [9]: c.acs5.state('B01001_004E', Census.ALL)                                                                                                                                                                    
Out[9]: 
[{'B01001_004E': 99703.0, 'state': '72'},
 {'B01001_004E': 155491.0, 'state': '01'},
 {'B01001_004E': 26172.0, 'state': '02'},
 {'B01001_004E': 231773.0, 'state': '04'},
...

This makes sense in that Census.ALL is very literally just a wildcard character:

https://github.com/datamade/census/blob/4f0244c91ee2c34c690e9a4a8b7e8305f213379b/census/core.py#L14

If this is true, the docs could probably be adjusted to clarify that Census.ALL isn't an appropriate choice for the get method.

jeancochrane avatar May 04 '19 16:05 jeancochrane