Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,14 @@ class DataFrame(NDFrame, OpsMixin):
) -> DataFrame: ...

# Add spacing between apply() overloads and remaining annotations
# Deprecated in pandas 2.1.0 and later
def applymap(
self, func: Callable, na_action: Literal["ignore"] | None = ..., **kwargs
) -> DataFrame: ...
# In pandas 2.1.0 and later: applymap is renamed map, applymap is deprecated
def map(
self, func: Callable, na_action: Literal["ignore"] | None = ..., **kwargs
) -> DataFrame: ...
def join(
self,
other: DataFrame | Series | list[DataFrame | Series],
Expand Down
12 changes: 12 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ def gethead(s: pd.Series, y: int) -> pd.Series:
)


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


# Added in pandas 2.1.0
def test_types_map() -> None:
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
df.map(lambda x: x**2)
df.map(np.exp)
df.map(str)
# na_action parameter was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
df.map(np.exp, na_action="ignore")
df.map(str, na_action=None)


def test_types_element_wise_arithmetic() -> None:
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
df2 = pd.DataFrame(data={"col1": [10, 20], "col3": [3, 4]})
Expand Down