-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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 NDFrame.swapaxes #26654
Conversation
6d0f791
to
7e6bd88
Compare
7e6bd88
to
676a2e4
Compare
Codecov Report
@@ Coverage Diff @@
## master #26654 +/- ##
===========================================
- Coverage 91.87% 41.81% -50.07%
===========================================
Files 174 174
Lines 50683 50684 +1
===========================================
- Hits 46567 21191 -25376
- Misses 4116 29493 +25377
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26654 +/- ##
===========================================
+ Coverage 41.84% 91.86% +50.01%
===========================================
Files 174 174
Lines 50663 50664 +1
===========================================
+ Hits 21201 46543 +25342
+ Misses 29462 4121 -25341
Continue to review full report at Codecov.
|
67930d1
to
2623f0a
Compare
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -476,6 +476,8 @@ Other Deprecations | |||
the :meth:`SparseArray.to_dense` method instead (:issue:`26421`). | |||
- The functions :func:`pandas.to_datetime` and :func:`pandas.to_timedelta` have deprecated the ``box`` keyword. Instead, use :meth:`to_numpy` or :meth:`Timestamp.to_datetime64` or :meth:`Timedelta.to_timedelta64`. (:issue:`24416`) | |||
- The :meth:`DataFrame.compound` and :meth:`Series.compound` methods are deprecated and will be removed in a future version (:issue:`26405`). | |||
- The :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes` methods are deprecated and will be removed in a future version. | |||
Use :meth:`DataFrame.transpose` and :meth:`Series.transpose` instead(:issue:`26654`). |
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.
space before the issue number
2623f0a
to
9a621aa
Compare
This passes locally, but is somehow failing on numpy_dev. I'll see it I can figure it out. |
with pytest.raises(ValueError, match=msg): | ||
df.swapaxes(2, 5) | ||
|
||
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
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.
Is there a reason you need the check_stacklevel=False
? (it seems a simple first level function, not multiple levels deep)
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.
I got an error related to stack level, because something else is also deprecated. I can't exactly remember which function was deprecated, but I just thought this was the easy solution (the exact stack level isn't that important...)
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.
(the exact stack level isn't that important...)
It is relevant for the user experience. But the stacklevel of 2 should be correct.
But a different deprecation being raised sounds a bit suspicious. Can you check which one it was?
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.
It has something to do with SparseDataFrame
:
def test_swapaxes_deprecated(self):
df = self.klass(np.random.randn(10, 5))
with tm.assert_produces_warning(FutureWarning):
> swapped = df.swapaxes(0, 1)
pandas\tests\frame\test_api.py:370:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <contextlib._GeneratorContextManager object at 0x000002453AD9E940>, type = None, value = None, traceback = None
def __exit__(self, type, value, traceback):
if type is None:
try:
> next(self.gen)
E AssertionError: Warning not set with correct stacklevel. File where warning is raised: C:\Users\TP\Documents\Python\pandasdev\pandasdev\pandas\core\generic.py != C:\Users\TP\Documents\Python\pandasdev\pandasdev\pandas\tests\frame\test_api.py. Warning message: SparseDataFrame is deprecated and will be removed in a future version.
E Use a regular DataFrame whose columns are SparseArrays instead.
E
E See http://pandas.pydata.org/pandas-docs/stable/user_guide/sparse.html#migrating for more.
I'll try to work around it.
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.
assert_produces_warning doesn't handle stack level correctly with multiple warnings. I'd recommend just check_stacklevel=False
like you've done.
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.
or don't test it for SparseDataFrame? That's deprecated anyway.
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.
Could you explain why the stack level important? Seems not so relevant to me.
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.
It's not that important here, as I can see you set it correctly.
But, in general, we want to test it because it ensures that end-users get a warning with the correction "location" indicated. If the stacklevel is set correctly, the warning message points to where this deprecated feature is being used. If not, it points to some other place, which is not useful or even plain confusing.
From the tracebacks on Azure, it might be from Not sure there is anything we can do about that .. (apart from actually implementing |
Thanks, that's something to investigate. Could be there's a |
I suppose it is actually numpy calling it. Basically, |
9a621aa
to
518ef5d
Compare
@@ -431,7 +431,7 @@ def test_size_compat(self): | |||
|
|||
def test_split_compat(self): | |||
# xref GH8846 | |||
o = self._construct(shape=10) | |||
o = self._construct(shape=10).values | |||
assert len(np.array_split(o, 5)) == 5 |
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.
nparray_split depends on np.swapaxes, so I sidestep the problem here. This test is not very useful. Is that __array_function__
in the pipeline to implement?
I'm thinking that maybe we should maybe keep swapaxes, perhaps hidden in _deprecations
like we do with tolist
?
@@ -431,7 +431,7 @@ def test_size_compat(self): | |||
|
|||
def test_split_compat(self): | |||
# xref GH8846 | |||
o = self._construct(shape=10) | |||
o = self._construct(shape=10).values |
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 defeats the purpose of the test, I think, as it was actually testing that np.array_split
works on a DataFrame/Series.
So the "quick fix" is rather to ignore warnings in this specific test, so it doesn't fail the test, I think.
Ideally we would prevent that the numpy function raises a warning at all, but not sure that is easily possible.
I'm taking this private for a while. I think |
git diff upstream/master -u -- "*.py" | flake8 --diff
.swapaxes
are not needed, now thatPanel
is being removed.