Source code for tseda.dataloader.coffee_prices_data_loader
"""Data loader for the ICO coffee prices dataset."""
from .local_dataloader import LocalDataLoader
import pandas as pd
[docs]
class CoffeePricesDataLoader(LocalDataLoader):
"""Load and expose the coffee prices CSV as a named ``signal`` series."""
[docs]
def __init__(self, file_path: str = "data/coffee_prices.csv"):
"""Configure the loader with the default coffee prices CSV path.
Args:
file_path: Path to the coffee prices CSV file.
"""
super().__init__(file_path)
[docs]
def load_coffee_prices(self) -> pd.DataFrame:
"""Load coffee prices and normalize expected column names.
Returns:
DataFrame with columns ``date`` and ``signal``. Returns an empty
DataFrame if source data cannot be loaded.
"""
data = self.load_data()
data.columns = ["date", "signal"]
data.date = pd.to_datetime(data.date)
if not data.empty:
# Additional processing specific to coffee prices can be added here
return data
else:
print("No data loaded.")
return pd.DataFrame()
[docs]
def get_series(self) -> pd.Series:
"""Extract the signal series from the normalized coffee dataset.
Returns:
``signal`` series indexed by ``date``. Returns an empty float series
when no data is available.
"""
data = self.load_coffee_prices()
data.index = data.date
if not data.empty:
return data["signal"]
else:
print("No data available to extract series.")
return pd.Series(dtype=float)