Skip to content

Fix nonzero of a SparseArray #21175

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

Merged
merged 22 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pandas/tests/sparse/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,3 +1350,11 @@ def test_assign_with_sparse_frame(self):

for column in res.columns:
assert type(res[column]) is SparseSeries

def test_dropna(self):
tm.assert_sp_frame_equal(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the result= and expected= format

add the issue number as a comment

pd.SparseDataFrame({"F2": [0, 1]}),
pd.SparseDataFrame(
{"F1": [float('nan'), float('nan')], "F2": [0, 1]}
).dropna(axis=1, inplace=False, how='all')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test for inplace=True/False, how='all', 'any'

via parametrization

)
19 changes: 19 additions & 0 deletions pandas/tests/sparse/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,25 @@ def tests_indexing_with_sparse(self, kind, fill):
s.iloc[indexer]


class TestSparseArray(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this to pandas/tests/arrays/sparse/test_array.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both things completed 👍, sorry for it.


def test_nonzero(self):
sa = pd.SparseArray([
float('nan'),
float('nan'),
1, 0, 0,
2, 0, 0, 0,
3, 0, 0
])
tm.assert_numpy_array_equal(np.array([2, 5, 9], dtype=np.int32),
sa.nonzero()[0])

sa = pd.SparseArray(
[0, 0, 1, 0, 0, 2, 0, 0, 0, 3, 0, 0])
tm.assert_numpy_array_equal(np.array([2, 5, 9], dtype=np.int32),
sa.nonzero()[0])


class TestSparseSeriesMultiIndexing(TestSparseSeriesIndexing):

def setup_method(self, method):
Expand Down