pystan icon indicating copy to clipboard operation
pystan copied to clipboard

fix: Update `num_samples_saved` formula in `fit.py`

Open ahartikainen opened this issue 2 years ago • 3 comments

Fixes #366

Fixes the formula to calculate num_samples_saved. Updates a test in tests/test_normal.py to hit this specific problem for both num_samples and num_warmup when save_warmup=True.

ahartikainen avatar Oct 07 '22 20:10 ahartikainen

Looks good to me. Let's fix the CI before merging though.

riddell-stan avatar Oct 09 '22 14:10 riddell-stan

This test does not raise any errors now. Is this due to update in httpstan or where in pystan code should it raise that error?

def test_bernoulli_sampling_invalid_argument(posterior):
    with pytest.raises(TypeError, match=r"'float' object cannot be interpreted as an integer"):
        posterior.sample(num_thin=2.0)

edit. Oh yeah, math.ceil makes the input an integer. Should we add an assert statement somewhere to check this?

ahartikainen avatar Oct 10 '22 20:10 ahartikainen

First, let's adjust that test so it's more obvious what the problem is: num_thin=2.5 would be even clearer.

Sure, add an isinstance check (with a ValueError exception if it's not an integer). I think doing that is cleaner than an assert.

riddell-stan avatar Oct 11 '22 13:10 riddell-stan

LGTM!

riddell-stan avatar Oct 16 '22 20:10 riddell-stan