socialfoundations / folktables

Datasets derived from US census data
MIT License
240 stars 19 forks source link

`get_definitions` fails if `get_data` wasn't called previously #47

Open cherrywoods opened 6 months ago

cherrywoods commented 6 months ago

Dear folktables developers, Thank you for providing this useful and nicely usable package! However, I stumbled upon a minor issue when downloading definitions:

from folktables import ACSDataSource, load_acs

data_source = folktables.ACSDataSource("2018", "1-Year", "person", root_dir=".datasets/ACS")

data_source.get_definitions(download=True)
""" Throws the following error:
Traceback (most recent call last):
  File "/.../.local/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3553, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-365e0bfd702d>", line 1, in <module>
    cats = data_source.get_definitions(download=True)
  File "/.../lib/python3.10/site-packages/folktables/acs.py", line 65, in get_definitions
    return load_definitions(root_dir=self._root_dir, year=self._survey_year, horizon=self._horizon,
  File "/.../lib/python3.10/site-packages/folktables/load_acs.py", line 171, in load_definitions
    with open(file_path, 'wb') as handle:
FileNotFoundError: [Errno 2] No such file or directory: '.datasets/ACS/2018/1-Year/definition.csv'
"""
load_acs(root_dir=".datasets/ACS", serial_filter_list=[], download=True)
data_source.get_definitions(download=True)
# works fine now

Best regards, David