Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inserting column with insert_col fails if dataset contains 0 rows #583

@LukasK1

Description

@LukasK1

I am trying to add additional column to a Dataset that is created from a dictionary. I have headers defined separately. However, when dictionary is empty (no rows to export because how data is filtered) insert_col method fails with error:

File "/usr/local/lib/python3.10/site-packages/tablib/core.py", line 372, in _clean_col
    header = [col.pop(0)]
IndexError: pop from empty list

After looking in to the code of the method _clean_col, my guess, that if statement:

tablib/src/tablib/core.py

Lines 373 to 376 in 4fd9a68

if self.headers:
header = [col.pop(0)]
else:
header = []

should be opposite:

        if not self.headers:
            header = [col.pop(0)]
        else:
            header = []

or:

        if self.headers:
            header = []
        else:
            header = [col.pop(0)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions