Skip to content

Commit d4976d4

Browse files
authored
Remove DataFrame.applymap and Styler.applymap (#57345)
1 parent 82abcd9 commit d4976d4

File tree

10 files changed

+5
-154
lines changed

10 files changed

+5
-154
lines changed

doc/redirects.csv

-5
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ generated/pandas.DataFrame.align,../reference/api/pandas.DataFrame.align
311311
generated/pandas.DataFrame.all,../reference/api/pandas.DataFrame.all
312312
generated/pandas.DataFrame.any,../reference/api/pandas.DataFrame.any
313313
generated/pandas.DataFrame.apply,../reference/api/pandas.DataFrame.apply
314-
generated/pandas.DataFrame.applymap,../reference/api/pandas.DataFrame.applymap
315314
generated/pandas.DataFrame.as_blocks,../reference/api/pandas.DataFrame.as_blocks
316315
generated/pandas.DataFrame.asfreq,../reference/api/pandas.DataFrame.asfreq
317316
generated/pandas.DataFrame.as_matrix,../reference/api/pandas.DataFrame.as_matrix
@@ -747,8 +746,6 @@ generated/pandas.Interval.overlaps,../reference/api/pandas.Interval.overlaps
747746
generated/pandas.interval_range,../reference/api/pandas.interval_range
748747
generated/pandas.Interval.right,../reference/api/pandas.Interval.right
749748
generated/pandas.io.formats.style.Styler.apply,../reference/api/pandas.io.formats.style.Styler.apply
750-
generated/pandas.io.formats.style.Styler.applymap,../reference/api/pandas.io.formats.style.Styler.map
751-
generated/pandas.io.formats.style.Styler.applymap_index,../reference/api/pandas.io.formats.style.Styler.map_index
752749
generated/pandas.io.formats.style.Styler.background_gradient,../reference/api/pandas.io.formats.style.Styler.background_gradient
753750
generated/pandas.io.formats.style.Styler.bar,../reference/api/pandas.io.formats.style.Styler.bar
754751
generated/pandas.io.formats.style.Styler.clear,../reference/api/pandas.io.formats.style.Styler.clear
@@ -1432,8 +1429,6 @@ reference/api/pandas.arrays.PandasArray,pandas.arrays.NumpyExtensionArray
14321429
reference/api/pandas.core.groupby.DataFrameGroupBy.backfill,pandas.core.groupby.DataFrameGroupBy.bfill
14331430
reference/api/pandas.core.groupby.GroupBy.backfill,pandas.core.groupby.DataFrameGroupBy.bfill
14341431
reference/api/pandas.core.resample.Resampler.backfill,pandas.core.resample.Resampler.bfill
1435-
reference/api/pandas.io.formats.style.Styler.applymap,pandas.io.formats.style.Styler.map
1436-
reference/api/pandas.io.formats.style.Styler.applymap_index,pandas.io.formats.style.Styler.map_index
14371432

14381433
# EWM -> ExponentialMovingWindow
14391434
reference/api/pandas.core.window.ewm.EWM.corr,pandas.core.window.ewm.ExponentialMovingWindow.corr

doc/source/reference/frame.rst

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ Function application, GroupBy & window
117117

118118
DataFrame.apply
119119
DataFrame.map
120-
DataFrame.applymap
121120
DataFrame.pipe
122121
DataFrame.agg
123122
DataFrame.aggregate

doc/source/user_guide/10min.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ will be completed:
9191
df2.any df2.combine
9292
df2.append df2.D
9393
df2.apply df2.describe
94-
df2.applymap df2.diff
9594
df2.B df2.duplicated
95+
df2.diff
9696

9797
As you can see, the columns ``A``, ``B``, ``C``, and ``D`` are automatically
9898
tab completed. ``E`` and ``F`` are there as well; the rest of the attributes have been

doc/source/whatsnew/v0.20.0.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ Experimental support has been added to export ``DataFrame.style`` formats to Exc
369369
For example, after running the following, ``styled.xlsx`` renders as below:
370370

371371
.. ipython:: python
372-
:okwarning:
373372
374373
np.random.seed(24)
375374
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
@@ -379,7 +378,7 @@ For example, after running the following, ``styled.xlsx`` renders as below:
379378
df.iloc[0, 2] = np.nan
380379
df
381380
styled = (df.style
382-
.applymap(lambda val: 'color:red;' if val < 0 else 'color:black;')
381+
.map(lambda val: 'color:red;' if val < 0 else 'color:black;')
383382
.highlight_max())
384383
styled.to_excel('styled.xlsx', engine='openpyxl')
385384

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Removal of prior version deprecations/changes
106106
- :func:`read_excel`, :func:`read_json`, :func:`read_html`, and :func:`read_xml` no longer accept raw string or byte representation of the data. That type of data must be wrapped in a :py:class:`StringIO` or :py:class:`BytesIO` (:issue:`53767`)
107107
- All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`)
108108
- Changed the default value of ``observed`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to ``True`` (:issue:`51811`)
109+
- Removed :meth:`DataFrame.applymap`, :meth:`Styler.applymap` and :meth:`Styler.applymap_index` (:issue:`52364`)
109110
- Removed ``DataFrame.bool`` and ``Series.bool`` (:issue:`51756`)
110111
- Removed ``DataFrame.first`` and ``DataFrame.last`` (:issue:`53710`)
111112
- Removed ``DataFrameGroupBy.grouper`` and ``SeriesGroupBy.grouper`` (:issue:`56521`)

pandas/core/frame.py

-55
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@
227227
MergeHow,
228228
MergeValidate,
229229
MutableMappingT,
230-
NaAction,
231230
NaPosition,
232231
NsmallestNlargestKeep,
233232
PythonFuncType,
@@ -10150,60 +10149,6 @@ def infer(x):
1015010149

1015110150
return self.apply(infer).__finalize__(self, "map")
1015210151

10153-
def applymap(
10154-
self, func: PythonFuncType, na_action: NaAction | None = None, **kwargs
10155-
) -> DataFrame:
10156-
"""
10157-
Apply a function to a Dataframe elementwise.
10158-
10159-
.. deprecated:: 2.1.0
10160-
10161-
DataFrame.applymap has been deprecated. Use DataFrame.map instead.
10162-
10163-
This method applies a function that accepts and returns a scalar
10164-
to every element of a DataFrame.
10165-
10166-
Parameters
10167-
----------
10168-
func : callable
10169-
Python function, returns a single value from a single value.
10170-
na_action : {None, 'ignore'}, default None
10171-
If 'ignore', propagate NaN values, without passing them to func.
10172-
**kwargs
10173-
Additional keyword arguments to pass as keywords arguments to
10174-
`func`.
10175-
10176-
Returns
10177-
-------
10178-
DataFrame
10179-
Transformed DataFrame.
10180-
10181-
See Also
10182-
--------
10183-
DataFrame.apply : Apply a function along input axis of DataFrame.
10184-
DataFrame.map : Apply a function along input axis of DataFrame.
10185-
DataFrame.replace: Replace values given in `to_replace` with `value`.
10186-
10187-
Examples
10188-
--------
10189-
>>> df = pd.DataFrame([[1, 2.12], [3.356, 4.567]])
10190-
>>> df
10191-
0 1
10192-
0 1.000 2.120
10193-
1 3.356 4.567
10194-
10195-
>>> df.map(lambda x: len(str(x)))
10196-
0 1
10197-
0 3 4
10198-
1 5 5
10199-
"""
10200-
warnings.warn(
10201-
"DataFrame.applymap has been deprecated. Use DataFrame.map instead.",
10202-
FutureWarning,
10203-
stacklevel=find_stack_level(),
10204-
)
10205-
return self.map(func, na_action=na_action, **kwargs)
10206-
1020710152
# ----------------------------------------------------------------------
1020810153
# Merging / joining methods
1020910154

pandas/errors/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,11 @@ class CSSWarning(UserWarning):
549549
Examples
550550
--------
551551
>>> df = pd.DataFrame({"A": [1, 1, 1]})
552-
>>> df.style.applymap(lambda x: "background-color: blueGreenRed;").to_excel(
552+
>>> df.style.map(lambda x: "background-color: blueGreenRed;").to_excel(
553553
... "styled.xlsx"
554554
... ) # doctest: +SKIP
555555
CSSWarning: Unhandled color format: 'blueGreenRed'
556-
>>> df.style.applymap(lambda x: "border: 1px solid red red;").to_excel(
556+
>>> df.style.map(lambda x: "border: 1px solid red red;").to_excel(
557557
... "styled.xlsx"
558558
... ) # doctest: +SKIP
559559
CSSWarning: Unhandled color format: 'blueGreenRed'

pandas/io/formats/style.py

-68
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Callable,
1313
overload,
1414
)
15-
import warnings
1615

1716
import numpy as np
1817

@@ -23,7 +22,6 @@
2322
Substitution,
2423
doc,
2524
)
26-
from pandas.util._exceptions import find_stack_level
2725

2826
import pandas as pd
2927
from pandas import (
@@ -2011,42 +2009,6 @@ def map_index(
20112009
)
20122010
return self
20132011

2014-
def applymap_index(
2015-
self,
2016-
func: Callable,
2017-
axis: AxisInt | str = 0,
2018-
level: Level | list[Level] | None = None,
2019-
**kwargs,
2020-
) -> Styler:
2021-
"""
2022-
Apply a CSS-styling function to the index or column headers, elementwise.
2023-
2024-
.. deprecated:: 2.1.0
2025-
2026-
Styler.applymap_index has been deprecated. Use Styler.map_index instead.
2027-
2028-
Parameters
2029-
----------
2030-
func : function
2031-
``func`` should take a scalar and return a string.
2032-
axis : {{0, 1, "index", "columns"}}
2033-
The headers over which to apply the function.
2034-
level : int, str, list, optional
2035-
If index is MultiIndex the level(s) over which to apply the function.
2036-
**kwargs : dict
2037-
Pass along to ``func``.
2038-
2039-
Returns
2040-
-------
2041-
Styler
2042-
"""
2043-
warnings.warn(
2044-
"Styler.applymap_index has been deprecated. Use Styler.map_index instead.",
2045-
FutureWarning,
2046-
stacklevel=find_stack_level(),
2047-
)
2048-
return self.map_index(func, axis, level, **kwargs)
2049-
20502012
def _map(self, func: Callable, subset: Subset | None = None, **kwargs) -> Styler:
20512013
func = partial(func, **kwargs) # map doesn't take kwargs?
20522014
if subset is None:
@@ -2117,36 +2079,6 @@ def map(self, func: Callable, subset: Subset | None = None, **kwargs) -> Styler:
21172079
)
21182080
return self
21192081

2120-
@Substitution(subset=subset_args)
2121-
def applymap(
2122-
self, func: Callable, subset: Subset | None = None, **kwargs
2123-
) -> Styler:
2124-
"""
2125-
Apply a CSS-styling function elementwise.
2126-
2127-
.. deprecated:: 2.1.0
2128-
2129-
Styler.applymap has been deprecated. Use Styler.map instead.
2130-
2131-
Parameters
2132-
----------
2133-
func : function
2134-
``func`` should take a scalar and return a string.
2135-
%(subset)s
2136-
**kwargs : dict
2137-
Pass along to ``func``.
2138-
2139-
Returns
2140-
-------
2141-
Styler
2142-
"""
2143-
warnings.warn(
2144-
"Styler.applymap has been deprecated. Use Styler.map instead.",
2145-
FutureWarning,
2146-
stacklevel=find_stack_level(),
2147-
)
2148-
return self.map(func, subset, **kwargs)
2149-
21502082
def set_table_attributes(self, attributes: str) -> Styler:
21512083
"""
21522084
Set the table attributes added to the ``<table>`` HTML element.

pandas/tests/frame/methods/test_map.py

-8
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,3 @@ def test_map_invalid_na_action(float_frame):
205205
# GH 23803
206206
with pytest.raises(ValueError, match="na_action must be .*Got 'abc'"):
207207
float_frame.map(lambda x: len(str(x)), na_action="abc")
208-
209-
210-
def test_applymap_deprecated():
211-
# GH52353
212-
df = DataFrame({"a": [1, 2, 3]})
213-
msg = "DataFrame.applymap has been deprecated. Use DataFrame.map instead."
214-
with tm.assert_produces_warning(FutureWarning, match=msg):
215-
df.applymap(lambda x: x)

pandas/tests/io/formats/style/test_style.py

-12
Original file line numberDiff line numberDiff line change
@@ -1586,15 +1586,3 @@ def test_output_buffer(mi_styler, format):
15861586
# gh 47053
15871587
with tm.ensure_clean(f"delete_me.{format}") as f:
15881588
getattr(mi_styler, f"to_{format}")(f)
1589-
1590-
1591-
def test_deprecation_warning_for_usage_of_aaply_map_index_method_of_styler_object():
1592-
# 56717 https://github.com/pandas-dev/pandas/issues/56717
1593-
df = DataFrame([[1, 2], [3, 4]], index=["A", "B"])
1594-
msg = "Styler.applymap_index has been deprecated. Use Styler.map_index instead."
1595-
1596-
def color_b(s):
1597-
return "background-color:yellow;"
1598-
1599-
with tm.assert_produces_warning(FutureWarning, match=msg):
1600-
df.style.applymap_index(color_b, axis="columns")

0 commit comments

Comments
 (0)