optimagic-dev / optimagic

optimagic is a Python package for numerical optimization. It is a unified interface to optimizers from SciPy, NlOpt and other packages. optimagic's minimize function works just like SciPy's, so you don't have to adjust your code. You simply get more optimizers for free. On top you get diagnostic tools, parallel numerical derivatives and more.
https://optimagic.readthedocs.io/
MIT License
266 stars 30 forks source link

Bug in `get_moments_cov` #484

Closed alanlujan91 closed 8 months ago

alanlujan91 commented 8 months ago

Bug description

Small bug in get_moments_cov where bootstrap_kwargs does not correspond exactly to current bootstrap kwargs.

To Reproduce

rng = get_rng(1234)
data = rng.normal(scale=[10, 5, 1], size=(100, 3))
data = pd.DataFrame(data=data)
data["cluster"] = np.random.choice([1, 2, 3], size=100)

def calc_moments(data, keys):
    means = data.mean()
    means.index = keys
    return means.to_dict()

moment_kwargs = {"keys": ["a", "b", "c", "cluster"]}

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, "cluster_by": "cluster"},
    )

Expected behavior

cluster_by should be an allowable keyword

Screenshots/Error messages

image

System

alanlujan91 commented 8 months ago

Closed by #483