import pathlib
import csv


def load_dataset(path_csv):
    """ Loads dataset into memory from csv file

    :param path_csv: str
    :return: object - [('text..', 'spam'), ('text...', 'ham'), ...]
    """
    dataset = []
    try:
        raw_data = pathlib \
            .Path(path_csv) \
            .read_text(encoding='utf-8') \
            .split('\n')
        csv_file = csv.reader(raw_data, delimiter=',')
    except FileNotFoundError as e:
        print("Sorry, no such file or directory.")
        return dataset

    # Read data from file
    for idx, row in enumerate(csv_file):
        if idx == 0 or len(row) < 2: continue
        text, label = row
        if text:
            dataset.append((text, label))

    return dataset