Skip to content

Commit 3de434d

Browse files
committed
TST: add regression tests for astropygh-8011
1 parent 2d5e8fe commit 3de434d

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎astropy/stats/tests/test_histogram.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44
import pytest
5-
from numpy.testing import assert_allclose
5+
from numpy.testing import assert_allclose, assert_array_equal
66

77
from astropy.stats import (
88
calculate_bin_edges,
@@ -138,35 +138,42 @@ def test_histogram_output_knuth():
138138
def test_histogram_output():
139139
rng = np.random.default_rng(0)
140140
X = rng.standard_normal(100)
141+
X_range = X_min, X_max = X.min(), X.max()
141142

142143
counts, bins = histogram(X, bins=10)
143144
assert_allclose(counts, [2, 0, 12, 14, 14, 17, 16, 8, 9, 8])
144145

145146
# fmt: off
146-
assert_allclose(bins, [-2.32503077, -1.89228844, -1.4595461, -1.02680377, -0.59406143,
147+
assert_allclose(bins, [X_min, -1.89228844, -1.4595461, -1.02680377, -0.59406143,
147148
-0.1613191, 0.27142324, 0.70416558, 1.13690791, 1.56965025,
148-
2.00239258])
149+
X_max])
149150
# fmt: on
150151

151152
counts, bins = histogram(X, bins="scott")
152153
assert_allclose(counts, [2, 14, 27, 25, 16, 16])
153154

154155
# fmt: off
155-
assert_allclose(bins, [-2.32503077, -1.59953424, -0.87403771, -0.14854117, 0.57695536,
156-
1.3024519, 2.02794843])
156+
assert_allclose(bins, [X_min, -1.59953424, -0.87403771, -0.14854117, 0.57695536,
157+
1.3024519, X_max])
157158
# fmt: on
158159

159160
counts, bins = histogram(X, bins="freedman")
160161
assert_allclose(counts, [2, 11, 16, 18, 22, 14, 13, 4])
161162

162163
# fmt: off
163-
assert_allclose(bins, [-2.32503077, -1.74087192, -1.15671306, -0.5725542, 0.01160465,
164-
0.59576351, 1.17992237, 1.76408122, 2.34824008], rtol=2e-7)
164+
assert_allclose(bins, [X_min, -1.74087192, -1.15671306, -0.5725542, 0.01160465,
165+
0.59576351, 1.17992237, 1.76408122, X_max], rtol=2e-7)
165166
# fmt: on
166167

167168
counts, bins = histogram(X, bins="blocks")
168169
assert_allclose(counts, [3, 97])
169-
assert_allclose(bins, [-2.32503077, -1.37136996, 2.00239258])
170+
assert_allclose(bins, [X_min, -1.37136996, X_max])
171+
172+
173+
def test_histogram_empty_data():
174+
counts, bins = histogram([], bins=2)
175+
assert_allclose(counts, [0, 0])
176+
assert_array_equal(bins, [0, 0.5, 1.0])
170177

171178

172179
def test_histogram_badargs(N=1000, rseed=0):

0 commit comments

Comments
 (0)