File size: 982 Bytes
0104e91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Reading the raw and the previously cleaned Excel datasets."""

from pathlib import Path

import pandas as pd

from config.constants import LABEL_COLUMN, TEXT_COLUMN
from config.paths import DEFAULT_CLEANED_DATA_PATH, DEFAULT_RAW_DATA_PATH


def load_raw_dataset(path=DEFAULT_RAW_DATA_PATH):
    """Load the raw Excel dataset."""
    return pd.read_excel(path)


def load_cleaned_dataset(path=DEFAULT_CLEANED_DATA_PATH):
    """Load a dataset already written by the preprocessing stage."""
    path = Path(path)
    if not path.is_file():
        raise FileNotFoundError(
            'No cleaned dataset at %s - run the pipeline once without '
            '--from-cleaned to create it.' % path
        )

    df = pd.read_excel(path)

    missing = [c for c in (TEXT_COLUMN, LABEL_COLUMN) if c not in df.columns]
    if missing:
        raise KeyError(
            '%s is missing the column(s) %s; found %s'
            % (path, missing, list(df.columns))
        )
    return df