pd.isna / pd.isnull raising mypy error for None
See original GitHub issueDescribe the bug pd.isna / pd.isnull raising mypy error for None
To Reproduce
file.py
import pandas as pd
pd.isnull(None)
~ pdnull ❯ mypy file.py 9s 15:54:43
file.py:2: error: No overload variant matches argument type "None"
file.py:2: note: Possible overload variants:
file.py:2: note: def isna(obj: DataFrame) -> DataFrame
file.py:2: note: def isna(obj: Series[Any]) -> Series[bool]
file.py:2: note: def isna(obj: Union[Index, List[Any], ExtensionArray, ndarray[Any, Any]]) -> ndarray[Any, dtype[bool_]]
file.py:2: note: def isna(obj: Union[str, bytes, date, datetime, timedelta, bool, complex, Timestamp, Timedelta]) -> bool
file.py:2: note: def isna(obj: Union[NaTType, NAType]) -> Literal[True]
Found 1 error in 1 file (checked 1 source file)
Please complete the following information:
- MacOS
- mypy-0.971
- pandas: 1.5.0
- python: 3.9
- pandas-stubs-1.4.4.220919
Expected behaviour: No issue since pd.isnull(None) == True
and works fine
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Why does pandas isnull() work but ==None not work?
As the comment above states, missing data in pandas is represented by a NaN, where NaN is a numerical value, i.e float type....
Read more >BUG: incorrect type hint for subset in dropna #49702 - GitHub
I have confirmed this bug exists on the main branch of pandas. Reproducible Example. import pandas as pd data = {'col1 ...
Read more >pandas.DataFrame.isnull — pandas 1.5.2 documentation
Return a boolean same-sized object indicating if the values are NA. NA values, such as None or numpy.NaN , gets mapped to True...
Read more >isna(), isnull(), notna(), notnull(), pad(), replace() – Finxter
Line [3] uses isna() to set the empty values ( np.nan , pd.NaT , None ) to True and the remainder (valid values)...
Read more >get index where non non nan value pandas Code Example
Python, pandas #Count missing values for each column of the dataframe df df.isnull().sum()
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The inline annotations of
isna
cover anyobject
(in the fallback overload) butNone
is not special-cased in the first overload to returnbool
: https://github.com/pandas-dev/pandas/blob/ce143a2fb0a41e78c85d5311d0e159552d651b00/pandas/core/dtypes/missing.py#L81While we cannot enumerate all possible inputs for isna (would probably create overlapping overloads), I’m +1 on adding
None
.The deep question is whether it is legit code? Are there examples of usage like this in the docs, even if not in the func docs?
Actually function doc says works on any scalar object, which is pretty wide.