question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pd.isna / pd.isnull raising mypy error for None

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
twoertweincommented, Sep 20, 2022

The inline annotations of isna cover any object (in the fallback overload) but None is not special-cased in the first overload to return bool: https://github.com/pandas-dev/pandas/blob/ce143a2fb0a41e78c85d5311d0e159552d651b00/pandas/core/dtypes/missing.py#L81

While we cannot enumerate all possible inputs for isna (would probably create overlapping overloads), I’m +1 on adding None.

1reaction
bashtagecommented, Sep 20, 2022

But the documentation does not actually say it can be used on any type. If we follow the documentation I think a lot of people will get type errors on perfectly legit code.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found