Skip to content
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

MAINT: FutureWarning for changes to np.average subclass handling #7433

Merged
merged 1 commit into from
Jun 14, 2016

Conversation

ahaldane
Copy link
Member

This slightly rolls back the changes to np.average in #7382, so that we emit a FutureWarning if np.average is called on an ndarray subclass. In the future, np.average will preserve subclasses, just like np.mean and almost all other numpy methods.

This is to fix #7403. Note that the specific case in #7403 will probably also be fixed by #7406, but this PR should make sure we aren't more generally breaking anyone's code (for now).

@@ -989,7 +989,17 @@ def average(a, axis=None, weights=None, returned=False):
TypeError: Axis must be specified when shapes of a and weights differ.

"""
a = np.asanyarray(a)
# replace the next few lines with "a = np.asanyarray(a)" in the future
Copy link
Member

Choose a reason for hiding this comment

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

If doing this, should add comment with data and release to help track when to change. Something like

# 3/19/2016 1.12.0

@charris
Copy link
Member

charris commented Mar 19, 2016

Also add something to the release notes. The 1.11.0 notes have a FutureWarnings section and having that for the 1.12.0 notes would make sense. Also a summary entry in future changes.

"will do so in the future to match the behaior of most "
"other numpy functions such as np.mean. In particular, "
"this means calls which returned a scalar may return a "
"0-d subclass object instead.", FutureWarning)
Copy link
Member

Choose a reason for hiding this comment

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

Since I hope to change this everywhere else as well by 1.12 (and probably force it in the numpy code base for the most part), could you add a stacklevel=2?

@ahaldane
Copy link
Member Author

Updated

@homu
Copy link
Contributor

homu commented Mar 20, 2016

☔ The latest upstream changes (presumably #7437) made this pull request unmergeable. Please resolve the merge conflicts.

@lesteve
Copy link
Contributor

lesteve commented Apr 4, 2016

I am not sure what is the status of this now that #7406 has been merged.

It if is still needed it needs a rebase on master and there is a behaior -> behavior typo to fix (missing v). EDIT: in two places.

@charris charris added this to the 1.12.0 release milestone Apr 16, 2016
@charris
Copy link
Member

charris commented Jun 13, 2016

@ahaldane What is the status of this? Note also the previous comment. Looks straight forward to me.

@ahaldane
Copy link
Member Author

Yeah, looks like we should do this. I'll fix it up tonight probably.

@charris charris merged commit ce08966 into numpy:master Jun 14, 2016
@charris
Copy link
Member

charris commented Jun 14, 2016

Thanks Allan.

@mhvk
Copy link
Contributor

mhvk commented Oct 21, 2016

Just a reminder that for 1.12.0 the behaviour was supposed to be changed to allow subclasses in np.average (I think). it would help for Quantity (see astropy/astropy#5421)

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.

np.average of memmap returns memmap 0d array instead of numpy scalar
6 participants