From 50c15c3d770bfc41635cb762a30123b666080aad Mon Sep 17 00:00:00 2001 From: Tim Mensinger Date: Fri, 29 Dec 2023 13:07:41 +0100 Subject: [PATCH] Pass bootstrap_kwargs to bootstrap call in get_moments_cov (#473) --- src/estimagic/estimation/msm_weighting.py | 4 +++- tests/estimation/test_msm_weighting.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/estimagic/estimation/msm_weighting.py b/src/estimagic/estimation/msm_weighting.py index 97e5b437b..c5bef1411 100644 --- a/src/estimagic/estimation/msm_weighting.py +++ b/src/estimagic/estimation/msm_weighting.py @@ -58,7 +58,9 @@ def func(data, **kwargs): ) # xxxx won't be necessary soon! return out - cov_arr = bootstrap(data=data, outcome=func, outcome_kwargs=moment_kwargs).cov() + cov_arr = bootstrap( + data=data, outcome=func, outcome_kwargs=moment_kwargs, **bootstrap_kwargs + ).cov() if isinstance(cov_arr, pd.DataFrame): cov_arr = cov_arr.to_numpy() # xxxx won't be necessary soon diff --git a/tests/estimation/test_msm_weighting.py b/tests/estimation/test_msm_weighting.py index 7605b9641..c15375a59 100644 --- a/tests/estimation/test_msm_weighting.py +++ b/tests/estimation/test_msm_weighting.py @@ -85,3 +85,24 @@ def calc_moments(data, keys): assert cov.shape == (3, 3) assert cov[0, 0] > cov[1, 1] > cov[2, 2] + + +def test_get_moments_cov_passes_bootstrap_kwargs_to_bootstrap(): + rng = get_rng(1234) + data = rng.normal(scale=[10, 5, 1], size=(100, 3)) + data = pd.DataFrame(data=data) + + def calc_moments(data, keys): + means = data.mean() + means.index = keys + return means.to_dict() + + moment_kwargs = {"keys": ["a", "b", "c"]} + + with pytest.raises(ValueError, match="a must be a positive integer unless no"): + get_moments_cov( + data=data, + calculate_moments=calc_moments, + moment_kwargs=moment_kwargs, + bootstrap_kwargs={"n_draws": -1}, + )