Skip to content

DEPR: null_color since color used everywhere else #45907

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 13 commits into from
Mar 3, 2022
2 changes: 1 addition & 1 deletion doc/source/user_guide/style.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@
"source": [
"df2.iloc[0,2] = np.nan\n",
"df2.iloc[4,3] = np.nan\n",
"df2.loc[:4].style.highlight_null(null_color='yellow')"
"df2.loc[:4].style.highlight_null(color='yellow')"
]
},
{
Expand Down
23 changes: 19 additions & 4 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -3097,19 +3097,23 @@ def bar(

return self

@Substitution(subset=subset, props=props)
@Substitution(subset=subset, props=props, color=color)
def highlight_null(
self,
null_color: str = "red",
color: str | None = None,
subset: Subset | None = None,
props: str | None = None,
null_color: str | None = "red",
) -> Styler:
"""
Highlight missing values with a style.

Parameters
----------
null_color : str, default 'red'
%(color)s

.. versionadded:: 1.5.0

%(subset)s

.. versionadded:: 1.1.0
Expand All @@ -3118,6 +3122,13 @@ def highlight_null(

.. versionadded:: 1.3.0

null_color : str, default 'red'
The background color for highlighting.

.. deprecated:: 1.5.0
Use ``color`` instead. If ``color`` is given ``null_color`` is
not used.

Returns
-------
self : Styler
Expand All @@ -3133,8 +3144,12 @@ def highlight_null(
def f(data: DataFrame, props: str) -> np.ndarray:
return np.where(pd.isna(data).to_numpy(), props, "")

if null_color != "red":
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to make null_color == lib.no_default here (and then if its not that you can warn)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

raise FutureWarning("`null_color` is deprecated: use `color` instead")

color = color if color else null_color
if props is None:
props = f"background-color: {null_color};"
props = f"background-color: {color};"
return self.apply(f, axis=None, subset=subset, props=props)

@Substitution(subset=subset, color=color, props=props)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/style/test_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_highlight_null(styler):
def test_highlight_null_subset(styler):
# GH 31345
result = (
styler.highlight_null(null_color="red", subset=["A"])
.highlight_null(null_color="green", subset=["B"])
styler.highlight_null(color="red", subset=["A"])
.highlight_null(color="green", subset=["B"])
._compute()
.ctx
)
Expand Down