-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DEPR: Deprecate Series/Dataframe.to_dense/to_sparse #26684
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26684 +/- ##
==========================================
+ Coverage 91.87% 91.9% +0.02%
==========================================
Files 174 174
Lines 50661 50916 +255
==========================================
+ Hits 46547 46796 +249
- Misses 4114 4120 +6
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26684 +/- ##
==========================================
- Coverage 91.87% 91.86% -0.01%
==========================================
Files 180 180
Lines 50712 50719 +7
==========================================
+ Hits 46590 46593 +3
- Misses 4122 4126 +4
Continue to review full report at Codecov.
|
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.
Thanks for the PR!
Some additional comments:
- There is an additional
to_dense
method in generic.py that should also be deprecated. - You will need to add some tests that those warnings are raised (as an example see the test added here: https://github.com/pandas-dev/pandas/pull/26421/files#diff-f446e63e2ec57a5d055add5511588c3fR1234)
@jorisvandenbossche Thanks for the review. I committed the stylistic changes that you suggested. Working on writing the tests. Could you please guide me on where the tests for Series and Dataframe (not sparse) need to be written? Should I create a new file or write it in an existing file. |
pandas/core/frame.py
Outdated
@@ -1939,6 +1940,9 @@ def to_sparse(self, fill_value=None, kind='block'): | |||
>>> type(sdf) # doctest: +SKIP | |||
<class 'pandas.core.sparse.frame.SparseDataFrame'> | |||
""" | |||
warnings.warn("DataFrame.to_sparse is deprecated and will be removed " | |||
"in a future version", FutureWarning, stacklevel=2) | |||
|
|||
from pandas.core.sparse.api import SparseDataFrame | |||
return SparseDataFrame(self._series, index=self.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.
wont' this also trigger the SDF warnings? (should this just be changed to create a DF here?
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.
Do you mean the SDF deprecation warning? If thats the case, yes, but this was requested in the issue that this PR will address ( #26557 ).
Also, this might be helpful if someone has already hit the SDF warning through a different route, as a gentle reminder. Either way we could decide whats best and update accordingly.
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.
Yes, it already triggers the SparseDataFrame warning. But, it is still good to explicitly deprecate this method as well (in the docs, and by giving a clearer warning message, although the other one will also still be present).
I don't think we should change the behaviour, since we are deprecating it (it would also be a backwards incompatible change, as DataFrame with sparse and SparseDataFrame are not fully interchangeable).
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.
So I think we can agree to keep both the warnings and resolve this conversation?
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.
actually i would suppress the SDF
warning here as the user facing to_sparse is already good enough
Hello @intell1gent! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-06-18 04:51:35 UTC |
Also, I'll change the code style issues in the next push. |
@intell1gent I would need to look myself to say for sure (but now away for the weekend), but if other tests raise those warnings, then it might be because the methods are still used in certain places in pandas. In such a case, you will need to check those places and see if it can be replaced with something else (or if it was just used in the tests directly, then you can add a filterwarnings decorator). |
Turns out changing |
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.
again, I don't want blanket warning filters at all. These are hiding errors.
For the old sparse tests (so not speaking about the groupby tests, there we indeed should certainly not hide the warnings), we decided earlier to not rewrite those tests but just ignore the warnings (until all functionality + tests can be removed). So you will see there are already existing filterwarnings for Sparse. For those cases (again, tests about the old, deprecated SparseDataFrame/Series, I think it is best to also ignore those new warnings). |
@intell1gent I think it is fine to have the double deprecation. How would you propose to only have a single warning? I personally think we certainly need a warning that mentions |
Update DataFrame/Series.to_dense deprecation message Co-Authored-By: Joris Van den Bossche <[email protected]>
right this case is ok, but we need to be really clear on this, e.g. on |
@intell1gent for future reference: you are correct that it was not added by you, but in general, the diff that github shows on the PR needs to be correct. So if you noticed unrelated changes in the diff here from master, that means that something went wrong when you updated this branch to the latest master. And it is still up to you to fix that. See my earlier comment on how that could be done. |
@jreback yes, that sounds correct, that we should in principle only do this general filterwarnings in the |
right, let's comment these warning to be clear where they come from if they are not in pandas/tests/sparse (and actually maybe there too) |
Yes, I changed |
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.
Looking good!
with tm.assert_produces_warning(FutureWarning, | ||
check_stacklevel=False): | ||
result = df.to_sparse() | ||
tm.assert_frame_equal(result, sparse_df) |
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.
you put this in a class where those warnings you want to check for are generally ignored. Does that work? (just wondering)
Maybe we can also put it at the end of the file as a function instead of method, to avoid possible concerns about that.
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.
But since the tests are passing, this is probably fine ;)
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.
This actually works fine, tm.assert_produces_warning
doesn't seem to care about filterwarnings. Remove the warning from to_sparse
and this test fails.
I wanted to keep both (test_dense_to_sparse
and test_deprecated_dense_to_sparse
) close for easy reference, thats all. Open to shifting it to the end though.
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.
Thanks for checking, then that sounds good!
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.
Thanks, looks good!
@jreback you're fine with the current filterwarnings? They are only added there were we already had a filterwarning for other sparse warnings as well
i will review at some point again |
thanks @intell1gent ! |
git diff upstream/master -u -- "*.py" | flake8 --diff
Marks the methods mentioned in #26557 as deprecated, with proper messages.