Skip to content

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

Merged
merged 1 commit into from
May 6, 2017

Conversation

eric-wieser
Copy link
Member

Only deprecated when this would be ambiguous.

Approaches #8701



class TestArgsort(TestCase):
""" gh-8701 """
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member Author

@eric-wieser eric-wieser Apr 11, 2017

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?

Copy link
Member Author

@eric-wieser eric-wieser Apr 11, 2017

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?

Copy link
Member

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)
Copy link
Member

@charris charris Apr 11, 2017

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.

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also below.

Copy link
Member

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
Copy link
Member

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 "
Copy link
Member

@charris charris Apr 11, 2017

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.

Copy link
Member Author

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?

Copy link
Member

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".

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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?

Copy link
Member

@charris charris Apr 13, 2017

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.

Copy link
Member

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.

Copy link
Member Author

@eric-wieser eric-wieser Apr 13, 2017

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?

Copy link
Member Author

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

@charris
Copy link
Member

charris commented Apr 12, 2017

Need to finish this up.

@eric-wieser eric-wieser force-pushed the deprecate-ma-argsort-no-axis branch 2 times, most recently from b2b3a0b to 056816c Compare April 13, 2017 01:55
"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)
Copy link
Member Author

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)
Copy link
Member Author

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

@eric-wieser eric-wieser force-pushed the deprecate-ma-argsort-no-axis branch from 056816c to 844d4f7 Compare April 13, 2017 10:15
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.
Copy link
Member Author

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

@eric-wieser
Copy link
Member Author

eric-wieser commented Apr 13, 2017

Fun fact: np.ma.maximum and np.ma.minimum also have the wrong default value for the axis argument. but they have no documentation at all. Deprecate those too, or outright fix them?

@homu
Copy link
Contributor

homu commented Apr 28, 2017

☔ 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
@eric-wieser eric-wieser force-pushed the deprecate-ma-argsort-no-axis branch from 844d4f7 to 0a8ee4c Compare May 5, 2017 21:27
@eric-wieser
Copy link
Member Author

Need to finish this up.

Rebased to fix the merge conflict

@charris charris merged commit 6153a70 into numpy:master May 6, 2017
@charris
Copy link
Member

charris commented May 6, 2017

Thanks Eric.

eric-wieser added a commit to eric-wieser/numpy that referenced this pull request May 6, 2017
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`
eric-wieser added a commit to eric-wieser/numpy that referenced this pull request May 6, 2017
Introduced by me in numpy#8918
mherkazandjian pushed a commit to mherkazandjian/numpy that referenced this pull request May 30, 2017
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`
mherkazandjian pushed a commit to mherkazandjian/numpy that referenced this pull request May 30, 2017
Introduced by me in numpy#8918
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants