Skip to content

Commit 926d167

Browse files
committed
TST: add regression tests for astropygh-8011
1 parent 4834673 commit 926d167

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
@@ -3,7 +3,7 @@
33

44
import numpy as np
55
import pytest
6-
from numpy.testing import assert_allclose
6+
from numpy.testing import assert_allclose, assert_array_equal
77

88
from astropy.stats import (
99
calculate_bin_edges,
@@ -144,35 +144,42 @@ def test_histogram_output_knuth():
144144
def test_histogram_output():
145145
rng = np.random.default_rng(0)
146146
X = rng.standard_normal(100)
147+
X_range = X_min, X_max = X.min(), X.max()
147148

148149
counts, bins = histogram(X, bins=10)
149150
assert_allclose(counts, [2, 0, 12, 14, 14, 17, 16, 8, 9, 8])
150151

151152
# fmt: off
152-
assert_allclose(bins, [-2.32503077, -1.89228844, -1.4595461, -1.02680377, -0.59406143,
153+
assert_allclose(bins, [X_min, -1.89228844, -1.4595461, -1.02680377, -0.59406143,
153154
-0.1613191, 0.27142324, 0.70416558, 1.13690791, 1.56965025,
154-
2.00239258])
155+
X_max])
155156
# fmt: on
156157

157158
counts, bins = histogram(X, bins="scott")
158159
assert_allclose(counts, [2, 14, 27, 25, 16, 16])
159160

160161
# fmt: off
161-
assert_allclose(bins, [-2.32503077, -1.59953424, -0.87403771, -0.14854117, 0.57695536,
162-
1.3024519, 2.02794843])
162+
assert_allclose(bins, [X_min, -1.59953424, -0.87403771, -0.14854117, 0.57695536,
163+
1.3024519, X_max])
163164
# fmt: on
164165

165166
counts, bins = histogram(X, bins="freedman")
166167
assert_allclose(counts, [2, 11, 16, 18, 22, 14, 13, 4])
167168

168169
# fmt: off
169-
assert_allclose(bins, [-2.32503077, -1.74087192, -1.15671306, -0.5725542, 0.01160465,
170-
0.59576351, 1.17992237, 1.76408122, 2.34824008], rtol=2e-7)
170+
assert_allclose(bins, [X_min, -1.74087192, -1.15671306, -0.5725542, 0.01160465,
171+
0.59576351, 1.17992237, 1.76408122, X_max], rtol=2e-7)
171172
# fmt: on
172173

173174
counts, bins = histogram(X, bins="blocks")
174175
assert_allclose(counts, [3, 97])
175-
assert_allclose(bins, [-2.32503077, -1.37136996, 2.00239258])
176+
assert_allclose(bins, [X_min, -1.37136996, X_max])
177+
178+
179+
def test_histogram_empty_data():
180+
counts, bins = histogram([], bins=2)
181+
assert_allclose(counts, [0, 0])
182+
assert_array_equal(bins, [0, 0.5, 1.0])
176183

177184

178185
def test_histogram_badargs():

0 commit comments

Comments
 (0)