", line 1, in ## File "/home/bbassett/venv37/lib/python3.7/sit...">

pd.isnull() raises AttributeError on Pandas type objects · Issue #27482 · pandas-dev/pandas (original) (raw)

import pandas as pd

x = pd.Series([1,2,3,4]) xt = type(x) pd.isnull(xt)

Traceback (most recent call last):

File "", line 1, in

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 "", line 1, in

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