Skip to content

Commit

Permalink
Fixed bug in treatment of noisy_percentile=-1 edge case. Resolves #939.…
Browse files Browse the repository at this point in the history
… Agreed, @mclaughlin6464?
  • Loading branch information
aphearin committed Jan 7, 2020
1 parent ce9bf4e commit 33946dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion halotools/empirical_models/abunmatch/noisy_percentile.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ def noisy_percentile(percentile, correlation_coeff, seed=None, random_percentile
Correlation strengths between zero and unity span the intermediary cases.
"""
if np.all(np.abs(correlation_coeff) == 1):
if np.all(correlation_coeff == 1):
return percentile
elif np.all(correlation_coeff == -1):
return percentile[::-1]

percentile = np.atleast_1d(percentile)
correlation_coeff = np.atleast_1d(correlation_coeff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ def test_noisy_percentile3():
u2 = noisy_percentile(u, r_desired, random_percentile=uran)
r_achieved = spearmanr(u, u2)[0]
assert np.allclose(r_desired, r_achieved, atol=0.02)


def test_negative_unity_noisy_percentile():
"""Regression test for #939.
"""
r_desired = -1
u2 = noisy_percentile(u, r_desired, seed=fixed_seed)
assert np.allclose(u2, u[::-1])

0 comments on commit 33946dd

Please sign in to comment.