Skip to content

Commit

Permalink
Merge pull request #6126 from astrofrog/fix-histogram-regression
Browse files Browse the repository at this point in the history
BUG: fixed regression in np.histogram which caused input floating-point values to be modified
  • Loading branch information
jaimefrio committed Jul 28, 2015
2 parents 9232200 + c49821c commit a92c4a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/lib/function_base.py
Expand Up @@ -232,7 +232,7 @@ def histogram(a, bins=10, range=None, normed=False, weights=None,
tmp_a = tmp_a[keep]
if tmp_w is not None:
tmp_w = tmp_w[keep]
tmp_a = np.array(tmp_a, dtype=float, copy=False)
tmp_a = tmp_a.astype(float)
tmp_a -= mn
tmp_a *= norm

Expand Down
7 changes: 7 additions & 0 deletions numpy/lib/tests/test_function_base.py
Expand Up @@ -1221,6 +1221,13 @@ def test_exotic_weights(self):
wa, wb = histogram(values, bins=2, range=[1, 3], weights=weights)
assert_array_almost_equal(wa, [Decimal(1), Decimal(5)])

def test_no_side_effects(self):
# This is a regression test that ensures that values passed to
# ``histogram`` are unchanged.
values = np.array([1.3, 2.5, 2.3])
np.histogram(values, range=[-10, 10], bins=100)
assert_array_almost_equal(values, [1.3, 2.5, 2.3])

def test_empty(self):
a, b = histogram([], bins=([0, 1]))
assert_array_equal(a, np.array([0]))
Expand Down

0 comments on commit a92c4a1

Please sign in to comment.