swvo.io.base#

Base class for all IO modules.

Classes

BaseIO([data_dir, prefer_env_var])

Abstract base class for all IO classes.

class swvo.io.base.BaseIO(data_dir: Path | None = None, prefer_env_var: bool = False)[source]#

Bases: ABC

Abstract base class for all IO classes.

This base class defines the common interface for external data I/O operations, including initialization, reading, and downloading/processing data.

Subclasses can implement flexible signatures for read() and download_and_process() methods to accommodate different data sources and requirements.

Parameters:
data_dirPath | None

Data directory for storing downloaded/processed data. If not provided, it will be read from the environment variable defined by the subclass’s ENV_VAR_NAME.

Raises:
ValueError

Raises ValueError if necessary environment variable is not set and data_dir is not provided.

abstractmethod read(*args, **kwargs) DataFrame | list[DataFrame][source]#

Read data.

Subclasses should implement this method with their specific signature. Common parameters include: - start_time: datetime

Start time of the data to read. Must be timezone-aware.

  • end_time: datetime

    End time of the data to read. Must be timezone-aware.

  • download: bool, optional

    Download data on the go if not available locally.

  • Additional parameters specific to each data source.

Returns:
pd.DataFrame or list[pd.DataFrame]

Data for the specified parameters.

abstractmethod download_and_process(*args, **kwargs) None[source]#

Download and process data.

Subclasses should implement this method with their specific signature. Common parameters include: - start_time: datetime

Start time of the data to download. Must be timezone-aware.

  • end_time: datetime

    End time of the data to download. Must be timezone-aware.

  • target_date: datetime

    Target date for data (for single-day sources).

  • request_time: datetime

    Request time for data (for streaming sources).

  • reprocess_files: bool, optional

    If True, re-download and re-process existing files.

  • Additional parameters specific to each data source.

Returns:
None