Skip to content

Fix failing test test_inverse_propΒ #336

Closed
@drbenvincent

Description

@drbenvincent

Slightly strange because all tests passed for #311. But we have a failing remote test for https://github.com/pymc-labs/CausalPy/actions/runs/8974649334/job/24647471387

On main I re-built the environment from scratch following instructions in CONTRIBUTING.md and can reproduce this bug locally:

FAILED causalpy/tests/test_pymc_experiments.py::test_inverse_prop - ValueError: autodetected range of [nan, nan] is not finite

This was fixed by adding in the rand_seed code to the PropensityScore.fit method which overrides the ModelBuilder.fit method. So the method should now be:

def fit(self, X, t, coords):
    """Draw samples from posterior, prior predictive, and posterior predictive
    distributions. We overwrite the base method because the base method assumes
    a variable y and we use t to indicate the treatment variable here.
    """

    # Ensure random_seed is used in sample_prior_predictive() and
    # sample_posterior_predictive() if provided in sample_kwargs.
    random_seed = self.sample_kwargs.get("random_seed", None)

    self.build_model(X, t, coords)
    with self:
        self.idata = pm.sample(**self.sample_kwargs)
        self.idata.extend(pm.sample_prior_predictive(random_seed=random_seed))
        self.idata.extend(
            pm.sample_posterior_predictive(
                self.idata, progressbar=False, random_seed=random_seed
            )
        )
    return self.idata

Though it's worth double checking the details of the test and error message which I didn't do πŸ€·πŸ»β€β™‚οΈπŸ˜œ

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions