Skip to content

Commit cb48905

Browse files
authored
[fix] No overload variant of "isna" matches argument type "NAType" [call-overload] (#279)
* [fix] No overload variant of "isna" matches argument type "NAType" [call-overload] Update `isna` & `notna` overloads inside pandas-stubs/core/dtypes/missing.pyi Update `test_isna` function inside tests/test_pandas.py file Refs #264 * [fix] No overload variant of "isna" matches argument type "NAType" [call-overload] Update `isna` & `notna` overloads inside pandas-stubs/core/dtypes/missing.pyi Update `test_isna` function inside tests/test_pandas.py file Refs #264 * [fix] No overload variant of "isna" matches argument type "NAType" [call-overload] Update `isna` & `notna` overloads inside pandas-stubs/core/dtypes/missing.pyi Update `test_isna` function inside tests/test_pandas.py file Refs #264 * [fix] No overload variant of "isna" matches argument type "NAType" [call-overload] Update `isna` & `notna` overloads inside pandas-stubs/core/dtypes/missing.pyi Update `test_isna` function inside tests/test_pandas.py file Refs #264 * [fix] No overload variant of "isna" matches argument type "NAType" [call-overload] Update `isna` & `notna` overloads inside pandas-stubs/core/dtypes/missing.pyi Update `test_isna` function inside tests/test_pandas.py file Refs #264
1 parent f1882b7 commit cb48905

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

pandas-stubs/core/dtypes/missing.pyi

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
from typing import overload
1+
from typing import (
2+
Literal,
3+
overload,
4+
)
25

36
import numpy as np
7+
from numpy import typing as npt
48
from pandas import (
59
DataFrame,
610
Index,
711
Series,
812
)
913

14+
from pandas._libs.missing import NAType
15+
from pandas._libs.tslibs import NaTType
1016
from pandas._typing import (
1117
ArrayLike,
1218
Scalar,
@@ -20,9 +26,11 @@ def isna(obj: DataFrame) -> DataFrame: ...
2026
@overload
2127
def isna(obj: Series) -> Series[bool]: ...
2228
@overload
23-
def isna(obj: Index | list | ArrayLike) -> np.ndarray: ...
29+
def isna(obj: Index | list | ArrayLike) -> npt.NDArray[np.bool_]: ...
2430
@overload
2531
def isna(obj: Scalar) -> bool: ...
32+
@overload
33+
def isna(obj: NaTType | NAType) -> Literal[True]: ...
2634

2735
isnull = isna
2836

@@ -31,8 +39,10 @@ def notna(obj: DataFrame) -> DataFrame: ...
3139
@overload
3240
def notna(obj: Series) -> Series[bool]: ...
3341
@overload
34-
def notna(obj: Index | list | ArrayLike) -> np.ndarray: ...
42+
def notna(obj: Index | list | ArrayLike) -> npt.NDArray[np.bool_]: ...
3543
@overload
3644
def notna(obj: Scalar) -> bool: ...
45+
@overload
46+
def notna(obj: NaTType | NAType) -> Literal[False]: ...
3747

3848
notnull = notna

tests/test_pandas.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from typing import (
44
TYPE_CHECKING,
55
Any,
6+
Literal,
67
Union,
78
)
89

910
import numpy as np
11+
from numpy import typing as npt
1012
import pandas as pd
1113
from pandas.api.extensions import ExtensionArray
1214
from typing_extensions import assert_type
@@ -112,13 +114,30 @@ def test_types_json_normalize() -> None:
112114

113115

114116
def test_isna() -> None:
115-
s = pd.Series([1, np.nan, 3.2])
116-
check(assert_type(pd.isna(s), "pd.Series[bool]"), pd.Series, bool)
117-
b: bool = pd.isna(np.nan)
118-
ar: np.ndarray = pd.isna(s.to_list())
119-
check(assert_type(pd.notna(s), "pd.Series[bool]"), pd.Series, bool)
120-
b2: bool = pd.notna(np.nan)
121-
ar2: np.ndarray = pd.notna(s.to_list())
117+
# https://github.com/pandas-dev/pandas-stubs/issues/264
118+
s1 = pd.Series([1, np.nan, 3.2])
119+
check(assert_type(pd.isna(s1), "pd.Series[bool]"), pd.Series, bool)
120+
121+
s2 = pd.Series([1, 3.2])
122+
check(assert_type(pd.notna(s2), "pd.Series[bool]"), pd.Series, bool)
123+
124+
df1 = pd.DataFrame({"a": [1, 2, 1, 2], "b": [1, 1, 2, np.nan]})
125+
check(assert_type(pd.isna(df1), "pd.DataFrame"), pd.DataFrame)
126+
127+
idx1 = pd.Index([1, 2, np.nan])
128+
check(assert_type(pd.isna(idx1), npt.NDArray[np.bool_]), np.ndarray, np.bool_)
129+
130+
idx2 = pd.Index([1, 2])
131+
check(assert_type(pd.notna(idx2), npt.NDArray[np.bool_]), np.ndarray, np.bool_)
132+
133+
assert check(assert_type(pd.isna(pd.NA), Literal[True]), bool)
134+
assert not check(assert_type(pd.notna(pd.NA), Literal[False]), bool)
135+
136+
assert check(assert_type(pd.isna(pd.NaT), Literal[True]), bool)
137+
assert not check(assert_type(pd.notna(pd.NaT), Literal[False]), bool)
138+
139+
check(assert_type(pd.isna(2.5), bool), bool)
140+
check(assert_type(pd.notna(2.5), bool), bool)
122141

123142

124143
# GH 55

0 commit comments

Comments
 (0)