Skip to content

DataFrame.dropna() not working with sparse columns #28287

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

Closed
rjboczar opened this issue Sep 4, 2019 · 4 comments · Fixed by #34879
Closed

DataFrame.dropna() not working with sparse columns #28287

rjboczar opened this issue Sep 4, 2019 · 4 comments · Fixed by #34879
Assignees
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@rjboczar
Copy link

rjboczar commented Sep 4, 2019

import numpy as np
import pandas as pd

A = pd.DataFrame({'a': [0,1], 'b': pd.SparseArray([np.nan, 1])})

# Prints empty DataFrame
A.dropna()

Not sure if I'm using this correctly, but I'd expect only the first row to be dropped.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.1
numpy : 1.16.4
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
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 : 2.10.1
IPython : 7.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@TomAugspurger
Copy link
Contributor

Huh, the bug is in actually in DataFrame.__invert__

In [39]: pd.isna(A)
Out[39]:
       a      b
0  False   True
1  False  False

In [40]: ~pd.isna(A)
Out[40]:
    a   b
0  -1  -2
1  -1  -1

Right now we call com.values_from_object. Ideally we would do some kind of blockwise __invert__ and wrap.

cc @jbrockmendel.

@TomAugspurger TomAugspurger added Numeric Operations Arithmetic, Comparison, and Logical operations Sparse Sparse Data Type labels Sep 9, 2019
@mroeschke
Copy link
Member

This looks to work on master. Could use a test I suppose

In [19]: import numpy as np
    ...: import pandas as pd
    ...:
    ...: A = pd.DataFrame({'a': [0,1], 'b': pd.arrays.SparseArray([np.nan, 1])})
    ...:
    ...: A.dropna()
Out[19]:
   a    b
1  1  1.0

In [23]: pd.__version__
Out[23]: '1.1.0.dev0+1361.g77a0f19c5'

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Numeric Operations Arithmetic, Comparison, and Logical operations Sparse Sparse Data Type labels Apr 25, 2020
@Dhron
Copy link

Dhron commented May 12, 2020

Hey, I'd like to work on writing a test for this, is that okay? =)

@MBrouns
Copy link
Contributor

MBrouns commented Jun 20, 2020

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants