-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
np.median behavior broken for array subclasses in 1.8.0rc1 #3846
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
Comments
Hmm, sounds RC to me. Thomas: do you really mean that you want to be able to define a .mean @jtaylor: did we just forget about ndarray.median when putting in the new
|
@njsmith - in Numpy < 1.8, when calling |
Similarly, it would be great if |
I would say that all the code depending on the previous behavior relied on an implementation detail. If a lot of it breaks though, it can't hurt to keep the call to the We shouldn't add new things like this though, like you propose for |
@rgommers - this currently breaks the |
Why monkey-patch? If you have code that accepts objects with and without a
Since |
@rgommers - things are a little more complicated because the issue is that |
But then your problem is every non-ufunc function your users ever want to use right? So why change just |
So the question is whether @rgommers: the motivation for that is probably to avoid a change of this behavior in median. @astrofrog: also, an unrelated issue: please take a look at the |
@rgommers - indeed, we would need to monkey-patch many of the Numpy non-ufuncs because they do not preserve sub-classes - I was just using @pv thanks for the note about |
@astrofrog, I doubt there is a big reason for that (though there may well be, I do not follow numpy for long). Half the time it was likely forgotten that it makes sense to call The subclassing situation does not seem great, but I guess the bigger subclassing packages will probably have to help if it is to be improved substantially, just like scipy.sparse now gave us |
In the long term, the way forward for 'units' is to improve custom dtype But, in the short term it does seem like we should come up with some Looking at the diff between 1.7.1 and 1.8, median doesn't actually call On Tue, Oct 1, 2013 at 10:49 AM, seberg notifications@github.com wrote:
|
@njsmith - I agree about the dtype, in fact we reached the same idea as a long-term solution. For now, simply fixing |
using asanyarray instead of asarray is seems to work fine. I'll fix that. |
note that median, percentile and sort will (hopefully) get extended axis support and (the first two) the keepdims keyword argument in 1.9. |
I think this is an important warning to include for subclass authors. Otherwise, we will be expanding our exposure of internal APIs as part of ``__array_function__``. All things being equal, it's great when things "just work" subclasses, but I don't want to guarantee it. In particular, I would be very displeased if ``__array_function__`` leads to NumPy adding more subclass specific hacks like always calling ``mean()`` inside ``median()`` (numpyGH-3846). mhvk: please take a look.
Previously, when writing Numpy array subclasses, it was possible to override the behavior of
np.mean
andnp.median
by defining amean
method on the sub-class. For example,produced the following output:
However, in 1.8.0rc1, it looks like none of the methods shown above get called:
This means that it is no longer possible to override the behavior of
median
, which makes things like quantity handing with units break. For instance:or
It would be great if this could be fixed by 1.8.0 final, as this will otherwise break a lot of unit-handing code.
The text was updated successfully, but these errors were encountered: