Skip to content

BUG: Empty DataFrame.style.render raises IndexError #15953

Closed
@TomAugspurger

Description

@TomAugspurger

Code Sample, a copy-pastable example if possible

In [6]: pd.DataFrame().style.render()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-6-345e1b37074e> in <module>()
----> 1 pd.DataFrame().style.render()

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/formats/style.py in render(self)
    416         """
    417         self._compute()
--> 418         d = self._translate()
    419         # filter out empty styles, every cell will have a class
    420         # but the list of props may just be [['', '']].

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/formats/style.py in _translate(self)
    252                            "is_visible": True})
    253
--> 254             for c in range(len(clabels[0])):
    255                 cs = [COL_HEADING_CLASS, "level%s" % r, "col%s" % c]
    256                 cs.extend(cell_context.get(

IndexError: list index out of range

Problem description

We assume that there's at least one column (and probably row)

Expected Output

Should match the output of an empty DataFrame in the notebook

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO HTMLread_html, to_html, Styler.apply, Styler.applymapOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions