-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fix SparseSeries reindex by using Series implementation #15461
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
Changes from 5 commits
55b99f8
7945cb4
af99190
922c7b0
d6a46da
9084246
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -504,6 +504,11 @@ def test_loc(self): | |
exp = orig.loc[[1, 3, 4, 5]].to_sparse() | ||
tm.assert_sp_series_equal(result, exp) | ||
|
||
# single element list (GH 15447) | ||
result = sparse.loc[['A']] | ||
exp = orig.loc[['A']].to_sparse() | ||
tm.assert_sp_series_equal(result, exp) | ||
|
||
# dense array | ||
result = sparse.loc[orig % 2 == 1] | ||
exp = orig.loc[orig % 2 == 1].to_sparse() | ||
|
@@ -537,6 +542,35 @@ def test_loc_slice(self): | |
orig.loc['A':'B'].to_sparse()) | ||
tm.assert_sp_series_equal(sparse.loc[:'B'], orig.loc[:'B'].to_sparse()) | ||
|
||
def test_reindex(self): | ||
# GH 15447 | ||
orig = self.orig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number |
||
sparse = self.sparse | ||
|
||
res = sparse.reindex([('A', 0), ('C', 1)]) | ||
exp = orig.reindex([('A', 0), ('C', 1)]).to_sparse() | ||
tm.assert_sp_series_equal(res, exp) | ||
|
||
# On specific level: | ||
res = sparse.reindex(['A', 'C', 'B'], level=0) | ||
exp = orig.reindex(['A', 'C', 'B'], level=0).to_sparse() | ||
tm.assert_sp_series_equal(res, exp) | ||
|
||
# single element list (GH 15447) | ||
res = sparse.reindex(['A'], level=0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above, this is True for Series, but NOT for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I meant line 640 |
||
exp = orig.reindex(['A'], level=0).to_sparse() | ||
tm.assert_sp_series_equal(res, exp) | ||
|
||
with tm.assertRaises(TypeError): | ||
# Incomplete keys are not accepted for reindexing: | ||
sparse.reindex(['A', 'C']) | ||
|
||
# "copy" argument: | ||
res = sparse.reindex(sparse.index, copy=True) | ||
exp = orig.reindex(orig.index, copy=True).to_sparse() | ||
tm.assert_sp_series_equal(res, exp) | ||
self.assertIsNot(sparse, res) | ||
|
||
|
||
class TestSparseDataFrameIndexing(tm.TestCase): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave the signature as it was
use a shared_doc to construct the doc-strings (see how its done in Series itself).