Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2017

Conversation

JimStearns206
Copy link
Contributor

A one line change to add an if clabels guard to clabels enumeration.

Returns HTML string consisting of empty table.

Help requested with format and placement of whatsnew entry.

@jreback jreback added Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string labels May 23, 2017
@TomAugspurger TomAugspurger added this to the 0.20.2 milestone May 23, 2017
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimStearns206 thanks. Whatsnew can go in doc/source/whatsnew/v0.20.2.txt

Just a minor request for a couple more edge cases. The fix looks good though.

@@ -103,6 +103,12 @@ def test_render(self):
s.render()
# it worked?

def test_render_empty_df(self):
empty_df = DataFrame()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a link to the issue here if you want https://github.com/pandas-dev/pandas/issues/15953

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a couple checks with

  • an index but on columns
  • columns but no index

It can be as simple as DataFrame(columns=['a']).style.render() and DataFrame(index=['a']).style.render()

@codecov
Copy link

codecov bot commented May 23, 2017

Codecov Report

Merging #16441 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16441      +/-   ##
==========================================
+ Coverage   90.42%   90.42%   +<.01%     
==========================================
  Files         161      161              
  Lines       51023    51024       +1     
==========================================
+ Hits        46138    46139       +1     
  Misses       4885     4885
Flag Coverage Δ
#multiple 88.26% <100%> (ø) ⬆️
#single 40.17% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 95.92% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49ec31b...5c40256. Read the comment docs.

@codecov
Copy link

codecov bot commented May 23, 2017

Codecov Report

Merging #16441 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16441      +/-   ##
==========================================
+ Coverage   90.42%   90.42%   +<.01%     
==========================================
  Files         161      161              
  Lines       51023    51024       +1     
==========================================
+ Hits        46138    46139       +1     
  Misses       4885     4885
Flag Coverage Δ
#multiple 88.26% <100%> (ø) ⬆️
#single 40.17% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 95.92% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6614e26...d9c354d. Read the comment docs.

@TomAugspurger
Copy link
Contributor

@JimStearns206 whoops looks like there were some extra commits in there. Are you on gitter? I can walk you through rebasing if you want.

@TomAugspurger
Copy link
Contributor

Basic idea is to

git fetch upstream
git rebase upstream/master
# fix any conflicts that come up
git push -f origin GH15953

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.
@TomAugspurger TomAugspurger merged commit d9a63d0 into pandas-dev:master May 23, 2017
@TomAugspurger
Copy link
Contributor

Thanks!

TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request May 29, 2017
…r. (pandas-dev#16441)

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

* TST: Test rendering of 2 empty-ish DataFrames (pandas-dev#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 pushed a commit that referenced this pull request May 30, 2017
…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 pushed a commit to stangirala/pandas that referenced this pull request Jun 11, 2017
…r. (pandas-dev#16441)

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

* TST: Test rendering of 2 empty-ish DataFrames (pandas-dev#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
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Empty DataFrame.style.render raises IndexError
3 participants