def test_bootstrap_existing_outcomes(setup):
    result = bootstrap(
        data=setup["df"],
        outcome=_outcome_func,
        n_draws=2,
    )
    assert len(result.outcomes) == 2
    result = bootstrap(
        outcome=_outcome_func,
        data=setup["df"],
        existing_result=result,
        n_draws=1,
    )
    assert len(result.outcomes) == 1
def test_outcome_not_callable(setup):
    expected_msg = "outcome must be a callable."

    with pytest.raises(ValueError) as error:
        assert bootstrap(data=setup["df"], outcome=setup["estimates_df"])

    assert str(error.value) == expected_msg
def test_bootstrap_with_outcome_kwargs(shift, setup):
    result = bootstrap(
        outcome=_outcome_func,
        data=setup["df"],
        seed=123,
        outcome_kwargs={"shift": shift},
    )

    expected = pd.Series([2.5, 7.0], index=["x1", "x2"])
    aaae(result.base_outcome, expected + shift)
def test_existing_result_wrong_input_type(input_type, setup):
    expected_msg = "existing_result must be None or a BootstrapResult."

    with pytest.raises(ValueError) as error:
        assert bootstrap(
            outcome=_outcome_func,
            data=setup["df"],
            existing_result=setup["estimates_" + input_type],
        )

    assert str(error.value) == expected_msg
def test_bootstrap_from_outcomes_single_outcome(setup, expected):

    result = bootstrap(outcome=_outcome_func,
                       data=setup["df"]["x1"],
                       seed=1234)

    _ = result.outcomes
    ci_lower, ci_upper = result.ci()

    aaae(ci_lower, expected["ci_lower_x1"])
    aaae(ci_upper, expected["ci_upper_x1"])
def test_cov_wrong_return_type(setup):
    result = bootstrap(
        outcome=_outcome_func,
        data=setup["df"],
    )

    expected_msg = "return_type must be one of pytree, array, or dataframe, not dict."

    with pytest.raises(ValueError) as error:
        assert result.cov(return_type="dict")

    assert str(error.value) == expected_msg
def test_existing_result(seaborn_example):
    first_result = bootstrap(data=seaborn_example["df"],
                             outcome=_outcome_ols,
                             seed=1234)

    expected_msg = "existing_result must be None or a BootstrapResult."
    with pytest.raises(ValueError) as error:
        assert bootstrap(
            data=seaborn_example["df"],
            outcome=_outcome_ols,
            existing_result=first_result.outcomes,
        )
    assert str(error.value) == expected_msg

    my_result = bootstrap(
        data=seaborn_example["df"],
        outcome=_outcome_ols,
        existing_result=first_result,
        seed=2,
    )
    lower_ci, upper_ci = my_result.ci(ci_method="t")

    aaae(lower_ci, seaborn_example["expected"]["lower_ci"])
    aaae(upper_ci, seaborn_example["expected"]["upper_ci"])
def test_bootstrap_from_outcomes_private_methods(setup, expected):

    result = bootstrap(outcome=_outcome_func, data=setup["df"], seed=1234)

    _ = result.outcomes
    ci_lower, ci_upper = result._ci
    covariance = result._cov
    standard_errors = result._se

    with pytest.raises(NotImplementedError):
        assert result._p_values

    aaae(ci_lower, expected["ci_lower"])
    aaae(ci_upper, expected["ci_upper"])
    aaae(covariance, expected["cov"])
    aaae(standard_errors, expected["se"])
def test_bootstrap_from_outcomes(setup, expected):

    result = bootstrap(outcome=_outcome_func, data=setup["df"], seed=1234)

    _ = result.outcomes
    summary = result.summary()
    ci_lower, ci_upper = result.ci()
    covariance = result.cov()
    standard_errors = result.se()

    with pytest.raises(NotImplementedError):
        assert result._p_values

    aaae(ci_lower, expected["ci_lower"])
    aaae(ci_upper, expected["ci_upper"])
    aaae(covariance, expected["cov"])
    aaae(standard_errors, expected["se"])

    aaae(summary["value"], expected["summary"]["value"])
    aaae(summary["standard_error"], expected["summary"]["standard_error"])
    aaae(summary["ci_lower"], expected["summary"]["ci_lower"])
    aaae(summary["ci_upper"], expected["summary"]["ci_upper"])
def test_cov_correct_return_type(return_type, setup):
    result = bootstrap(
        outcome=_outcome_func,
        data=setup["df"],
    )
    _ = result.cov(return_type=return_type)