-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
DEP: deprecate calling ma.argsort without an axis #8918
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
9da0a5b
to
1075c1d
Compare
|
||
|
||
class TestArgsort(TestCase): | ||
""" gh-8701 """ |
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.
Should include date and numpy version, that helps keep track of expiration dates, etc.
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.
Thought that having it repeated in the tests would just be noise - date and version are already in the source
numpy/ma/core.py
Outdated
# no warning needed - switch to -1 to avoid surprising subclasses | ||
return -1 | ||
else: | ||
# 2017-04-10, numpy 1.13.0 |
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.
Date and version are here - should they be repeated at the call site as well?
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.
And a related idea - maybe we should have a custom np.DeprecationWarning
with version
and date
fields?
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 usually grep for the date and version to find what needs to be changed after branching a version, so whatever should be easily grepable and location specific. I think it is not too much work to just add a comment.
numpy/ma/core.py
Outdated
@@ -5284,6 +5311,8 @@ def argsort(self, axis=None, kind='quicksort', order=None, | |||
|
|||
""" | |||
|
|||
axis = _deprecate_argsort_axis(self, axis) |
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.
Add note with date and numpy version, something like
# 04-11-2017, Numpy 1.13.0, warn on axis default.
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.
Should I remove that comment from inside _deprecate_argsort_axis
itself then?
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.
Also below.
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.
Doesn't matter, but really the information needs to be at the point of call.
numpy/ma/core.py
Outdated
@@ -93,6 +93,33 @@ | |||
class MaskedArrayFutureWarning(FutureWarning): | |||
pass | |||
|
|||
def _deprecate_argsort_axis(arr, axis): | |||
""" | |||
Takes the array argsort was called upon, and the axis argument |
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.
Should follow usual docstring standard. This is really something for the Parameters
section.
numpy/ma/core.py
Outdated
else: | ||
# 2017-04-10, numpy 1.13.0 | ||
warnings.warn( | ||
"Unlike np.argsort, np.sort, np.ma.sort, and the " |
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 shorten this message, I'd just say the in the future the default axis will be -1 to match the documentation, not the current None and omit the unlike bit.
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.
Not worth keeping the "pass the axis explicitly to squash" bit?
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 keep that. There is temptation is to explain "why", which is good for a commit message, but documentation should mosty be "what".
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.
Should also mention the change in the function axis documentation with a note about the deprecation.
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.
How do you recommend I word 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.
Should we keep the part that says "the default is -1", despite it being wrong?
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.
Maybe
The default value is None. Prior to NumPy 1.13.0 the
default was documented to be -1, but that was in error.
However, we intend to make the default -1 for real at
some future date, and so issue a FutureWarning unless
the axis is explicitly given for arrays of dimension > 1.
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.
Note that I think a simple FutureWarning
would suffice rather than the temporary two off MaskedArrayFutureWarning
.
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.
Are we reserving MaskedArrayFutureWarning
for the incoming "mask
is the same type of view/non-view as data
" change then?
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 benefit of having a MaskedArrayFutureWarning
is that it makes it obvious that the warning only applies to masked arrays, and the message doesn't need to explain that only ma.argsort
has a bad default argument
Need to finish this up. |
b2b3a0b
to
056816c
Compare
"In the future the default for argsort will be axis=-1, not the " | ||
"current None, to match its documentation and np.argsort. " | ||
"Explicitly pass -1 or None to silence this warning.", | ||
MaskedArrayFutureWarning, stacklevel=3) |
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 level needed to be 3
, not 2
, as it is not directly in the deprecated function
@@ -5284,6 +5311,10 @@ def argsort(self, axis=None, kind='quicksort', order=None, | |||
|
|||
""" | |||
|
|||
# 2017-04-11, Numpy 1.13.0, gh-8701: warn on axis default | |||
if axis is np._NoValue: | |||
axis = _deprecate_argsort_axis(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.
Doing the test here makes it more obvious that this only affects default arguments
056816c
to
844d4f7
Compare
in error. At some future date, the default will change to -1, as | ||
originally intended. | ||
Until then, the axis should be given explicitly when | ||
``arr.ndim > 1``, to avoid a FutureWarning. |
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.
Added the comment to the axis argument
Fun fact: |
☔ The latest upstream changes (presumably #8996) made this pull request unmergeable. Please resolve the merge conflicts. |
Only deprecated when this would be ambiguous. Approaches numpy#8701
844d4f7
to
0a8ee4c
Compare
Rebased to fix the merge conflict |
Thanks Eric. |
This does not match np.maximum, which is confusing because the masked version has no documentation at all. This uses a similar deprecation approach to numpygh-8918, noting that the warning is only needed for arrays of more than one dimension. The same remarks apply to `np.ma.minimum`
Introduced by me in numpy#8918
This does not match np.maximum, which is confusing because the masked version has no documentation at all. This uses a similar deprecation approach to numpygh-8918, noting that the warning is only needed for arrays of more than one dimension. The same remarks apply to `np.ma.minimum`
Introduced by me in numpy#8918
Only deprecated when this would be ambiguous.
Approaches #8701