-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ENH: Styler.highlight_null
can accepts subset
argument
#31350
Conversation
pandas/io/formats/style.py
Outdated
@@ -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 |
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 know this was already absent, but should the default (red) be mentioned here in the docstring?
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.
sure~
pandas/io/formats/style.py
Outdated
""" | ||
Shade the background ``null_color`` for missing values. | ||
|
||
Parameters | ||
---------- | ||
null_color : str | ||
null_color : str, default 'red' | ||
subset : IndexSlice, default None |
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.
This isn't an IndexSlice right? Just a label or list of labels?
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.
It is an IndexSlice, since it calls self.applymap
and applymap
uses IndexSlice.
< code >
pandas/pandas/io/formats/style.py
Lines 729 to 736 in e22a656
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 >
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.
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
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.
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.
Can you update this to label or list of labels
?
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.
sure.
pandas/io/formats/style.py
Outdated
""" | ||
Shade the background ``null_color`` for missing values. | ||
|
||
Parameters | ||
---------- | ||
null_color : str | ||
null_color : str, default 'red' | ||
subset : IndexSlice, default None |
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.
Can you update this to label or list of labels
?
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.
minor nit on annotation otherwise lgtm
@TomAugspurger care to look?
Won't have time near-term to look.
…On Tue, Mar 3, 2020 at 7:24 PM William Ayd ***@***.***> wrote:
***@***.**** requested changes on this pull request.
minor nit on annotation otherwise lgtm
@TomAugspurger <https://github.com/TomAugspurger> care to look?
------------------------------
In pandas/io/formats/style.py
<#31350 (comment)>:
> @@ -1003,19 +1003,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":
⬇️ Suggested change
- def highlight_null(self, null_color: str = "red", subset=None) -> "Styler":
+ def highlight_null(self, null_color: str = "red", subset: Optional[Union[Label, Sequence[Label]]]=None) -> "Styler":
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#31350?email_source=notifications&email_token=AAKAOIVIA555AZZ3BF32TA3RFWUUFA5CNFSM4KMDQDK2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCX3AUCA#pullrequestreview-368445960>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAOIXD3STROVYY3QN3RKLRFWUUFANCNFSM4KMDQDKQ>
.
|
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.
LGTM once the CI issue is sorted out.
…l-can-accept-subset
Thanks, it's ok now. |
Thanks @immaxchen nice PR! |
As proposed in #31345 and as a follow-up PR for #29118
Styler.highlight_null
to acceptsubset
argument #31345black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff