-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Slicing subclasses of SparseDataFrames. #13787
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
Conversation
@@ -373,7 +373,9 @@ def _slice(self, slobj, axis=0, kind=None): | |||
new_index = self.index | |||
new_columns = self.columns[slobj] | |||
|
|||
return self.reindex(index=new_index, columns=new_columns) | |||
return self._constructor(data=self.reindex(index=new_index, |
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.
try not to use \
, instead:
return self._constructor(
data=self.reindex(index=new_index,
columns=new_columns)).__finalize__(self)
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.
can't we fix .reindex
to return subclass?
is there a specific issue for this? @sinhrks pls have a look |
Current coverage is 85.25% (diff: 100%)@@ master #13787 diff @@
==========================================
Files 140 140
Lines 50455 50471 +16
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 43014 43031 +17
+ Misses 7441 7440 -1
Partials 0 0
|
Thank you for your comments, I made changes according to them:
|
|
||
Parameters | ||
---------- | ||
left : DataFrame |
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.
nice docstring:) SparseDataFrame
.
@sstanovnik thx for update! i linked the PR from #10627, so new issue is not needed unless there is something which is not fixid in this PR. |
Should I also squash the commits? |
not mandatory on your side. will be done during merge. |
Typo fixed, rebased. |
Two old pickling tests failed: see this build. I didn't see a nice way out, so I made an exception for the deprecated SparseTimeSeries. This may not be what you want and needs review. |
@sstanovnik yeah |
@@ -210,3 +210,25 @@ def test_subclass_align_combinations(self): | |||
tm.assert_series_equal(res1, exp2) | |||
tm.assertIsInstance(res2, tm.SubclassedDataFrame) | |||
tm.assert_frame_equal(res2, exp1) | |||
|
|||
def test_subclass_sparse_slice(self): |
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.
we have lots of changes, but want to see if we can have a test for each, can you audit these changes and add tests if needed.
I added additional tests to check other subclassing changes I made. |
lgtm; though I think the read_pickle assertion can be done in a clearer way (use sep function). @sinhrks ? |
@@ -44,8 +44,15 @@ def compare_element(self, result, expected, typ, version=None): | |||
return | |||
|
|||
if typ.startswith('sp_'): | |||
# SparseTimeSeries deprecated in 0.17.0 | |||
if (typ == "sp_series" and version and |
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.
test_pickle
can use object-specific method if it is defined. Defining compare_sp_series_ts
(like other compare_xxx
method) should allow test_pickle
to use the method for sparse time series. Current impl skips type check of all sparse series.
NOTE: method name is derived from pickle key:
@sstanovnik looks good. @sinhrks anything further? |
None. thanks for all the effort, @sstanovnik ! |
@sstanovnik lgtm. pls add a whatsnew note (put in API changes). ping when green. |
Use proper subclassing behaviour so subclasses work properly: this fixes an issue where a multi-element slice of a subclass of SparseDataFrame returned the SparseDataFrame type instead of the subclass type.
This should fix subclassing issues.
ping |
thanks @sstanovnik |
git diff upstream/master | flake8 --diff
This changes
SparseDataFrame
to use proper subclassing functionality so slicing of subclasses ofSparseDataFrame
works. Example of a failure that this PR fixes: