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

Let nanarg{min,max}(..., axis=...) optionally return a placeholder value for all-nan slices. #198

Open
anntzer opened this issue Nov 8, 2018 · 1 comment

Comments

@anntzer
Copy link

anntzer commented Nov 8, 2018

Currently, nanarg{min,max}(..., axis=...) raises a ValueError when any full-nan slice exists. On numpy's side it looks like a while ago (#3030) this used to return UINTPTR_MIN (the largest negative value), and that behavior was removed to avoid hiding bugs.

I agree with raising by default, but OTOH this prevents writing code where we know that all-nan slices are possible and we are ready to handle them. Adding an option like raise_on_all_nan: bool (defaulting to True) would allow one to do e.g.

idxs = np.nanargmin(t, axis=1, raise_on_all_nan=False)
all_nans_mask = idxs < 0
# do some handling with all_nans_mask

Similar issue posted on numpy's side as numpy/numpy#12352.

@kwgoodman
Copy link
Collaborator

My goal is to follow numpy. So I'd only consider changing if you got them to change.

To follow current numpy behavior I do:

if (allnan) {
        VALUE_ERR("All-NaN slice encountered");
        return NULL;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants