|
5 | 5 |
|
6 | 6 | from decimal import Decimal
|
7 | 7 | from functools import partial
|
| 8 | +from typing import ( |
| 9 | + TYPE_CHECKING, |
| 10 | + overload, |
| 11 | +) |
8 | 12 |
|
9 | 13 | import numpy as np
|
10 | 14 |
|
|
16 | 20 | NaT,
|
17 | 21 | iNaT,
|
18 | 22 | )
|
19 |
| -from pandas._typing import ( |
20 |
| - ArrayLike, |
21 |
| - DtypeObj, |
22 |
| - npt, |
23 |
| -) |
24 | 23 |
|
25 | 24 | from pandas.core.dtypes.common import (
|
26 | 25 | DT64NS_DTYPE,
|
|
54 | 53 | )
|
55 | 54 | from pandas.core.dtypes.inference import is_list_like
|
56 | 55 |
|
| 56 | +if TYPE_CHECKING: |
| 57 | + from pandas._typing import ( |
| 58 | + ArrayLike, |
| 59 | + DtypeObj, |
| 60 | + NDFrame, |
| 61 | + NDFrameT, |
| 62 | + Scalar, |
| 63 | + npt, |
| 64 | + ) |
| 65 | + |
| 66 | + from pandas.core.indexes.base import Index |
| 67 | + |
| 68 | + |
57 | 69 | isposinf_scalar = libmissing.isposinf_scalar
|
58 | 70 | isneginf_scalar = libmissing.isneginf_scalar
|
59 | 71 |
|
|
63 | 75 | _dtype_str = np.dtype(str)
|
64 | 76 |
|
65 | 77 |
|
66 |
| -def isna(obj): |
| 78 | +@overload |
| 79 | +def isna(obj: Scalar) -> bool: |
| 80 | + ... |
| 81 | + |
| 82 | + |
| 83 | +@overload |
| 84 | +def isna( |
| 85 | + obj: ArrayLike | Index | list, |
| 86 | +) -> npt.NDArray[np.bool_]: |
| 87 | + ... |
| 88 | + |
| 89 | + |
| 90 | +@overload |
| 91 | +def isna(obj: NDFrameT) -> NDFrameT: |
| 92 | + ... |
| 93 | + |
| 94 | + |
| 95 | +# handle unions |
| 96 | +@overload |
| 97 | +def isna(obj: NDFrameT | ArrayLike | Index | list) -> NDFrameT | npt.NDArray[np.bool_]: |
| 98 | + ... |
| 99 | + |
| 100 | + |
| 101 | +@overload |
| 102 | +def isna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame: |
| 103 | + ... |
| 104 | + |
| 105 | + |
| 106 | +def isna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame: |
67 | 107 | """
|
68 | 108 | Detect missing values for an array-like object.
|
69 | 109 |
|
@@ -284,7 +324,35 @@ def _isna_string_dtype(values: np.ndarray, inf_as_na: bool) -> npt.NDArray[np.bo
|
284 | 324 | return result
|
285 | 325 |
|
286 | 326 |
|
287 |
| -def notna(obj): |
| 327 | +@overload |
| 328 | +def notna(obj: Scalar) -> bool: |
| 329 | + ... |
| 330 | + |
| 331 | + |
| 332 | +@overload |
| 333 | +def notna( |
| 334 | + obj: ArrayLike | Index | list, |
| 335 | +) -> npt.NDArray[np.bool_]: |
| 336 | + ... |
| 337 | + |
| 338 | + |
| 339 | +@overload |
| 340 | +def notna(obj: NDFrameT) -> NDFrameT: |
| 341 | + ... |
| 342 | + |
| 343 | + |
| 344 | +# handle unions |
| 345 | +@overload |
| 346 | +def notna(obj: NDFrameT | ArrayLike | Index | list) -> NDFrameT | npt.NDArray[np.bool_]: |
| 347 | + ... |
| 348 | + |
| 349 | + |
| 350 | +@overload |
| 351 | +def notna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame: |
| 352 | + ... |
| 353 | + |
| 354 | + |
| 355 | +def notna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame: |
288 | 356 | """
|
289 | 357 | Detect non-missing values for an array-like object.
|
290 | 358 |
|
@@ -362,7 +430,7 @@ def notna(obj):
|
362 | 430 | Name: 1, dtype: bool
|
363 | 431 | """
|
364 | 432 | res = isna(obj)
|
365 |
| - if is_scalar(res): |
| 433 | + if isinstance(res, bool): |
366 | 434 | return not res
|
367 | 435 | return ~res
|
368 | 436 |
|
|
0 commit comments