Skip to content

Commit

Permalink
BUG: fix an issue where np.histogramdd could create infinite recursio…
Browse files Browse the repository at this point in the history
…n on some inputs
  • Loading branch information
neutrinoceros committed Dec 18, 2024
1 parent 196685d commit d41543b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions unyt/_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,16 @@ def _histogramdd(
# don't getattr(..., "units", NULL_UNIT) because e.g. we don't want
# a unyt_array if weights are not a unyt_array and not density
if density:
divider_units = 1 * NULL_UNIT
for s in sample:
counts /= getattr(s, "units", 1)
counts *= getattr(weights, "units", 1)
if not hasattr(s, "units"):
continue
divider_units *= s.units
if divider_units != NULL_UNIT:
counts /= divider_units

if weights is not None and hasattr(weights, "units"):
counts *= weights.units
return counts, tuple(_bin * getattr(s, "units", 1) for _bin, s in zip(bins, sample))


Expand Down

0 comments on commit d41543b

Please sign in to comment.