Skip to content

BUG: Handle nan values on histogram's slow path.#31461

Open
JosephMehdiyev wants to merge 3 commits into
numpy:mainfrom
JosephMehdiyev:hist-nan-2
Open

BUG: Handle nan values on histogram's slow path.#31461
JosephMehdiyev wants to merge 3 commits into
numpy:mainfrom
JosephMehdiyev:hist-nan-2

Conversation

@JosephMehdiyev

@JosephMehdiyev JosephMehdiyev commented May 18, 2026

Copy link
Copy Markdown
Contributor

PR summary

Fixes #28730
Contrary to histogramdd (which is another problem I think), histogram uses a different algorithm that uses _search_sorted_inclusive on its slow path where nan values work ambigiously depending on the dtype. This is a small workaround to fix it basically.

I am still not sure if this fix is proper, I will play around the PR until its ready

AI Disclosure

I have used claude to review the code. The changes are not AI written.

@JosephMehdiyev JosephMehdiyev marked this pull request as ready for review May 19, 2026 16:58
@JosephMehdiyev

Copy link
Copy Markdown
Contributor Author

Maybe an additional warning about the data containing nan values and how the histogram handles it would be nice addition? Otherwise it might be ambigious?

@seberg

seberg commented Jun 3, 2026

Copy link
Copy Markdown
Member

If we go with #31431, I think we'll get this for free so I am not sure we should go the manual route here.

@JosephMehdiyev

Copy link
Copy Markdown
Contributor Author

#31431 surely would be a better fix (didn't know that PR existed), although I tried to test that branch and the issue is still there

@seberg

seberg commented Jun 3, 2026

Copy link
Copy Markdown
Member

Ah, right. That changes sorting but this would (also?) need searchsorted to take incomparable values into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: histogram error with nan objects

3 participants