-
-
Notifications
You must be signed in to change notification settings - Fork 151
Description
Describe the bug
Recently #972 introduced a TypeIs annotation for pd.isna. The annotation states that the function returns True if and only if the input value is one of the types NaTType | NAType | None. However, this is not correct, since the function also returns True for the value float('nan'), which is of type float.
To Reproduce
- Provide a minimal runnable
pandasexample that is not properly checked by the stubs.
from pandas import isna
def main() -> None:
foo: float = float('nan')
if isna(foo) and 1 == 1:
print('not a number')
else:
print('is a number')
if __name__ == '__main__':
main()
The output is not a number, but because of the TypeIs annotation, mypy thinks that line is unreachable
- Indicate which type checker you are using (
mypyorpyright).
mypy 1.10.1
- Show the error message received from that type checker while checking your example.
type_test.py:6: error: Right operand of "and" is never evaluated [unreachable]
if isna(foo) and 1 == 1:
^~~~~~
type_test.py:7: error: Statement is unreachable [unreachable]
print('not a number')
^~~~~~~~~~~~~~~~~~~~~
Found 2 errors in 1 file (checked 1 source file)
Please complete the following information:
- OS: [e.g. Windows, Linux, MacOS]: Windows
- OS Version [e.g. 22]: 11
- python version: 3.11.4
- version of type checker: 1.10.1
- version of installed
pandas-stubs: 2.2.2.240909
Additional context
Add any other context about the problem here.