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

BUG: pd.NA acts differently when inside/outside a series/dataframe with object dtype #33066

Open
HYChou0515 opened this issue Mar 27, 2020 · 3 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions NA - MaskedArrays Related to pd.NA and nullable extension arrays

Comments

@HYChou0515
Copy link

HYChou0515 commented Mar 27, 2020

Code Sample, a copy-pastable example if possible

# return pd.NA, cool
pd.NA | pd.NA

# return False, not cool
pd.Series([pd.NA]) | pd.Series([pd.NA])

Problem description

pd.NA acts differently when inside/outside a series/dataframe may be confusing. It force me to handle each entry of a series/dataframe.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-91-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : None.None

pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0
Cython : None
pytest : 5.3.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@TomAugspurger
Copy link
Contributor

You've created an object-dtype Series

In [4]: pd.Series([pd.NA])
Out[4]:
0    <NA>
dtype: object

If you create a boolean Series with dtype='boolean' you'll get the expected result.

Fixing this may be possible, but I don't think it should be a high priority.

@TomAugspurger TomAugspurger added Dtype Conversions Unexpected or buggy dtype conversions NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Mar 27, 2020
@jorisvandenbossche jorisvandenbossche changed the title pd.NA acts differently when inside/outside a series/dataframe BUG: pd.NA acts differently when inside/outside a series/dataframe with object dtype Mar 27, 2020
@jorisvandenbossche
Copy link
Member

Given the several issues with pd.NA in object dtype, should we consider warning about it? (cfr #32931)

@TomAugspurger
Copy link
Contributor

By warning, do you mean something in the docs or in code?

+1 to something in the docs. I don't think there's any good reason to end up with an NA in object dtype.

For code, detecting NA would be difficult / slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

No branches or pull requests

4 participants