Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 15, 2024
1 parent 26b4700 commit 459b90e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion unyt/_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def histogram2d(x, y, bins=10, range=None, density=None, weights=None, *args, **


@implements(np.histogramdd)
def histogramdd(sample, bins=10, range=None, density=None, weights=None, *args, **kwargs):
def histogramdd(
sample, bins=10, range=None, density=None, weights=None, *args, **kwargs
):
units = [_.units for _ in sample]
range = _sanitize_range(range, units=units)
counts, bins = np.histogramdd._implementation(
Expand Down
14 changes: 8 additions & 6 deletions unyt/tests/test_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,15 +667,15 @@ def test_histogram_with_weights_density():
# check case with density
rng = np.random.default_rng()
arr = rng.normal(size=1000) * cm
density, bins = np.histogram(arr, bins=10, range=(arr.min(), arr.max()), density=True)
density, bins = np.histogram(
arr, bins=10, range=(arr.min(), arr.max()), density=True
)
assert type(density) is unyt_array
assert density.units == arr.units ** -1
assert density.units == arr.units**-1
assert bins.units == arr.units
# also check case with weights
w = rng.uniform(size=1000) * g
wcounts, wbins = np.histogram(
arr, bins=10, range=(arr.min(), arr.max()), weights=w
)
wcounts, wbins = np.histogram(arr, bins=10, range=(arr.min(), arr.max()), weights=w)
assert type(wcounts) is unyt_array
assert wcounts.units == w.units
assert wbins.units == arr.units
Expand Down Expand Up @@ -761,7 +761,9 @@ def test_histogramdd_with_weights_density():
assert ywbins.units == y.units
assert zwbins.units == z.units
# also check case with weights and density
wdensity, (xwdbins, ywdbins, zwdbins) = np.histogramdd((x, y, z), weights=w, density=True)
wdensity, (xwdbins, ywdbins, zwdbins) = np.histogramdd(
(x, y, z), weights=w, density=True
)
assert wdensity.ndim == 3
assert type(wdensity) is unyt_array
assert wdensity.units == w.units / (x.units * y.units * z.units)
Expand Down

0 comments on commit 459b90e

Please sign in to comment.