-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix failing VI test due to pytest change #7144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
53641dd
remove pytest.warn()
aerubanov dac40ec
modify condition
aerubanov 2b7713f
add warning.catch_warnings
aerubanov ec8f238
remove unused code and add comment
aerubanov a225ba4
add check for missing warning
aerubanov 9826bd1
fix check
aerubanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| import io | ||
| import operator | ||
| import warnings | ||
|
|
||
| from contextlib import nullcontext | ||
|
|
||
|
|
@@ -196,18 +197,26 @@ def test_fit_start(inference_spec, simple_model): | |
|
|
||
| # Minibatch data can't be extracted into the `observed_data` group in the final InferenceData | ||
| [observed_value] = [simple_model.rvs_to_values[obs] for obs in simple_model.observed_RVs] | ||
| if observed_value.name.startswith("minibatch"): | ||
| warn_ctxt = pytest.warns( | ||
| UserWarning, match="Could not extract data from symbolic observation" | ||
| ) | ||
| else: | ||
| warn_ctxt = nullcontext() | ||
|
|
||
| try: | ||
| with warn_ctxt: | ||
| # We can`t use pytest.warns here because after version 8.0 it`s still check for warning when | ||
| # exception raised and test failed instead being skipped | ||
| warning_raised = False | ||
| expected_warning = observed_value.name.startswith("minibatch") | ||
| with warnings.catch_warnings(record=True) as record: | ||
| warnings.simplefilter("always") | ||
| try: | ||
| trace = inference.fit(n=0).sample(10000) | ||
| except NotImplementedInference as e: | ||
| pytest.skip(str(e)) | ||
| except NotImplementedInference as e: | ||
| pytest.skip(str(e)) | ||
|
|
||
| if expected_warning: | ||
| assert len(record) > 1 | ||
|
||
| for item in record: | ||
| assert issubclass(item.category, UserWarning) | ||
| assert "Could not extract data from symbolic observation" in str(item.message) | ||
| if not expected_warning: | ||
| assert not record | ||
|
|
||
| np.testing.assert_allclose(np.mean(trace.posterior["mu"]), mu_init, rtol=0.05) | ||
| if has_start_sigma: | ||
| np.testing.assert_allclose(np.std(trace.posterior["mu"]), mu_sigma_init, rtol=0.05) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.