Repository: pandas-dev/pandas
Pull request: TST: Add test to verify 'dropna' behaviour on SparseArray
verify that calling `dropna` on a pd.SparseArray does not inadvertently drop non-na records on both DataFrames and the SparseArray itself.

- [x] closes #28287
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry (not applicable?)


Problem statement:
DataFrame.dropna() not working with sparse columns
```python
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()``

<details>

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


</details>

Hints from issue discussion:
Huh, the bug is in actually in `DataFrame.__invert__`

```python
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.
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'
```
Hey, I'd like to work on writing a test for this, is that okay? =) 
take

Commit message: Add test to verify `dropna` behaviour on `pd.SparseArray`

verify that calling `dropna` on a pd.SparseArray does not
inadvertently drop non-na records on both DataFrames
and the SparseArray itself.

Patch to review:
diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py
index 2f2907fbaaebc..664ef397dd32f 100644
--- a/pandas/tests/arrays/sparse/test_array.py
+++ b/pandas/tests/arrays/sparse/test_array.py
@@ -1295,3 +1295,14 @@ def test_map_missing():
 
     result = arr.map({0: 10, 1: 11})
     tm.assert_sp_array_equal(result, expected)
+
+
+def test_dropna_sparse_column_doesnt_drop_nonna():
+    # GH-28287
+    arr = SparseArray([np.nan, 1])
+    exp = SparseArray([1.0])
+    tm.assert_sp_array_equal(arr.dropna(), exp)
+
+    df = pd.DataFrame({"a": [0, 1], "b": arr})
+    expected_df = pd.DataFrame({"a": [1], "b": exp}, index=pd.Int64Index([1]))
+    tm.assert_equal(df.dropna(), expected_df)


Code review comments:
diff_hunk: @@ -1295,3 +1295,14 @@ def test_map_missing():
 
     result = arr.map({0: 10, 1: 11})
     tm.assert_sp_array_equal(result, expected)
+
+
+def test_dropna_sparse_column_doesnt_drop_nonna():
+    # GH-28287
+    arr = SparseArray([np.nan, 1])
path: pandas/tests/arrays/sparse/test_array.py
text: @user1:

```suggestion
    arr = SparseArray([np.nan, 1], fill_value=fill_value)
```

Could you parametrize this test over a fill_value of np.nan and 1?

@author:
Just to check, the expected behaviour would be the same in case fill_value=1, correct?

@user1:
Yes, the expected result is the same. But I want to ensure that it works both in cases where the "missing value" is the fill value and where it is not the fill value.