Skip to content

Commit 33946dd

Browse files
committed
Fixed bug in treatment of noisy_percentile=-1 edge case. Resolves #939. Agreed, @mclaughlin6464?
1 parent ce9bf4e commit 33946dd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

halotools/empirical_models/abunmatch/noisy_percentile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ def noisy_percentile(percentile, correlation_coeff, seed=None, random_percentile
147147
Correlation strengths between zero and unity span the intermediary cases.
148148
149149
"""
150-
if np.all(np.abs(correlation_coeff) == 1):
150+
if np.all(correlation_coeff == 1):
151151
return percentile
152+
elif np.all(correlation_coeff == -1):
153+
return percentile[::-1]
152154

153155
percentile = np.atleast_1d(percentile)
154156
correlation_coeff = np.atleast_1d(correlation_coeff)

halotools/empirical_models/abunmatch/tests/test_noisy_percentile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ def test_noisy_percentile3():
3939
u2 = noisy_percentile(u, r_desired, random_percentile=uran)
4040
r_achieved = spearmanr(u, u2)[0]
4141
assert np.allclose(r_desired, r_achieved, atol=0.02)
42+
43+
44+
def test_negative_unity_noisy_percentile():
45+
"""Regression test for #939.
46+
"""
47+
r_desired = -1
48+
u2 = noisy_percentile(u, r_desired, seed=fixed_seed)
49+
assert np.allclose(u2, u[::-1])

0 commit comments

Comments
 (0)