|
3 | 3 | from typing import (
|
4 | 4 | TYPE_CHECKING,
|
5 | 5 | Any,
|
| 6 | + Literal, |
6 | 7 | Union,
|
7 | 8 | )
|
8 | 9 |
|
9 | 10 | import numpy as np
|
| 11 | +from numpy import typing as npt |
10 | 12 | import pandas as pd
|
11 | 13 | from pandas.api.extensions import ExtensionArray
|
12 | 14 | from typing_extensions import assert_type
|
@@ -112,13 +114,30 @@ def test_types_json_normalize() -> None:
|
112 | 114 |
|
113 | 115 |
|
114 | 116 | 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) |
122 | 141 |
|
123 | 142 |
|
124 | 143 | # GH 55
|
|
0 commit comments