Exemplo n.º 1
0
def test_binned_binom_proportion():

    # Check that it works.
    nbins = 20
    x = np.linspace(0., 10., 100)  # Guarantee an `x` in every bin.
    success = np.ones(len(x), dtype=bool)
    bin_ctr, bin_hw, p, perr = funcs.binned_binom_proportion(x,
                                                             success,
                                                             bins=nbins)

    # Check shape of outputs
    assert bin_ctr.shape == (nbins, )
    assert bin_hw.shape == (nbins, )
    assert p.shape == (nbins, )
    assert perr.shape == (2, nbins)

    # Check that p is 1 in all bins, since success = True for all `x`.
    assert (p == 1.).all()

    # Check that p is 0 in all bins if success = False for all `x`.
    success[:] = False
    bin_ctr, bin_hw, p, perr = funcs.binned_binom_proportion(x,
                                                             success,
                                                             bins=nbins)
    assert (p == 0.).all()
Exemplo n.º 2
0
def test_binned_binom_proportion():

    # Check that it works.
    nbins = 20
    x = np.linspace(0., 10., 100)  # Guarantee an `x` in every bin.
    success = np.ones(len(x), dtype=bool)
    bin_ctr, bin_hw, p, perr = funcs.binned_binom_proportion(x, success,
                                                             bins=nbins)

    # Check shape of outputs
    assert bin_ctr.shape == (nbins,)
    assert bin_hw.shape == (nbins,)
    assert p.shape == (nbins,)
    assert perr.shape == (2, nbins)

    # Check that p is 1 in all bins, since success = True for all `x`.
    assert (p == 1.).all()

    # Check that p is 0 in all bins if success = False for all `x`.
    success[:] = False
    bin_ctr, bin_hw, p, perr = funcs.binned_binom_proportion(x, success,
                                                             bins=nbins)
    assert (p == 0.).all()
Exemplo n.º 3
0
def test_binned_binom_proportion_exception():
    with pytest.raises(ValueError):
        with pytest.warns(AstropyDeprecationWarning):
            funcs.binned_binom_proportion([0], [1, 2], conf=0.75)
Exemplo n.º 4
0
def test_binned_binom_proportion_exception():
    with pytest.raises(ValueError):
        funcs.binned_binom_proportion([0], [1, 2], confidence_level=0.75)