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

Closed
TomAugspurger opened this Issue Apr 8, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@TomAugspurger
Contributor

TomAugspurger commented Apr 8, 2017

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

@TomAugspurger TomAugspurger added this to the Next Major Release milestone Apr 8, 2017

sandipchatterjee added a commit to sandipchatterjee/pandas that referenced this issue Apr 10, 2017

BUG: Fix Empty DataFrame.style.render raises IndexError
Fix attempt for Issue #15953

Handles DataFrames and Series with no rows or columns
using `pd.DataFrame().empty` or `pd.Series().empty`
@JimStearns206

This comment has been minimized.

Show comment
Hide comment
@JimStearns206

JimStearns206 May 22, 2017

Contributor

I'll take a stab at this (I'm at PyCon sprint).

Contributor

JimStearns206 commented May 22, 2017

I'll take a stab at this (I'm at PyCon sprint).

JimStearns206 added a commit to JimStearns206/pandas that referenced this issue May 23, 2017

TST: Test rendering of 2 empty-ish DataFrames (#15953)
DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

JimStearns206 added a commit to JimStearns206/pandas that referenced this issue May 23, 2017

TST: Test rendering of 2 empty-ish DataFrames (#15953)
DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

TomAugspurger added a commit that referenced this issue May 23, 2017

BUG: Render empty DataFrame as empty HTML table w/o raising IndexErro…
…r. (#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

pvomelveny added a commit to pvomelveny/pandas that referenced this issue May 23, 2017

BUG: Render empty DataFrame as empty HTML table w/o raising IndexErro…
…r. (#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue May 29, 2017

BUG: Render empty DataFrame as empty HTML table w/o raising IndexErro…
…r. (#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

(cherry picked from commit d9a63d0)

TomAugspurger added a commit that referenced this issue May 30, 2017

BUG: Render empty DataFrame as empty HTML table w/o raising IndexErro…
…r. (#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

(cherry picked from commit d9a63d0)

stangirala added a commit to stangirala/pandas that referenced this issue Jun 11, 2017

BUG: Render empty DataFrame as empty HTML table w/o raising IndexErro…
…r. (#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment