Skip to content
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

ENH: Styler.highlight_null can accepts subset argument #31350

Merged

Conversation

immaxchen
Copy link
Contributor

As proposed in #31345 and as a follow-up PR for #29118

@@ -1006,19 +1006,23 @@ def hide_columns(self, subset) -> "Styler":
def _highlight_null(v, null_color: str) -> str:
return f"background-color: {null_color}" if pd.isna(v) else ""

def highlight_null(self, null_color: str = "red") -> "Styler":
def highlight_null(self, null_color: str = "red", subset=None) -> "Styler":
"""
Shade the background ``null_color`` for missing values.

Parameters
----------
null_color : str
Copy link
Member

@MarcoGorelli MarcoGorelli Jan 27, 2020

Choose a reason for hiding this comment

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

I know this was already absent, but should the default (red) be mentioned here in the docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure~

"""
Shade the background ``null_color`` for missing values.

Parameters
----------
null_color : str
null_color : str, default 'red'
subset : IndexSlice, default None
Copy link
Member

Choose a reason for hiding this comment

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

This isn't an IndexSlice right? Just a label or list of labels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is an IndexSlice, since it calls self.applymap and applymap uses IndexSlice.

< code >

def _applymap(self, func: Callable, subset=None, **kwargs) -> "Styler":
func = partial(func, **kwargs) # applymap doesn't take kwargs?
if subset is None:
subset = pd.IndexSlice[:]
subset = _non_reducing_slice(subset)
result = self.data.loc[subset].applymap(func)
self._update_ctx(result)
return self

< proof >

image

< the doc >

Copy link
Member

Choose a reason for hiding this comment

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

The test case here though is not for an IndexSlice rather a list of labels. I think for a natural API should go with Label / Sequence of Labels as mentioned above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can take Label / Sequence of Labels as well, just like other Styler built-in methods.

image

Copy link
Member

Choose a reason for hiding this comment

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

Can you update this to label or list of labels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure.

@WillAyd WillAyd added the Styler conditional formatting using DataFrame.style label Feb 12, 2020
"""
Shade the background ``null_color`` for missing values.

Parameters
----------
null_color : str
null_color : str, default 'red'
subset : IndexSlice, default None
Copy link
Member

Choose a reason for hiding this comment

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

Can you update this to label or list of labels?

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

minor nit on annotation otherwise lgtm

@TomAugspurger care to look?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Mar 4, 2020 via email

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.

LGTM once the CI issue is sorted out.

@immaxchen
Copy link
Contributor Author

Thanks, it's ok now.

@WillAyd WillAyd added this to the 1.1 milestone Mar 10, 2020
@WillAyd WillAyd merged commit a77ad8b into pandas-dev:master Mar 10, 2020
@WillAyd
Copy link
Member

WillAyd commented Mar 10, 2020

Thanks @immaxchen nice PR!

SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Styler.highlight_null to accept subset argument
4 participants