Skip to content

Commit 05d6a52

Browse files
authored
Add types for pandas.DataFrame.map (#801)
* Add types for pandas.DataFrame.map * Made some changes: - Removed stub and test for applymap - Downgraded pyright - Ran the precommit (it just removes some whitespace) * Remove comment referencing deprecated applymap * add GH774 comment
1 parent e7d8661 commit 05d6a52

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ class DataFrame(NDFrame, OpsMixin):
13161316
) -> DataFrame: ...
13171317

13181318
# Add spacing between apply() overloads and remaining annotations
1319-
def applymap(
1319+
def map(
13201320
self, func: Callable, na_action: Literal["ignore"] | None = ..., **kwargs
13211321
) -> DataFrame: ...
13221322
def join(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mypy = "1.6.0"
3939
pandas = "2.1.1"
4040
pyarrow = ">=10.0.1"
4141
pytest = ">=7.1.2"
42-
pyright = ">=1.1.331"
42+
pyright = "==1.1.331"
4343
poethepoet = ">=0.16.5"
4444
loguru = ">=0.6.0"
4545
typing-extensions = ">=4.4.0"

tests/test_frame.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -728,17 +728,15 @@ def gethead(s: pd.Series, y: int) -> pd.Series:
728728
)
729729

730730

731-
def test_types_applymap() -> None:
732-
with pytest_warns_bounded(
733-
FutureWarning, "DataFrame.applymap has been deprecated", lower="2.0.99"
734-
):
735-
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
736-
df.applymap(lambda x: x**2)
737-
df.applymap(np.exp)
738-
df.applymap(str)
739-
# na_action parameter was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
740-
df.applymap(np.exp, na_action="ignore")
741-
df.applymap(str, na_action=None)
731+
def test_types_map() -> None:
732+
# GH774
733+
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
734+
df.map(lambda x: x**2)
735+
df.map(np.exp)
736+
df.map(str)
737+
# na_action parameter was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
738+
df.map(np.exp, na_action="ignore")
739+
df.map(str, na_action=None)
742740

743741

744742
def test_types_element_wise_arithmetic() -> None:

0 commit comments

Comments
 (0)