# Buggy code
def split_data_line(line, dialect=None):
    delimiters = ",\t"

    # This can not be done in a per reader basis, and relational fields
    # can be HUGE
    csv.field_size_limit(int(ctypes.c_ulong(-1).value // 2))

    # Remove the line end if any
    if line[-1] == "\n":
        line = line[:-1]

    sniff_line = line

    # Add a delimiter if none is present, so that the csv.Sniffer
    # does not complain for a single-field CSV.
    if not any(d in line for d in delimiters):
        sniff_line += ","

    if dialect is None:
        dialect = csv.Sniffer().sniff(sniff_line, delimiters=delimiters)
        workaround_csv_sniffer_bug_last_field(
            sniff_line=sniff_line, dialect=dialect, delimiters=delimiters
        )

    row = next(csv.reader([line], dialect))

    return row, dialect


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-2169f5ba31ae> in <module>
2 import pandas as pd
3
----> 4 data = arff.loadarff('data/zoo.arff')
5 df = pd.DataFrame(data[0])
6

/opt/conda/lib/python3.8/site-packages/scipy/io/arff/arffread.py in loadarff(f)
800         ofile = open(f, 'rt')
801     try:
--> 802         return _loadarff(ofile)
803     finally:
804         if ofile is not f:  # only close what we opened

/opt/conda/lib/python3.8/site-packages/scipy/io/arff/arffread.py in _loadarff(ofile)
865             yield tuple([attr[i].parse_data(row[i]) for i in elems])
866
--> 867     a = list(generator(ofile))
868     # No error should happen here: it is a bug otherwise
869     data = np.array(a, [(a.name, a.dtype) for a in attr])

/opt/conda/lib/python3.8/site-packages/scipy/io/arff/arffread.py in generator(row_iter, delim)
863             row, dialect = split_data_line(raw, dialect)
864
--> 865             yield tuple([attr[i].parse_data(row[i]) for i in elems])
866
867     a = list(generator(ofile))

/opt/conda/lib/python3.8/site-packages/scipy/io/arff/arffread.py in <listcomp>(.0)
863             row, dialect = split_data_line(raw, dialect)
864
--> 865             yield tuple([attr[i].parse_data(row[i]) for i in elems])
866
867     a = list(generator(ofile))

/opt/conda/lib/python3.8/site-packages/scipy/io/arff/arffread.py in parse_data(self, data_str)
157             return data_str
158         else:
--> 159             raise ValueError("%s value not in %s" % (str(data_str),
160                                                      str(self.values)))
161

ValueError: invertebrate value not in ('mammal', 'bird', 'reptile', 'fish', 'amphibian', 'insect', 'invertebrate ')

# Fixed code
def split_data_line(line, dialect=None):
    delimiters = ",\t"

    # This can not be done in a per reader basis, and relational fields
    # can be HUGE
    csv.field_size_limit(int(ctypes.c_ulong(-1).value // 2))

    # Remove the line end if any
    if line[-1] == "\n":
        line = line[:-1]

    # Remove potential trailing whitespace
    line = line.strip()

    sniff_line = line

    # Add a delimiter if none is present, so that the csv.Sniffer
    # does not complain for a single-field CSV.
    if not any(d in line for d in delimiters):
        sniff_line += ","

    if dialect is None:
        dialect = csv.Sniffer().sniff(sniff_line, delimiters=delimiters)
        workaround_csv_sniffer_bug_last_field(
            sniff_line=sniff_line, dialect=dialect, delimiters=delimiters
        )

    row = next(csv.reader([line], dialect))

    return row, dialect