-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix Empty DataFrame.style.render raises IndexError #15971
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
Conversation
Fix attempt for Issue pandas-dev#15953 Handles DataFrames and Series with no rows or columns using `pd.DataFrame().empty` or `pd.Series().empty`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! One comment on the fix. Could you also add tests and a release note in doc/source/whatsnew/v0.20.0.txt?
@@ -218,8 +218,8 @@ def format_attr(pair): | |||
|
|||
cell_context = dict() | |||
|
|||
n_rlvls = self.data.index.nlevels | |||
n_clvls = self.data.columns.nlevels | |||
n_rlvls = 0 if self.data.empty else self.data.index.nlevels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll have to change this around a bit. DataFrame.empty
is True if either the index or columns is empty. So you get
pd.DataFrame([], index=[1, 2]).empty # True
pd.DataFrame([], columns=['A', 'B']).empty # True
Codecov Report
@@ Coverage Diff @@
## master #15971 +/- ##
==========================================
+ Coverage 91% 91.01% +<.01%
==========================================
Files 145 145
Lines 49581 49581
==========================================
+ Hits 45122 45124 +2
+ Misses 4459 4457 -2
Continue to review full report at Codecov.
|
pls rebase / update according to the comments. Needs a tests. |
whatsnew notes should go in |
Looks like #16441 fixed this in the meantime. Thanks anyways @sandipchatterjee, sorry about the duplicated effort. |
Fix attempt for Issue #15953
Handles DataFrames and Series with no rows or columns
using
pd.DataFrame().empty
orpd.Series().empty
git diff upstream/master --name-only -- '*.py' | flake8 --diff