generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
496c65c
commit 2c34af7
Showing
12 changed files
with
128 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,51 +1,53 @@ | ||
import arviz as az | ||
import numpy as np | ||
import polars as pl | ||
import pytest | ||
import xarray as xr | ||
# import arviz as az | ||
# import numpy as np | ||
# import polars as pl | ||
# import pytest | ||
# import xarray as xr | ||
|
||
import forecasttools | ||
# import forecasttools | ||
|
||
|
||
@pytest.fixture | ||
def mock_inference_data(): | ||
np.random.seed(42) | ||
posterior_predictive = xr.Dataset( | ||
{ | ||
"observed_hospital_admissions": ("chain", np.random.randn(2, 100)), | ||
}, | ||
coords={"chain": [0, 1]}, | ||
) | ||
# @pytest.fixture | ||
# def mock_inference_data(): | ||
# np.random.seed(42) | ||
# posterior_predictive = xr.Dataset( | ||
# { | ||
# "observed_hospital_admissions": ("chain", np.random.randn(2, 100)), | ||
# }, | ||
# coords={"chain": [0, 1]}, | ||
# ) | ||
|
||
idata = az.from_dict(posterior_predictive=posterior_predictive) | ||
# idata = az.from_dict(posterior_predictive=posterior_predictive) | ||
|
||
return idata | ||
# return idata | ||
|
||
|
||
def test_valid_conversion(mock_inference_data): | ||
result = forecasttools.convert_inference_data_to_tidydraws( | ||
mock_inference_data, ["posterior_predictive"] | ||
) | ||
assert isinstance(result, dict) | ||
assert "posterior_predictive" in result | ||
assert isinstance(result["posterior_predictive"], pl.DataFrame) | ||
# def test_valid_conversion(mock_inference_data): | ||
# result = forecasttools.convert_inference_data_to_tidydraws( | ||
# mock_inference_data, ["posterior_predictive"] | ||
# ) | ||
# assert isinstance(result, dict) | ||
# assert "posterior_predictive" in result | ||
# assert isinstance(result["posterior_predictive"], pl.DataFrame) | ||
|
||
df = result["posterior_predictive"] | ||
assert all( | ||
col in df.columns | ||
for col in [".chain", ".draw", ".iteration", "variable", "value"] | ||
) | ||
# df = result["posterior_predictive"] | ||
# assert all( | ||
# col in df.columns | ||
# for col in [".chain", ".draw", ".iteration", "variable", "value"] | ||
# ) | ||
|
||
assert df[".draw"].n_unique() == df[".draw"].shape[0] | ||
# assert df[".draw"].n_unique() == df[".draw"].shape[0] | ||
|
||
|
||
def test_invalid_group(mock_inference_data): | ||
with pytest.raises(ValueError, match="Invalid groups provided"): | ||
forecasttools.convert_inference_data_to_tidydraws( | ||
mock_inference_data, ["invalid_group"] | ||
) | ||
# def test_invalid_group(mock_inference_data): | ||
# with pytest.raises(ValueError, match="Invalid groups provided"): | ||
# forecasttools.convert_inference_data_to_tidydraws( | ||
# mock_inference_data, ["invalid_group"] | ||
# ) | ||
|
||
|
||
def test_empty_group_list(mock_inference_data): | ||
result = forecasttools.convert_inference_data_to_tidydraws(mock_inference_data, []) | ||
assert result == {} | ||
# def test_empty_group_list(mock_inference_data): | ||
# result = forecasttools.convert_inference_data_to_tidydraws( | ||
# mock_inference_data, [] | ||
# ) | ||
# assert result == {} |
This file contains 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