Skip to content

Commit

Permalink
BUG: fix backward compatibility for calling np.histogram with implici…
Browse files Browse the repository at this point in the history
…t range units
  • Loading branch information
neutrinoceros committed Nov 2, 2023
1 parent 13413d4 commit 7bb2324
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions unyt/_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,16 @@ def _sanitize_range(_range, units):
ilim = _range[2 * i : 2 * (i + 1)]
imin, imax = ilim
if not (hasattr(imin, "units") and hasattr(imax, "units")):
raise TypeError(
f"Elements of range must both have a 'units' attribute. Got {_range}"
)
if len(units) == 1:
# allow range to be pure numerical scalars
# for backward compatibility with unyt 2.9.5
# see https://github.com/yt-project/unyt/issues/465
imin *= units[0]
imax *= units[0]
else:
raise TypeError(
f"Elements of range must both have a 'units' attribute. Got {_range}"
)
new_range[i] = imin.to_value(units[i]), imax.to_value(units[i])
return new_range.squeeze()

Expand Down

0 comments on commit 7bb2324

Please sign in to comment.