Skip to content

Refactoring of DataSource component for easier, future, extensibility #26

Description

@RicardoJSandoval

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.

  1. 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.
  2. Added the ability to download files asynchronously.
  3. 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).
  4. 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.
  5. 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.
  6. 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

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions