diff --git a/asv_bench/benchmarks/io/style.py b/asv_bench/benchmarks/io/style.py
index f0902c9c2c328..1ebdb08e8c727 100644
--- a/asv_bench/benchmarks/io/style.py
+++ b/asv_bench/benchmarks/io/style.py
@@ -83,11 +83,11 @@ def _style_format(self):
def _style_apply_format_hide(self):
self.st = self.df.style.applymap(lambda v: "color: red;")
self.st.format("{:.3f}")
- self.st.hide_index(self.st.index[1:])
- self.st.hide_columns(self.st.columns[1:])
+ self.st.hide(self.st.index[1:], axis=0)
+ self.st.hide(self.st.columns[1:], axis=1)
def _style_tooltips(self):
ttips = DataFrame("abc", index=self.df.index[::2], columns=self.df.columns[::2])
self.st = self.df.style.set_tooltips(ttips)
- self.st.hide_index(self.st.index[12:])
- self.st.hide_columns(self.st.columns[12:])
+ self.st.hide(self.st.index[12:], axis=0)
+ self.st.hide(self.st.columns[12:], axis=1)
diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst
index 1f245b585df48..136c97f18881c 100644
--- a/doc/source/whatsnew/v2.0.0.rst
+++ b/doc/source/whatsnew/v2.0.0.rst
@@ -173,6 +173,11 @@ Removal of prior version deprecations/changes
- Removed deprecated ``weekofyear`` and ``week`` attributes of :class:`DatetimeArray`, :class:`DatetimeIndex` and ``dt`` accessor in favor of ``isocalendar().week`` (:issue:`33595`)
- Removed deprecated :meth:`RangeIndex._start`, :meth:`RangeIndex._stop`, :meth:`RangeIndex._step`, use ``start``, ``stop``, ``step`` instead (:issue:`30482`)
- Removed deprecated :meth:`DatetimeIndex.to_perioddelta`, Use ``dtindex - dtindex.to_period(freq).to_timestamp()`` instead (:issue:`34853`)
+- Removed deprecated :meth:`.Styler.hide_index` and :meth:`.Styler.hide_columns` (:issue:`49397`)
+- Removed deprecated :meth:`.Styler.set_na_rep` and :meth:`.Styler.set_precision` (:issue:`49397`)
+- Removed deprecated :meth:`.Styler.where` (:issue:`49397`)
+- Removed deprecated :meth:`.Styler.render` (:issue:`49397`)
+- Removed deprecated argument ``null_color`` in :meth:`.Styler.highlight_null` (:issue:`49397`)
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
- Enforced deprecation disallowing passing a sequence of timezone-aware values and ``dtype="datetime64[ns]"`` to to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
- Enforced deprecation disallowing using ``.astype`` to convert a ``datetime64[ns]`` :class:`Series`, :class:`DataFrame`, or :class:`DatetimeIndex` to timezone-aware dtype, use ``obj.tz_localize`` or ``ser.dt.tz_localize`` instead (:issue:`39258`)
diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py
index f3c58ac2ad18d..fb44082aa5b58 100644
--- a/pandas/io/formats/style.py
+++ b/pandas/io/formats/style.py
@@ -16,13 +16,11 @@
Sequence,
overload,
)
-import warnings
import numpy as np
from pandas._config import get_option
-from pandas._libs import lib
from pandas._typing import (
Axis,
AxisInt,
@@ -39,7 +37,6 @@
Substitution,
doc,
)
-from pandas.util._exceptions import find_stack_level
import pandas as pd
from pandas import (
@@ -270,8 +267,6 @@ def __init__(
formatter = formatter or get_option("styler.format.formatter")
# precision is handled by superclass as default for performance
- self.precision = precision # can be removed on set_precision depr cycle
- self.na_rep = na_rep # can be removed on set_na_rep depr cycle
self.format(
formatter=formatter,
precision=precision,
@@ -390,72 +385,6 @@ def _repr_latex_(self) -> str | None:
return self.to_latex()
return None
- def render(
- self,
- sparse_index: bool | None = None,
- sparse_columns: bool | None = None,
- **kwargs,
- ) -> str:
- """
- Render the ``Styler`` including all applied styles to HTML.
-
- .. deprecated:: 1.4.0
-
- Parameters
- ----------
- sparse_index : bool, optional
- Whether to sparsify the display of a hierarchical index. Setting to False
- will display each explicit level element in a hierarchical key for each row.
- Defaults to ``pandas.options.styler.sparse.index`` value.
- sparse_columns : bool, optional
- Whether to sparsify the display of a hierarchical index. Setting to False
- will display each explicit level element in a hierarchical key for each row.
- Defaults to ``pandas.options.styler.sparse.columns`` value.
- **kwargs
- Any additional keyword arguments are passed
- through to ``self.template.render``.
- This is useful when you need to provide
- additional variables for a custom template.
-
- Returns
- -------
- rendered : str
- The rendered HTML.
-
- Notes
- -----
- This method is deprecated in favour of ``Styler.to_html``.
-
- Styler objects have defined the ``_repr_html_`` method
- which automatically calls ``self.to_html()`` when it's the
- last item in a Notebook cell.
-
- When calling ``Styler.render()`` directly, wrap the result in
- ``IPython.display.HTML`` to view the rendered HTML in the notebook.
-
- Pandas uses the following keys in render. Arguments passed
- in ``**kwargs`` take precedence, so think carefully if you want
- to override them:
-
- * head
- * cellstyle
- * body
- * uuid
- * table_styles
- * caption
- * table_attributes
- """
- warnings.warn(
- "this method is deprecated in favour of `Styler.to_html()`",
- FutureWarning,
- stacklevel=find_stack_level(),
- )
- if sparse_index is None:
- sparse_index = get_option("styler.sparse.index")
- if sparse_columns is None:
- sparse_columns = get_option("styler.sparse.columns")
- return self._render_html(sparse_index, sparse_columns, **kwargs)
-
def set_tooltips(
self,
ttips: DataFrame,
@@ -2063,108 +1992,6 @@ def applymap(
)
return self
- @Substitution(subset=subset)
- def where(
- self,
- cond: Callable,
- value: str,
- other: str | None = None,
- subset: Subset | None = None,
- **kwargs,
- ) -> Styler:
- """
- Apply CSS-styles based on a conditional function elementwise.
-
- .. deprecated:: 1.3.0
-
- Updates the HTML representation with a style which is
- selected in accordance with the return value of a function.
-
- Parameters
- ----------
- cond : callable
- ``cond`` should take a scalar, and optional keyword arguments, and return
- a boolean.
- value : str
- Applied when ``cond`` returns true.
- other : str
- Applied when ``cond`` returns false.
- %(subset)s
- **kwargs : dict
- Pass along to ``cond``.
-
- Returns
- -------
- self : Styler
-
- See Also
- --------
- Styler.applymap: Apply a CSS-styling function elementwise.
- Styler.apply: Apply a CSS-styling function column-wise, row-wise, or table-wise.
-
- Notes
- -----
- This method is deprecated.
-
- This method is a convenience wrapper for :meth:`Styler.applymap`, which we
- recommend using instead.
-
- The example:
-
- >>> df = pd.DataFrame([[1, 2], [3, 4]])
- >>> def cond(v, limit=4):
- ... return v > 1 and v != limit
- >>> df.style.where(cond, value='color:green;', other='color:red;')
- ... # doctest: +SKIP
-
- should be refactored to:
-
- >>> def style_func(v, value, other, limit=4):
- ... cond = v > 1 and v != limit
- ... return value if cond else other
- >>> df.style.applymap(style_func, value='color:green;', other='color:red;')
- ... # doctest: +SKIP
- """
- warnings.warn(
- "this method is deprecated in favour of `Styler.applymap()`",
- FutureWarning,
- stacklevel=find_stack_level(),
- )
-
- if other is None:
- other = ""
-
- return self.applymap(
- lambda val: value if cond(val, **kwargs) else other,
- subset=subset,
- )
-
- def set_precision(self, precision: int) -> StylerRenderer:
- """
- Set the precision used to display values.
-
- .. deprecated:: 1.3.0
-
- Parameters
- ----------
- precision : int
-
- Returns
- -------
- self : Styler
-
- Notes
- -----
- This method is deprecated see `Styler.format`.
- """
- warnings.warn(
- "this method is deprecated in favour of `Styler.format(precision=..)`",
- FutureWarning,
- stacklevel=find_stack_level(),
- )
- self.precision = precision
- return self.format(precision=precision, na_rep=self.na_rep)
-
def set_table_attributes(self, attributes: str) -> Styler:
"""
Set the table attributes added to the ``
`` HTML element.
@@ -2649,140 +2476,6 @@ def set_table_styles(
self.table_styles = table_styles
return self
- def set_na_rep(self, na_rep: str) -> StylerRenderer:
- """
- Set the missing data representation on a ``Styler``.
-
- .. versionadded:: 1.0.0
-
- .. deprecated:: 1.3.0
-
- Parameters
- ----------
- na_rep : str
-
- Returns
- -------
- self : Styler
-
- Notes
- -----
- This method is deprecated. See `Styler.format()`
- """
- warnings.warn(
- "this method is deprecated in favour of `Styler.format(na_rep=..)`",
- FutureWarning,
- stacklevel=find_stack_level(),
- )
- self.na_rep = na_rep
- return self.format(na_rep=na_rep, precision=self.precision)
-
- def hide_index(
- self,
- subset: Subset | None = None,
- level: Level | list[Level] | None = None,
- names: bool = False,
- ) -> Styler:
- """
- Hide the entire index, or specific keys in the index from rendering.
-
- This method has dual functionality:
-
- - if ``subset`` is ``None`` then the entire index, or specified levels, will
- be hidden whilst displaying all data-rows.
- - if a ``subset`` is given then those specific rows will be hidden whilst the
- index itself remains visible.
-
- .. versionchanged:: 1.3.0
-
- .. deprecated:: 1.4.0
- This method should be replaced by ``hide(axis="index", **kwargs)``
-
- Parameters
- ----------
- subset : label, array-like, IndexSlice, optional
- A valid 1d input or single key along the index axis within
- `DataFrame.loc[, :]`, to limit ``data`` to *before* applying
- the function.
- level : int, str, list
- The level(s) to hide in a MultiIndex if hiding the entire index. Cannot be
- used simultaneously with ``subset``.
-
- .. versionadded:: 1.4.0
- names : bool
- Whether to hide the index name(s), in the case the index or part of it
- remains visible.
-
- .. versionadded:: 1.4.0
-
- Returns
- -------
- self : Styler
-
- See Also
- --------
- Styler.hide: Hide the entire index / columns, or specific rows / columns.
- """
- warnings.warn(
- 'this method is deprecated in favour of `Styler.hide(axis="index")`',
- FutureWarning,
- stacklevel=find_stack_level(),
- )
- return self.hide(axis="index", level=level, subset=subset, names=names)
-
- def hide_columns(
- self,
- subset: Subset | None = None,
- level: Level | list[Level] | None = None,
- names: bool = False,
- ) -> Styler:
- """
- Hide the column headers or specific keys in the columns from rendering.
-
- This method has dual functionality:
-
- - if ``subset`` is ``None`` then the entire column headers row, or
- specific levels, will be hidden whilst the data-values remain visible.
- - if a ``subset`` is given then those specific columns, including the
- data-values will be hidden, whilst the column headers row remains visible.
-
- .. versionchanged:: 1.3.0
-
- ..deprecated:: 1.4.0
- This method should be replaced by ``hide(axis="columns", **kwargs)``
-
- Parameters
- ----------
- subset : label, array-like, IndexSlice, optional
- A valid 1d input or single key along the columns axis within
- `DataFrame.loc[:, ]`, to limit ``data`` to *before* applying
- the function.
- level : int, str, list
- The level(s) to hide in a MultiIndex if hiding the entire column headers
- row. Cannot be used simultaneously with ``subset``.
-
- .. versionadded:: 1.4.0
- names : bool
- Whether to hide the column index name(s), in the case all column headers,
- or some levels, are visible.
-
- .. versionadded:: 1.4.0
-
- Returns
- -------
- self : Styler
-
- See Also
- --------
- Styler.hide: Hide the entire index / columns, or specific rows / columns.
- """
- warnings.warn(
- 'this method is deprecated in favour of `Styler.hide(axis="columns")`',
- FutureWarning,
- stacklevel=find_stack_level(),
- )
- return self.hide(axis="columns", level=level, subset=subset, names=names)
-
def hide(
self,
subset: Subset | None = None,
@@ -3334,10 +3027,9 @@ def bar(
@Substitution(subset=subset, props=props, color=color.format(default="red"))
def highlight_null(
self,
- color: str | None = None,
+ color: str = "red",
subset: Subset | None = None,
props: str | None = None,
- null_color: str | lib.NoDefault = lib.no_default,
) -> Styler:
"""
Highlight missing values with a style.
@@ -3356,13 +3048,6 @@ def highlight_null(
.. versionadded:: 1.3.0
- null_color : str, default None
- The background color for highlighting.
-
- .. deprecated:: 1.5.0
- Use ``color`` instead. If ``color`` is given ``null_color`` is
- not used.
-
Returns
-------
self : Styler
@@ -3378,17 +3063,6 @@ def highlight_null(
def f(data: DataFrame, props: str) -> np.ndarray:
return np.where(pd.isna(data).to_numpy(), props, "")
- if null_color != lib.no_default:
- warnings.warn(
- "`null_color` is deprecated: use `color` instead",
- FutureWarning,
- stacklevel=find_stack_level(),
- )
-
- if color is None and null_color == lib.no_default:
- color = "red"
- elif color is None and null_color != lib.no_default:
- color = null_color
if props is None:
props = f"background-color: {color};"
return self.apply(f, axis=None, subset=subset, props=props)
diff --git a/pandas/tests/io/formats/style/test_deprecated.py b/pandas/tests/io/formats/style/test_deprecated.py
deleted file mode 100644
index 863c31ed3cccd..0000000000000
--- a/pandas/tests/io/formats/style/test_deprecated.py
+++ /dev/null
@@ -1,170 +0,0 @@
-"""
-modules collects tests for Styler methods which have been deprecated
-"""
-import numpy as np
-import pytest
-
-jinja2 = pytest.importorskip("jinja2")
-
-from pandas import (
- DataFrame,
- IndexSlice,
- NaT,
- Timestamp,
-)
-import pandas._testing as tm
-
-
-@pytest.fixture
-def df():
- return DataFrame({"A": [0, 1], "B": np.random.randn(2)})
-
-
-@pytest.mark.parametrize("axis", ["index", "columns"])
-def test_hide_index_columns(df, axis):
- with tm.assert_produces_warning(FutureWarning):
- getattr(df.style, "hide_" + axis)()
-
-
-def test_set_non_numeric_na():
- # GH 21527 28358
- df = DataFrame(
- {
- "object": [None, np.nan, "foo"],
- "datetime": [None, NaT, Timestamp("20120101")],
- }
- )
-
- with tm.assert_produces_warning(FutureWarning):
- ctx = df.style.set_na_rep("NA")._translate(True, True)
- assert ctx["body"][0][1]["display_value"] == "NA"
- assert ctx["body"][0][2]["display_value"] == "NA"
- assert ctx["body"][1][1]["display_value"] == "NA"
- assert ctx["body"][1][2]["display_value"] == "NA"
-
-
-def test_where_with_one_style(df):
- # GH 17474
- def f(x):
- return x > 0.5
-
- style1 = "foo: bar"
-
- with tm.assert_produces_warning(FutureWarning):
- result = df.style.where(f, style1)._compute().ctx
- expected = {
- (r, c): [("foo", "bar")]
- for r, row in enumerate(df.index)
- for c, col in enumerate(df.columns)
- if f(df.loc[row, col])
- }
- assert result == expected
-
-
-@pytest.mark.parametrize(
- "slice_",
- [
- IndexSlice[:],
- IndexSlice[:, ["A"]],
- IndexSlice[[1], :],
- IndexSlice[[1], ["A"]],
- IndexSlice[:2, ["A", "B"]],
- ],
-)
-def test_where_subset(df, slice_):
- # GH 17474
- def f(x):
- return x > 0.5
-
- style1 = "foo: bar"
- style2 = "baz: foo"
-
- with tm.assert_produces_warning(FutureWarning):
- res = df.style.where(f, style1, style2, subset=slice_)._compute().ctx
- expected = {
- (r, c): [("foo", "bar") if f(df.loc[row, col]) else ("baz", "foo")]
- for r, row in enumerate(df.index)
- for c, col in enumerate(df.columns)
- if row in df.loc[slice_].index and col in df.loc[slice_].columns
- }
- assert res == expected
-
-
-def test_where_subset_compare_with_applymap(df):
- # GH 17474
- def f(x):
- return x > 0.5
-
- style1 = "foo: bar"
- style2 = "baz: foo"
-
- def g(x):
- return style1 if f(x) else style2
-
- slices = [
- IndexSlice[:],
- IndexSlice[:, ["A"]],
- IndexSlice[[1], :],
- IndexSlice[[1], ["A"]],
- IndexSlice[:2, ["A", "B"]],
- ]
-
- for slice_ in slices:
- with tm.assert_produces_warning(FutureWarning):
- result = df.style.where(f, style1, style2, subset=slice_)._compute().ctx
- expected = df.style.applymap(g, subset=slice_)._compute().ctx
- assert result == expected
-
-
-def test_where_kwargs():
- df = DataFrame([[1, 2], [3, 4]])
-
- def f(x, val):
- return x > val
-
- with tm.assert_produces_warning(FutureWarning):
- res = df.style.where(f, "color:green;", "color:red;", val=2)._compute().ctx
- expected = {
- (0, 0): [("color", "red")],
- (0, 1): [("color", "red")],
- (1, 0): [("color", "green")],
- (1, 1): [("color", "green")],
- }
- assert res == expected
-
-
-def test_set_na_rep():
- # GH 21527 28358
- df = DataFrame([[None, None], [1.1, 1.2]], columns=["A", "B"])
-
- with tm.assert_produces_warning(FutureWarning):
- ctx = df.style.set_na_rep("NA")._translate(True, True)
- assert ctx["body"][0][1]["display_value"] == "NA"
- assert ctx["body"][0][2]["display_value"] == "NA"
-
- with tm.assert_produces_warning(FutureWarning):
- ctx = (
- df.style.set_na_rep("NA")
- .format(None, na_rep="-", subset=["B"])
- ._translate(True, True)
- )
- assert ctx["body"][0][1]["display_value"] == "NA"
- assert ctx["body"][0][2]["display_value"] == "-"
-
-
-def test_precision(df):
- styler = df.style
- with tm.assert_produces_warning(FutureWarning):
- s2 = styler.set_precision(1)
- assert styler is s2
- assert styler.precision == 1
-
-
-def test_render(df):
- with tm.assert_produces_warning(FutureWarning):
- df.style.render()
-
-
-def test_null_color(df):
- with tm.assert_produces_warning(FutureWarning):
- df.style.highlight_null(null_color="blue")
diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py
index 77a996b1f92d6..35cc977368c5d 100644
--- a/pandas/tests/io/formats/style/test_style.py
+++ b/pandas/tests/io/formats/style/test_style.py
@@ -272,8 +272,6 @@ def test_copy(comprehensive, render, deepcopy, mi_styler, mi_styler_comp):
styler.to_html()
excl = [
- "na_rep", # deprecated
- "precision", # deprecated
"cellstyle_map", # render time vars..
"cellstyle_map_columns",
"cellstyle_map_index",
@@ -333,8 +331,6 @@ def test_clear(mi_styler_comp):
"cellstyle_map", # execution time only
"cellstyle_map_columns", # execution time only
"cellstyle_map_index", # execution time only
- "precision", # deprecated
- "na_rep", # deprecated
"template_latex", # render templates are class level
"template_html",
"template_html_style",