ENH: use _get_bin_edges() on histogramdd for consistency.#31276
ENH: use _get_bin_edges() on histogramdd for consistency.#31276JosephMehdiyev wants to merge 10 commits intonumpy:mainfrom
_get_bin_edges() on histogramdd for consistency.#31276Conversation
This will also add additional string arguments for `bin` for `histogramdd`. Similarly, `histogram2d` will change.
Also, this fixes some obvious bugs that was introduced from the last modification of `histogramdd`.
|
@jorenham (afaik you are the author of these stubs) is there a specific reason why overload stubs of for example deleting this @overload
def histogram2d(
x: _ArrayLike1DNumber_co,
y: _ArrayLike1DNumber_co,
bins: _BinKind | Sequence[Sequence[int] | _BinKind],
range: _ArrayLike2DFloat_co | None = None,
density: bool | None = None,
weights: _ArrayLike1DFloat_co | None = None,
) -> _Histogram2D[np.int_]: ...since this below already handles that case def histogram2d[ScalarT: _Number_co](
x: _ArrayLike1DNumber_co,
y: _ArrayLike1DNumber_co,
bins: _BinKind | _ArrayLike1D[ScalarT] | Sequence[_ArrayLike1D[ScalarT] | _BinKind],
range: _ArrayLike2DFloat_co | None = None,
density: bool | None = None,
weights: _ArrayLike1DFloat_co | None = None,
) -> _Histogram2D[ScalarT]: ...I have no experience with .pyi files, I am mirroring my knowledge from .hpp and cpp templates FYI |
The difference here is in the So these overloads are distinct and non-overlapping. ... or at least, that's what they should be. You added |
|
Not sure the failing tests are PR related. |
There was a problem hiding this comment.
in second thought this specific warning seems unnecessary, i'll change it

PR summary
Basically make bin edge calculation of
histogramddsimilar tohistogram. This will also add possibility of str values on binsFixes #20215
Continuation of #20358
I did recycle some stuff like documentation and main fix approach from the unclosed old PR, I am not sure how I could have continued from the old PR with rebase and stuff so I opened a new PR from scratch. Plagiarism is not my intention here, if there is some way to fix this let me know.
Other comments
ValueError.I believe for example0.95not being a integer should raise aTypeErrorin bins, not aValueError(similar torange(0.95)error)Also the error comes from
_get_bin_edges()as aTypeError. I can change it of course, but I thinkTypeErroris more logical here.I found a discussion about this
https://mail.python.org/archives/list/numpy-discussion@python.org/thread/NIHE7UT4SDPU6KCDSMUIU2UA52PDSEIJ/
Its been so long, and fix is so simple. Just wanted to point it out here
histogramtests onhistogramddand it works as intended (except for the float things that I have said above). Will write them laterhistogramddfunction only and use it for internals ofhistogramsimilar tohistogram2d? Don't know what is the reason here, changing this would fix issues like 2) above if existsAI Disclosure
I used Claude as sanity check on my fixes. All modifications etc are done solely by my decisions and manually typed or copy pasted documentation from the related PR above.