Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pd.isnull() raises AttributeError on Pandas type objects #27482

Closed
bribass opened this issue Jul 19, 2019 · 1 comment · Fixed by #27664

Comments

@bribass
Copy link

commented Jul 19, 2019

import pandas as pd

x = pd.Series([1,2,3,4])
xt = type(x)
pd.isnull(xt)
## Traceback (most recent call last):
##   File "<input>", line 1, in <module>
##   File "/home/bbassett/venv37/lib/python3.7/site-packages/pandas/core/dtypes/missing.py", line 122, in isna
##     return _isna(obj)
##   File "/home/bbassett/venv37/lib/python3.7/site-packages/pandas/core/dtypes/missing.py", line 145, in _isna_new
##     return _isna_ndarraylike(obj)
##   File "/home/bbassett/venv37/lib/python3.7/site-packages/pandas/core/dtypes/missing.py", line 225, in _isna_ndarraylike
##     dtype = values.dtype
## AttributeError: 'property' object has no attribute 'dtype'

y = pd.DataFrame({"col": [1,2,3,4]})
yt = type(y)
pd.isnull(yt)
## Traceback (most recent call last):
##   File "<input>", line 1, in <module>
##   File "/home/bbassett/venv37/lib/python3.7/site-packages/pandas/core/dtypes/missing.py", line 122, in isna
##     return _isna(obj)
##   File "/home/bbassett/venv37/lib/python3.7/site-packages/pandas/core/dtypes/missing.py", line 147, in _isna_new
##     return obj._constructor(obj._data.isna(func=isna))
## AttributeError: 'NoneType' object has no attribute 'isna'

Problem description

I'm using a list comprehension and pd.isnull() to remove empty items from a list ([x for x in l if not pd.isnull(x)]). When one of my users passes a pandas type object to this logic, it gums up the works by raising an AttributeError. This logic works as expected with type objects from Python's builtins:

import pandas as pd

z = "This is a test."
zt = type(z)
pd.isnull(zt)
## False

Expected Output

Both calls to pd.isnull() above should return False. The type objects are not null/None/NaN/missing.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.0-5-amd64
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.0
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@TomAugspurger

This comment has been minimized.

Copy link
Contributor

commented Jul 19, 2019

Probably need to include something like not isinstance(obj, type) in this block

    128 def _isna_new(obj):
    129     if is_scalar(obj):
    130         return libmissing.checknull(obj)
    131     # hack (for now) because MI registers as ndarray
    132     elif isinstance(obj, ABCMultiIndex):
    133         raise NotImplementedError("isna is not defined for MultiIndex")
    134     elif isinstance(
    135         obj,
    136         (
    137             ABCSeries,
    138             np.ndarray,
    139             ABCIndexClass,
    140             ABCExtensionArray,
    141             ABCDatetimeArray,
    142             ABCTimedeltaArray,
    143         ),
    144     ):
--> 145         return _isna_ndarraylike(obj)

@TomAugspurger TomAugspurger added this to the 0.25.1 milestone Jul 19, 2019

SvoONs added a commit to SvoONs/pandas that referenced this issue Jul 30, 2019
SvoONs added a commit to SvoONs/pandas that referenced this issue Jul 30, 2019
SvoONs added a commit to SvoONs/pandas that referenced this issue Jul 30, 2019
pradeepb2505 added a commit to pradeepb2505/pandas that referenced this issue Aug 18, 2019
pradeepb2505 added a commit to pradeepb2505/pandas that referenced this issue Aug 18, 2019
pradeepb2505 added a commit to pradeepb2505/pandas that referenced this issue Aug 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.