Repository navigation
Conversation
|
Nice. There is still the case of which would preserve long double precision (could use 0 for Wondering about the 0-d special case. You could probably just remove it. It should just keep working, except creating warnings due to empty |
|
Oh, I completely forgot about I didn't know about |
There was a problem hiding this comment.
Could you have a look at this too? I think we should probably just remove the special case. There will be some warnings raised (actually more then just one, but that is also the case in std, etc.) in some cases, but I don't see a problem with it, the current result is plain nonsense in those cases.
If you fix this, there is also the case of ddof being too large. So maybe you could add a warning such as std/var are now giving: RuntimeWarning: Degrees of freedom <= 0 for slice if fact is <= 0 (and replace fact by 0 in that case).
There was a problem hiding this comment.
Oh, I think charris made sure that the warnings for std, about the degrees of freedoms are raised before other warnings about the same thing, so it would be good to move the fact calculation/check before the mean calculation probably.
There was a problem hiding this comment.
If I understand correcty, you want me to remove the check for empty arrays and get a RuntimeWarning on the mean computation ?
I can check for ddof but if I set fact = 0 there will be a division by 0 at the end of the function. The correct value should be 1.
There was a problem hiding this comment.
really? I would have thought the most correct value is nan (unless we throw an error) because of that division, just like std gives nan in those cases. If the value was 1, then they would all be 1 and not add up to 1?! I simply care for the warning mean gives, if you prefer to put the mean calculation in a conditional to avoid it, that is fine with me too.
There was a problem hiding this comment.
Uh, well, I guess they ar enot supposed to add up, but still, does such a 1 result really make sense, also considering if ddof >= 1 and there actually are values, but just not enough.
There was a problem hiding this comment.
You're right, 1 makes no sense. The division by 0 yields nan only if the value in the array are 0, otherwise it is +/-inf. Is it acceptable ?
There was a problem hiding this comment.
I tried to remove the special case of X.size == 0, but then test_empty fails (after tweaking to take the warning into account) as the returned value is nan thus not empty: dot([], []) is False and is then divided by 0.0. Returning an empty array the size of the input array seems a better option.
There was a problem hiding this comment.
I think that is acceptable, i.e. std does the same, and we would add the warning as well.
To be honest, I would guess that the empty special case was just part of many such added when the general support for this was much worse, and the test should just be changed. As far as I can see, the current result is almost always incorrect. Since the old result is plain wrong, I would consider it a bug fix and probably no big warnings are needed. But we could of course add a FutureWarning for now...
Add a warning and set value to 0
There was a problem hiding this comment.
I think you said that inf is possible? Could use np.isfinite, or simply c / c.
There was a problem hiding this comment.
Right, nan was only for empty arrays but it is indeed possible to have a scalar with ddof too high.
There was a problem hiding this comment.
Can stay as is as far as I am concerned, just in case you like it: np.zeros((0, 0)), is a bit shorter ;).
There was a problem hiding this comment.
I prefer to keep np.array([]) as it shows more clearly that the array is empty, compared to np.zeros((0, 0)).
|
Anyway, great, thanks! Will just wait a bit with merging in case someone thinks changing the 0-d case should be done more gentle, or has some other comment. |
|
Should I merge these commits into a big one ? |
|
Squashing away the back and forth edits and tiny fixups would make sense. Whatever you feel sensible :). |
|
note pull #3864 probably conflicts with this one, it would also be great if you can help out reviewing it. |
|
Sorry to bother, but where you planning on squashing it? Otherwise I will just put it in or maybe squash myself. Thanks a lot for all the patience fixing the the 0-size thing too :)! |
|
Oh, sorry, I forgot about that. I think it's better if you squash it yourself or put it as it is (I'm still learning about I use numpy everyday at work and sometimes at home, I'm glad to have contributed to such a great library ! |
|
Actually it is a bit simpler for you, since we cannot edit PRs directly. Rebasing is quite simple. If you just want to squash it together into a single commit, you can do:
|
|
@seberg you can squash, rebase and push (with |
|
yes, will do. I should learn that too... |
|
Thanks again, pushed in 84c52d8 |
Closes issues #597 and #2680, which are duplicates.
It follows #2716 which was abandoned.
The example for the test was taken from #597.