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

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

Comments

Projects
None yet
2 participants
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 added this to the Next Major Release milestone Apr 8, 2017

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

@sandipchatterjee sandipchatterjee 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`
5f88c22
Contributor

JimStearns206 commented May 22, 2017

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

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

@JimStearns206 JimStearns206 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.
8a13aa9

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

@JimStearns206 JimStearns206 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.
d9c354d

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

@JimStearns206 @TomAugspurger JimStearns206 + TomAugspurger 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.
d9a63d0

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

@JimStearns206 @pvomelveny JimStearns206 + pvomelveny 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.
f35e50a

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

@JimStearns206 @TomAugspurger JimStearns206 + TomAugspurger 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)
1d1ef5d

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

@JimStearns206 @TomAugspurger JimStearns206 + TomAugspurger 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)
de94073

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

@JimStearns206 @stangirala JimStearns206 + stangirala 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.
4772a19

@guillemborrell guillemborrell added a commit to guillemborrell/pandas that referenced this issue Jul 7, 2017

@JimStearns206 @guillemborrell JimStearns206 + guillemborrell 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.
f7785d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment