8000 ENH: remove "Invalid value" warnings from median, percentile by mattip · Pull Request #12679 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: remove "Invalid value" warnings from median, percentile #12679

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
Jan 9, 2019

Conversation

mattip
Copy link
Member
@mattip mattip commented Jan 6, 2019

Fixes #12676 by removing the Invalid value warning from median, percentile and quantile

Copy link
Contributor
@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

👍 to the change, and looks all OK.

@eric-wieser
Copy link
Member
eric-wieser commented Jan 6, 2019

Are there any places where we do want this warning? It would be good to know what the motivation for it was in the first place - in all cases, it seems redundant vs just checking for Nan in the output.

@shoyer
Copy link
Member
shoyer commented Jan 6, 2019

This PR is the original source: #5753

It added these warnings at the same time as it added a guarantee that NaN is returned if any NaNs are encountered.

The release notes do say: "Similar to mean, median and percentile now emits a Runtime warning and
returns NaN in slices where a NaN is present."

But I'm not sure it was ever true that mean would emit a runtime warning when NaNs are encountered. Possibly we used to be more aggressive about warning when an operation that already includes NaNs also returns in an NaN value? np.mean() on inputs with NaN (really np.add.reduce) definitely does not trigger an invalid floating point state today.

@seberg
Copy link
Member
seberg commented Jan 6, 2019

Are there any tests for things such as np.mean([]) where a division by 0 occurs (correctly producing a NaN)?


def test_empty(self):
# empty arrays
# mean(empty array) emits two warnings: empty slice and divide by 0
Copy link
Member Author

Choose a reason for hiding this comment

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

@seberg this test uses an empty array

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, nvm. had thought about it a bit earlier and forgot again ;). All fine for sure length 0 would still have a division by zero. And things such as +inf - inf already warn during the sum step I would assume at least.

@charris
Copy link
Member
charris commented Jan 6, 2019

@shoyer That implies that at least @madphysicist is/was relying on the current behavior. Hmm...

@seberg
Copy link
Member
seberg commented Jan 9, 2019

Rereading that message, I think it was an oversight from us at the time that we decided to go with the warning (maybe to be on the safe side being unsure).

I believe what the message is really about is to return NaN at all. So I do not think anyone relies on it and we can merge this.

Thanks Matti!

@seberg seberg merged commit ad0e902 into numpy:master Jan 9, 2019
@seberg
Copy link
Member
seberg commented Jan 9, 2019

Just to note. I checked the scipy.stats.iqr which was probably the thing that might have relied on this. It does not rely on this, it might be that it could be made a bit simpler now that it can rely on the result being np.nan here.

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.

6 participants
0