Skip to content

Commit 911dc2e

Browse files
committed
Add types for pandas.DataFrame.map
1 parent e7d8661 commit 911dc2e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,9 +1316,14 @@ class DataFrame(NDFrame, OpsMixin):
13161316
) -> DataFrame: ...
13171317

13181318
# Add spacing between apply() overloads and remaining annotations
1319+
# Deprecated in pandas 2.1.0 and later
13191320
def applymap(
13201321
self, func: Callable, na_action: Literal["ignore"] | None = ..., **kwargs
13211322
) -> DataFrame: ...
1323+
# In pandas 2.1.0 and later: applymap is renamed map, applymap is deprecated
1324+
def map(
1325+
self, func: Callable, na_action: Literal["ignore"] | None = ..., **kwargs
1326+
) -> DataFrame: ...
13221327
def join(
13231328
self,
13241329
other: DataFrame | Series | list[DataFrame | Series],

tests/test_frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ def gethead(s: pd.Series, y: int) -> pd.Series:
728728
)
729729

730730

731+
# Deprecated in pandas 2.1.0
731732
def test_types_applymap() -> None:
732733
with pytest_warns_bounded(
733734
FutureWarning, "DataFrame.applymap has been deprecated", lower="2.0.99"
@@ -741,6 +742,17 @@ def test_types_applymap() -> None:
741742
df.applymap(str, na_action=None)
742743

743744

745+
# Added in pandas 2.1.0
746+
def test_types_map() -> None:
747+
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
748+
df.map(lambda x: x**2)
749+
df.map(np.exp)
750+
df.map(str)
751+
# na_action parameter was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
752+
df.map(np.exp, na_action="ignore")
753+
df.map(str, na_action=None)
754+
755+
744756
def test_types_element_wise_arithmetic() -> None:
745757
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
746758
df2 = pd.DataFrame(data={"col1": [10, 20], "col3": [3, 4]})

0 commit comments

Comments
 (0)