pystreamapi icon indicating copy to clipboard operation
pystreamapi copied to clipboard

Loading big CSV files not safe

Open garlontas opened this issue 1 year ago • 0 comments

From __csv_loader.py:

def __load_csv(file_path, cast, delimiter, encoding):
    """Load a CSV file and convert it into a list of namedtuples"""
    # skipcq: PTC-W6004
    with open(file_path, mode='r', newline='', encoding=encoding) as csvfile:
        csvreader = reader(csvfile, delimiter=delimiter)

        # Create a namedtuple type, casting the header values to int or float if possible
        header = __get_csv_header(csvreader)

        Row = namedtuple('Row', list(header))

        mapper = LoaderUtils.try_cast if cast else lambda x: x

        # Process the data, casting values to int or float if possible
        data = [Row(*[mapper(value) for value in row]) for row in csvreader]
    return data

what happens if the file is too big to fit in memory?...

Originally posted by @adrian-herscu in https://github.com/PickwickSoft/pystreamapi/issues/94#issuecomment-2311735937

garlontas avatar Sep 02 '24 11:09 garlontas