Hi! I'm proposing a refactoring of folktables's DataSource component (refer to this ZIP to see the changes already implemented).
Proposed changes
In this section I describe the changes I'm proposing that will affect the structure of the DataSource component.
- Creating utilities that help to (down)load different datasets: many of the functionalities already coded in the current version of folktables can be reused to (down)load different datasets (e.g., making the HTTP request to download a dataset from the U.S. Census Bureau's website, saving the content of the HTTP request into local memory, ...). Hence, I'm proposing creating utilities for these common tasks as it will allow us to reuse the code in the case that more datasets will be supported.
- Added the ability to download files asynchronously.
- Changing the
DataSource from an ABC to a Protocol: as I see it, the role of DataSource is to define an interface for classes that help with the (down)loading of different datasets. By having DataSource be a Protocol we'll be taking advantage of Python's duck typing and will make it more straight forward that this is the interface that should be followed (plus, we have the added benefit that we do not have to directly inherit from DataSource whenever defining this component for a different dataset).
- Introducing
DownloadResource, LoadResource, and FilesResource: these are dataclasses that contain information pertaining to file paths and URLs for the different datasets the user wants to (down)load. These objects (note that FilesResource just contains instances of DownloadResource and LoadResource) makes it easier to keep track of the resources needed to (down)load files.
- Refactored
load_acs.py and the ACSDataSource class in acs.py into one file: in this refactoring I'm following the re-defined DataSource interface, I'm using the utility functions I created or refactored, and I'm taking advantage of the *Resource objects defined. One additional thing I did was to turn the hard coded URL into a "constant" variable.
- Introducing custom exceptions.
Proposed file structure
folktables
| __init__.py
| folktables.py
| exceptions.py
| acs.py
|_____data_source
| | __init__.py
| | acs_data_source.py
| | data_source.py
|_____utils
| | __init__.py
| | download_utils.py
| | files_resource.py
| | load_utils.py
Hi! I'm proposing a refactoring of folktables's
DataSourcecomponent (refer to this ZIP to see the changes already implemented).Proposed changes
In this section I describe the changes I'm proposing that will affect the structure of the
DataSourcecomponent.DataSourcefrom anABCto aProtocol: as I see it, the role ofDataSourceis to define an interface for classes that help with the (down)loading of different datasets. By havingDataSourcebe aProtocolwe'll be taking advantage of Python's duck typing and will make it more straight forward that this is the interface that should be followed (plus, we have the added benefit that we do not have to directly inherit fromDataSourcewhenever defining this component for a different dataset).DownloadResource,LoadResource, andFilesResource: these aredataclassesthat contain information pertaining to file paths and URLs for the different datasets the user wants to (down)load. These objects (note thatFilesResourcejust contains instances ofDownloadResourceandLoadResource) makes it easier to keep track of the resources needed to (down)load files.load_acs.pyand theACSDataSourceclass inacs.pyinto one file: in this refactoring I'm following the re-definedDataSourceinterface, I'm using the utility functions I created or refactored, and I'm taking advantage of the*Resourceobjects defined. One additional thing I did was to turn the hard coded URL into a "constant" variable.Proposed file structure