Skip to content

Commit

Permalink
Merge pull request astropy#1005 from aphearin/pep8_check
Browse files Browse the repository at this point in the history
Reformatting to testing module by black
  • Loading branch information
aphearin authored Dec 11, 2020
2 parents bfc466b + a451cf7 commit 6499cff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
- master
# tags: # run CI if specific tags are pushed
pull_request:
- master
branches:
- master

jobs:
# Github Actions supports ubuntu, windows, and macos virtual environments:
Expand All @@ -17,25 +18,15 @@ jobs:
strategy:
matrix:
include:
- name: Code style checks
os: ubuntu-latest
python: 3.x
toxenv: codestyle

- name: Python 3.7 with minimal dependencies
- name: Ubuntu - Python 3.7 with all optional dependencies
os: ubuntu-latest
python: 3.7
toxenv: py37-test
toxenv: 'py37-test-alldeps'

- name: Python 3.7 with minimal dependencies
- name: MacOs - Python 3.7 with all optional dependencies
os: macos-latest
python: 3.7
toxenv: py37-test-alldeps

- name: Windows - Python 3.8 with all optional dependencies
os: windows-latest
python: 3.7
toxenv: py38-test-alldeps
toxenv: 'py37-test-alldeps'

steps:
- name: Checkout code
Expand Down
40 changes: 23 additions & 17 deletions halotools/utils/tests/test_its.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,38 @@
import pytest
import warnings

from ..inverse_transformation_sampling import _sorted_rank_order_array, rank_order_percentile
from ..inverse_transformation_sampling import build_cdf_lookup, monte_carlo_from_cdf_lookup
from ..inverse_transformation_sampling import (
_sorted_rank_order_array,
rank_order_percentile,
)
from ..inverse_transformation_sampling import (
build_cdf_lookup,
monte_carlo_from_cdf_lookup,
)

__all__ = ('test_sorted_rank_order_array', )
__all__ = ("test_sorted_rank_order_array",)


def test_sorted_rank_order_array():
result = _sorted_rank_order_array(4)
assert np.all(result == (1/5., 2/5., 3/5., 4/5.))
assert np.all(result == (1 / 5.0, 2 / 5.0, 3 / 5.0, 4 / 5.0))


def test_rank_order_percentile1():
result = rank_order_percentile((1, 2, 3, 4))
assert np.all(result == (1/5., 2/5., 3/5., 4/5.))
assert np.all(result == (1 / 5.0, 2 / 5.0, 3 / 5.0, 4 / 5.0))


def test_rank_order_percentile2():
result = rank_order_percentile((4, 3, 2, 1))
assert np.all(result == (4/5., 3/5., 2/5., 1/5.))
assert np.all(result == (4 / 5.0, 3 / 5.0, 2 / 5.0, 1 / 5.0))


def test_rank_order_percentile3():
with NumpyRNGContext(43):
randoms = np.random.rand(100)
result1 = rank_order_percentile(randoms)
result2 = rank_order_percentile(0.5*randoms)
result2 = rank_order_percentile(0.5 * randoms)
assert np.all(result1 == result2)


Expand All @@ -56,29 +62,28 @@ def test_build_cdf_lookup3():
npts = int(1e5)
with NumpyRNGContext(43):
y = np.random.normal(size=npts, loc=900)
x_table, y_table = build_cdf_lookup(y, npts_lookup_table=npts//10)
assert np.allclose(y_table.mean(), 900., atol=0.01)
x_table, y_table = build_cdf_lookup(y, npts_lookup_table=npts // 10)
assert np.allclose(y_table.mean(), 900.0, atol=0.01)


def test_monte_carlo_from_cdf_lookup1():
npts = int(1e5)
mean = 50.
mean = 50.0
std = 0.5
with NumpyRNGContext(43):
y = np.random.normal(size=npts, loc=mean, scale=std)
x_table, y_table = build_cdf_lookup(y)
mc_y = monte_carlo_from_cdf_lookup(x_table, y_table,
num_draws=npts+5, seed=43)
mc_y = monte_carlo_from_cdf_lookup(x_table, y_table, num_draws=npts + 5, seed=43)

assert len(mc_y) == npts+5
assert len(mc_y) == npts + 5
assert np.allclose(mc_y.mean(), mean, rtol=0.01)


def test_monte_carlo_from_cdf_lookup2():
"""
"""
npts = int(1e4)
y = 0.3*np.random.normal(size=npts) + 0.7*np.random.power(2, size=npts)
y = 0.3 * np.random.normal(size=npts) + 0.7 * np.random.power(2, size=npts)
x_table, y_table = build_cdf_lookup(y)

with pytest.raises(ValueError) as err:
Expand All @@ -91,12 +96,13 @@ def test_monte_carlo_from_cdf_lookup3():
"""
"""
npts = int(1e4)
y = 0.3*np.random.normal(size=npts) + 0.7*np.random.power(2, size=npts)
y = 0.3 * np.random.normal(size=npts) + 0.7 * np.random.power(2, size=npts)
x_table, y_table = build_cdf_lookup(y)

with pytest.raises(ValueError) as err:
monte_carlo_from_cdf_lookup(x_table, y_table,
mc_input=np.array((0.1, 0.4, 0.25)), num_draws=10)
monte_carlo_from_cdf_lookup(
x_table, y_table, mc_input=np.array((0.1, 0.4, 0.25)), num_draws=10
)
substr = "If input ``mc_input`` is specified"
assert substr in err.value.args[0]

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py37
envlist = py37-test-alldeps

[testenv]
deps =
Expand Down

0 comments on commit 6499cff

Please sign in to comment.