arviz 0.23.3__py3-none-any.whl → 1.0.0rc0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arviz/__init__.py +52 -367
- arviz-1.0.0rc0.dist-info/METADATA +182 -0
- arviz-1.0.0rc0.dist-info/RECORD +5 -0
- {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/WHEEL +1 -2
- {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/licenses/LICENSE +0 -1
- arviz/data/__init__.py +0 -55
- arviz/data/base.py +0 -596
- arviz/data/converters.py +0 -203
- arviz/data/datasets.py +0 -161
- arviz/data/example_data/code/radon/radon.json +0 -326
- arviz/data/example_data/data/centered_eight.nc +0 -0
- arviz/data/example_data/data/non_centered_eight.nc +0 -0
- arviz/data/example_data/data_local.json +0 -12
- arviz/data/example_data/data_remote.json +0 -58
- arviz/data/inference_data.py +0 -2386
- arviz/data/io_beanmachine.py +0 -112
- arviz/data/io_cmdstan.py +0 -1036
- arviz/data/io_cmdstanpy.py +0 -1233
- arviz/data/io_datatree.py +0 -23
- arviz/data/io_dict.py +0 -462
- arviz/data/io_emcee.py +0 -317
- arviz/data/io_json.py +0 -54
- arviz/data/io_netcdf.py +0 -68
- arviz/data/io_numpyro.py +0 -497
- arviz/data/io_pyjags.py +0 -378
- arviz/data/io_pyro.py +0 -333
- arviz/data/io_pystan.py +0 -1095
- arviz/data/io_zarr.py +0 -46
- arviz/data/utils.py +0 -139
- arviz/labels.py +0 -210
- arviz/plots/__init__.py +0 -61
- arviz/plots/autocorrplot.py +0 -171
- arviz/plots/backends/__init__.py +0 -223
- arviz/plots/backends/bokeh/__init__.py +0 -166
- arviz/plots/backends/bokeh/autocorrplot.py +0 -101
- arviz/plots/backends/bokeh/bfplot.py +0 -23
- arviz/plots/backends/bokeh/bpvplot.py +0 -193
- arviz/plots/backends/bokeh/compareplot.py +0 -167
- arviz/plots/backends/bokeh/densityplot.py +0 -239
- arviz/plots/backends/bokeh/distcomparisonplot.py +0 -23
- arviz/plots/backends/bokeh/distplot.py +0 -183
- arviz/plots/backends/bokeh/dotplot.py +0 -113
- arviz/plots/backends/bokeh/ecdfplot.py +0 -73
- arviz/plots/backends/bokeh/elpdplot.py +0 -203
- arviz/plots/backends/bokeh/energyplot.py +0 -155
- arviz/plots/backends/bokeh/essplot.py +0 -176
- arviz/plots/backends/bokeh/forestplot.py +0 -772
- arviz/plots/backends/bokeh/hdiplot.py +0 -54
- arviz/plots/backends/bokeh/kdeplot.py +0 -268
- arviz/plots/backends/bokeh/khatplot.py +0 -163
- arviz/plots/backends/bokeh/lmplot.py +0 -185
- arviz/plots/backends/bokeh/loopitplot.py +0 -211
- arviz/plots/backends/bokeh/mcseplot.py +0 -184
- arviz/plots/backends/bokeh/pairplot.py +0 -328
- arviz/plots/backends/bokeh/parallelplot.py +0 -81
- arviz/plots/backends/bokeh/posteriorplot.py +0 -324
- arviz/plots/backends/bokeh/ppcplot.py +0 -379
- arviz/plots/backends/bokeh/rankplot.py +0 -149
- arviz/plots/backends/bokeh/separationplot.py +0 -107
- arviz/plots/backends/bokeh/traceplot.py +0 -436
- arviz/plots/backends/bokeh/violinplot.py +0 -164
- arviz/plots/backends/matplotlib/__init__.py +0 -124
- arviz/plots/backends/matplotlib/autocorrplot.py +0 -72
- arviz/plots/backends/matplotlib/bfplot.py +0 -78
- arviz/plots/backends/matplotlib/bpvplot.py +0 -177
- arviz/plots/backends/matplotlib/compareplot.py +0 -135
- arviz/plots/backends/matplotlib/densityplot.py +0 -194
- arviz/plots/backends/matplotlib/distcomparisonplot.py +0 -119
- arviz/plots/backends/matplotlib/distplot.py +0 -178
- arviz/plots/backends/matplotlib/dotplot.py +0 -116
- arviz/plots/backends/matplotlib/ecdfplot.py +0 -70
- arviz/plots/backends/matplotlib/elpdplot.py +0 -189
- arviz/plots/backends/matplotlib/energyplot.py +0 -113
- arviz/plots/backends/matplotlib/essplot.py +0 -180
- arviz/plots/backends/matplotlib/forestplot.py +0 -656
- arviz/plots/backends/matplotlib/hdiplot.py +0 -48
- arviz/plots/backends/matplotlib/kdeplot.py +0 -177
- arviz/plots/backends/matplotlib/khatplot.py +0 -241
- arviz/plots/backends/matplotlib/lmplot.py +0 -149
- arviz/plots/backends/matplotlib/loopitplot.py +0 -144
- arviz/plots/backends/matplotlib/mcseplot.py +0 -161
- arviz/plots/backends/matplotlib/pairplot.py +0 -355
- arviz/plots/backends/matplotlib/parallelplot.py +0 -58
- arviz/plots/backends/matplotlib/posteriorplot.py +0 -348
- arviz/plots/backends/matplotlib/ppcplot.py +0 -478
- arviz/plots/backends/matplotlib/rankplot.py +0 -119
- arviz/plots/backends/matplotlib/separationplot.py +0 -97
- arviz/plots/backends/matplotlib/traceplot.py +0 -526
- arviz/plots/backends/matplotlib/tsplot.py +0 -121
- arviz/plots/backends/matplotlib/violinplot.py +0 -148
- arviz/plots/bfplot.py +0 -128
- arviz/plots/bpvplot.py +0 -308
- arviz/plots/compareplot.py +0 -177
- arviz/plots/densityplot.py +0 -284
- arviz/plots/distcomparisonplot.py +0 -197
- arviz/plots/distplot.py +0 -233
- arviz/plots/dotplot.py +0 -233
- arviz/plots/ecdfplot.py +0 -372
- arviz/plots/elpdplot.py +0 -174
- arviz/plots/energyplot.py +0 -147
- arviz/plots/essplot.py +0 -319
- arviz/plots/forestplot.py +0 -304
- arviz/plots/hdiplot.py +0 -211
- arviz/plots/kdeplot.py +0 -357
- arviz/plots/khatplot.py +0 -236
- arviz/plots/lmplot.py +0 -380
- arviz/plots/loopitplot.py +0 -224
- arviz/plots/mcseplot.py +0 -194
- arviz/plots/pairplot.py +0 -281
- arviz/plots/parallelplot.py +0 -204
- arviz/plots/plot_utils.py +0 -599
- arviz/plots/posteriorplot.py +0 -298
- arviz/plots/ppcplot.py +0 -369
- arviz/plots/rankplot.py +0 -232
- arviz/plots/separationplot.py +0 -167
- arviz/plots/styles/arviz-bluish.mplstyle +0 -1
- arviz/plots/styles/arviz-brownish.mplstyle +0 -1
- arviz/plots/styles/arviz-colors.mplstyle +0 -2
- arviz/plots/styles/arviz-cyanish.mplstyle +0 -1
- arviz/plots/styles/arviz-darkgrid.mplstyle +0 -40
- arviz/plots/styles/arviz-doc.mplstyle +0 -88
- arviz/plots/styles/arviz-docgrid.mplstyle +0 -88
- arviz/plots/styles/arviz-grayscale.mplstyle +0 -41
- arviz/plots/styles/arviz-greenish.mplstyle +0 -1
- arviz/plots/styles/arviz-orangish.mplstyle +0 -1
- arviz/plots/styles/arviz-plasmish.mplstyle +0 -1
- arviz/plots/styles/arviz-purplish.mplstyle +0 -1
- arviz/plots/styles/arviz-redish.mplstyle +0 -1
- arviz/plots/styles/arviz-royish.mplstyle +0 -1
- arviz/plots/styles/arviz-viridish.mplstyle +0 -1
- arviz/plots/styles/arviz-white.mplstyle +0 -40
- arviz/plots/styles/arviz-whitegrid.mplstyle +0 -40
- arviz/plots/traceplot.py +0 -273
- arviz/plots/tsplot.py +0 -440
- arviz/plots/violinplot.py +0 -192
- arviz/preview.py +0 -58
- arviz/py.typed +0 -0
- arviz/rcparams.py +0 -606
- arviz/sel_utils.py +0 -223
- arviz/static/css/style.css +0 -340
- arviz/static/html/icons-svg-inline.html +0 -15
- arviz/stats/__init__.py +0 -37
- arviz/stats/density_utils.py +0 -1013
- arviz/stats/diagnostics.py +0 -1013
- arviz/stats/ecdf_utils.py +0 -324
- arviz/stats/stats.py +0 -2422
- arviz/stats/stats_refitting.py +0 -119
- arviz/stats/stats_utils.py +0 -609
- arviz/tests/__init__.py +0 -1
- arviz/tests/base_tests/__init__.py +0 -1
- arviz/tests/base_tests/test_data.py +0 -1679
- arviz/tests/base_tests/test_data_zarr.py +0 -143
- arviz/tests/base_tests/test_diagnostics.py +0 -511
- arviz/tests/base_tests/test_diagnostics_numba.py +0 -87
- arviz/tests/base_tests/test_helpers.py +0 -18
- arviz/tests/base_tests/test_labels.py +0 -69
- arviz/tests/base_tests/test_plot_utils.py +0 -342
- arviz/tests/base_tests/test_plots_bokeh.py +0 -1288
- arviz/tests/base_tests/test_plots_matplotlib.py +0 -2197
- arviz/tests/base_tests/test_rcparams.py +0 -317
- arviz/tests/base_tests/test_stats.py +0 -925
- arviz/tests/base_tests/test_stats_ecdf_utils.py +0 -166
- arviz/tests/base_tests/test_stats_numba.py +0 -45
- arviz/tests/base_tests/test_stats_utils.py +0 -384
- arviz/tests/base_tests/test_utils.py +0 -376
- arviz/tests/base_tests/test_utils_numba.py +0 -87
- arviz/tests/conftest.py +0 -46
- arviz/tests/external_tests/__init__.py +0 -1
- arviz/tests/external_tests/test_data_beanmachine.py +0 -78
- arviz/tests/external_tests/test_data_cmdstan.py +0 -398
- arviz/tests/external_tests/test_data_cmdstanpy.py +0 -496
- arviz/tests/external_tests/test_data_emcee.py +0 -166
- arviz/tests/external_tests/test_data_numpyro.py +0 -434
- arviz/tests/external_tests/test_data_pyjags.py +0 -119
- arviz/tests/external_tests/test_data_pyro.py +0 -260
- arviz/tests/external_tests/test_data_pystan.py +0 -307
- arviz/tests/helpers.py +0 -677
- arviz/utils.py +0 -773
- arviz/wrappers/__init__.py +0 -13
- arviz/wrappers/base.py +0 -236
- arviz/wrappers/wrap_pymc.py +0 -36
- arviz/wrappers/wrap_stan.py +0 -148
- arviz-0.23.3.dist-info/METADATA +0 -264
- arviz-0.23.3.dist-info/RECORD +0 -183
- arviz-0.23.3.dist-info/top_level.txt +0 -1
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
# pylint: disable=redefined-outer-name
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
import numpy as np
|
|
5
|
-
import pytest
|
|
6
|
-
from xarray.core.indexing import MemoryCachedArray
|
|
7
|
-
|
|
8
|
-
from ...data import datasets, load_arviz_data
|
|
9
|
-
from ...rcparams import (
|
|
10
|
-
_make_validate_choice,
|
|
11
|
-
_make_validate_choice_regex,
|
|
12
|
-
_validate_float_or_none,
|
|
13
|
-
_validate_positive_int_or_none,
|
|
14
|
-
_validate_probability,
|
|
15
|
-
make_iterable_validator,
|
|
16
|
-
rc_context,
|
|
17
|
-
rc_params,
|
|
18
|
-
rcParams,
|
|
19
|
-
read_rcfile,
|
|
20
|
-
)
|
|
21
|
-
from ...stats import compare
|
|
22
|
-
from ..helpers import models # pylint: disable=unused-import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### Test rcparams classes ###
|
|
26
|
-
def test_rc_context_dict():
|
|
27
|
-
rcParams["data.load"] = "lazy"
|
|
28
|
-
with rc_context(rc={"data.load": "eager"}):
|
|
29
|
-
assert rcParams["data.load"] == "eager"
|
|
30
|
-
assert rcParams["data.load"] == "lazy"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def test_rc_context_file():
|
|
34
|
-
path = os.path.dirname(os.path.abspath(__file__))
|
|
35
|
-
rcParams["data.load"] = "lazy"
|
|
36
|
-
with rc_context(fname=os.path.join(path, "../test.rcparams")):
|
|
37
|
-
assert rcParams["data.load"] == "eager"
|
|
38
|
-
assert rcParams["data.load"] == "lazy"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def test_bad_rc_file():
|
|
42
|
-
"""Test bad value raises error."""
|
|
43
|
-
path = os.path.dirname(os.path.abspath(__file__))
|
|
44
|
-
with pytest.raises(ValueError, match="Bad val "):
|
|
45
|
-
read_rcfile(os.path.join(path, "../bad.rcparams"))
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_warning_rc_file(caplog):
|
|
49
|
-
"""Test invalid lines and duplicated keys log warnings and bad value raises error."""
|
|
50
|
-
path = os.path.dirname(os.path.abspath(__file__))
|
|
51
|
-
read_rcfile(os.path.join(path, "../test.rcparams"))
|
|
52
|
-
records = caplog.records
|
|
53
|
-
assert len(records) == 1
|
|
54
|
-
assert records[0].levelname == "WARNING"
|
|
55
|
-
assert "Duplicate key" in caplog.text
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def test_bad_key():
|
|
59
|
-
"""Test the error when using unexistent keys in rcParams is correct."""
|
|
60
|
-
with pytest.raises(KeyError, match="bad_key is not a valid rc"):
|
|
61
|
-
rcParams["bad_key"] = "nothing"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def test_del_key_error():
|
|
65
|
-
"""Check that rcParams keys cannot be deleted."""
|
|
66
|
-
with pytest.raises(TypeError, match="keys cannot be deleted"):
|
|
67
|
-
del rcParams["data.load"]
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def test_clear_error():
|
|
71
|
-
"""Check that rcParams cannot be cleared."""
|
|
72
|
-
with pytest.raises(TypeError, match="keys cannot be deleted"):
|
|
73
|
-
rcParams.clear()
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def test_pop_error():
|
|
77
|
-
"""Check rcParams pop error."""
|
|
78
|
-
with pytest.raises(TypeError, match=r"keys cannot be deleted.*get\(key\)"):
|
|
79
|
-
rcParams.pop("data.load")
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def test_popitem_error():
|
|
83
|
-
"""Check rcParams popitem error."""
|
|
84
|
-
with pytest.raises(TypeError, match=r"keys cannot be deleted.*get\(key\)"):
|
|
85
|
-
rcParams.popitem()
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def test_setdefaults_error():
|
|
89
|
-
"""Check rcParams popitem error."""
|
|
90
|
-
with pytest.raises(TypeError, match="Use arvizrc"):
|
|
91
|
-
rcParams.setdefault("data.load", "eager")
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def test_rcparams_find_all():
|
|
95
|
-
data_rcparams = rcParams.find_all("data")
|
|
96
|
-
assert len(data_rcparams)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def test_rcparams_repr_str():
|
|
100
|
-
"""Check both repr and str print all keys."""
|
|
101
|
-
repr_str = repr(rcParams)
|
|
102
|
-
str_str = str(rcParams)
|
|
103
|
-
assert repr_str.startswith("RcParams")
|
|
104
|
-
for string in (repr_str, str_str):
|
|
105
|
-
assert all((key in string for key in rcParams.keys()))
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
### Test arvizrc.template file is up to date ###
|
|
109
|
-
def test_rctemplate_updated():
|
|
110
|
-
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../arvizrc.template")
|
|
111
|
-
rc_pars_template = read_rcfile(fname)
|
|
112
|
-
rc_defaults = rc_params(ignore_files=True)
|
|
113
|
-
assert all((key in rc_pars_template.keys() for key in rc_defaults.keys())), [
|
|
114
|
-
key for key in rc_defaults.keys() if key not in rc_pars_template
|
|
115
|
-
]
|
|
116
|
-
assert all((value == rc_pars_template[key] for key, value in rc_defaults.items())), [
|
|
117
|
-
key for key, value in rc_defaults.items() if value != rc_pars_template[key]
|
|
118
|
-
]
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
### Test validation functions ###
|
|
122
|
-
@pytest.mark.parametrize("param", ["data.load", "stats.information_criterion"])
|
|
123
|
-
def test_choice_bad_values(param):
|
|
124
|
-
"""Test error messages are correct for rcParams validated with _make_validate_choice."""
|
|
125
|
-
msg = "{}: bad_value is not one of".format(param.replace(".", r"\."))
|
|
126
|
-
with pytest.raises(ValueError, match=msg):
|
|
127
|
-
rcParams[param] = "bad_value"
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
@pytest.mark.parametrize("args", [("stats.hdi_prob", "stats.ci_prob", 0.7, 0.7)])
|
|
131
|
-
def test_deprecated_param(args):
|
|
132
|
-
"""Test value and warning message correctly set for deprecated rcparams."""
|
|
133
|
-
param_old, param_new, val_old, val_new = args
|
|
134
|
-
assert param_new in rcParams
|
|
135
|
-
assert not np.isclose(rcParams[param_new], val_new)
|
|
136
|
-
msg = f"{param_old} is deprecated since .*, use {param_new} instead"
|
|
137
|
-
with pytest.warns(FutureWarning, match=msg):
|
|
138
|
-
with rc_context(rc={param_old: val_old}):
|
|
139
|
-
assert np.isclose(rcParams[param_new], val_new)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
@pytest.mark.parametrize("allow_none", (True, False))
|
|
143
|
-
@pytest.mark.parametrize("typeof", (str, int))
|
|
144
|
-
@pytest.mark.parametrize("args", [("not one", 10), (False, None), (False, 4)])
|
|
145
|
-
def test_make_validate_choice(args, allow_none, typeof):
|
|
146
|
-
accepted_values = set(typeof(value) for value in (0, 1, 4, 6))
|
|
147
|
-
validate_choice = _make_validate_choice(accepted_values, allow_none=allow_none, typeof=typeof)
|
|
148
|
-
raise_error, value = args
|
|
149
|
-
if value is None and not allow_none:
|
|
150
|
-
raise_error = "not one of" if typeof == str else "Could not convert"
|
|
151
|
-
if raise_error:
|
|
152
|
-
with pytest.raises(ValueError, match=raise_error):
|
|
153
|
-
validate_choice(value)
|
|
154
|
-
else:
|
|
155
|
-
value = validate_choice(value)
|
|
156
|
-
assert value in accepted_values or value is None
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
@pytest.mark.parametrize("allow_none", (True, False))
|
|
160
|
-
@pytest.mark.parametrize(
|
|
161
|
-
"args",
|
|
162
|
-
[
|
|
163
|
-
(False, None),
|
|
164
|
-
(False, "row"),
|
|
165
|
-
(False, "54row"),
|
|
166
|
-
(False, "4column"),
|
|
167
|
-
("or in regex", "square"),
|
|
168
|
-
],
|
|
169
|
-
)
|
|
170
|
-
def test_make_validate_choice_regex(args, allow_none):
|
|
171
|
-
accepted_values = {"row", "column"}
|
|
172
|
-
accepted_values_regex = {r"\d*row", r"\d*column"}
|
|
173
|
-
validate_choice = _make_validate_choice_regex(
|
|
174
|
-
accepted_values, accepted_values_regex, allow_none=allow_none
|
|
175
|
-
)
|
|
176
|
-
raise_error, value = args
|
|
177
|
-
if value is None and not allow_none:
|
|
178
|
-
raise_error = "or in regex"
|
|
179
|
-
if raise_error:
|
|
180
|
-
with pytest.raises(ValueError, match=raise_error):
|
|
181
|
-
validate_choice(value)
|
|
182
|
-
else:
|
|
183
|
-
value_result = validate_choice(value)
|
|
184
|
-
assert value == value_result
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@pytest.mark.parametrize("allow_none", (True, False))
|
|
188
|
-
@pytest.mark.parametrize("allow_auto", (True, False))
|
|
189
|
-
@pytest.mark.parametrize("value", [(1, 2), "auto", None, "(1, 4)"])
|
|
190
|
-
def test_make_iterable_validator_none_auto(value, allow_auto, allow_none):
|
|
191
|
-
scalar_validator = _validate_float_or_none
|
|
192
|
-
validate_iterable = make_iterable_validator(
|
|
193
|
-
scalar_validator, allow_auto=allow_auto, allow_none=allow_none
|
|
194
|
-
)
|
|
195
|
-
raise_error = False
|
|
196
|
-
if value is None and not allow_none:
|
|
197
|
-
raise_error = "Only ordered iterable"
|
|
198
|
-
if value == "auto" and not allow_auto:
|
|
199
|
-
raise_error = "Could not convert"
|
|
200
|
-
if raise_error:
|
|
201
|
-
with pytest.raises(ValueError, match=raise_error):
|
|
202
|
-
validate_iterable(value)
|
|
203
|
-
else:
|
|
204
|
-
value = validate_iterable(value)
|
|
205
|
-
assert np.iterable(value) or value is None or value == "auto"
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
@pytest.mark.parametrize("length", (2, None))
|
|
209
|
-
@pytest.mark.parametrize("value", [(1, 5), (1, 3, 5), "(3, 4, 5)"])
|
|
210
|
-
def test_make_iterable_validator_length(value, length):
|
|
211
|
-
scalar_validator = _validate_float_or_none
|
|
212
|
-
validate_iterable = make_iterable_validator(scalar_validator, length=length)
|
|
213
|
-
raise_error = False
|
|
214
|
-
if length is not None and len(value) != length:
|
|
215
|
-
raise_error = "Iterable must be of length"
|
|
216
|
-
if raise_error:
|
|
217
|
-
with pytest.raises(ValueError, match=raise_error):
|
|
218
|
-
validate_iterable(value)
|
|
219
|
-
else:
|
|
220
|
-
value = validate_iterable(value)
|
|
221
|
-
assert np.iterable(value)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
@pytest.mark.parametrize(
|
|
225
|
-
"args",
|
|
226
|
-
[
|
|
227
|
-
("Only ordered iterable", set(["a", "b", "c"])),
|
|
228
|
-
("Could not convert", "johndoe"),
|
|
229
|
-
("Only ordered iterable", 15),
|
|
230
|
-
],
|
|
231
|
-
)
|
|
232
|
-
def test_make_iterable_validator_illegal(args):
|
|
233
|
-
scalar_validator = _validate_float_or_none
|
|
234
|
-
validate_iterable = make_iterable_validator(scalar_validator)
|
|
235
|
-
raise_error, value = args
|
|
236
|
-
with pytest.raises(ValueError, match=raise_error):
|
|
237
|
-
validate_iterable(value)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
@pytest.mark.parametrize(
|
|
241
|
-
"args",
|
|
242
|
-
[("Only positive", -1), ("Could not convert", "1.3"), (False, "2"), (False, None), (False, 1)],
|
|
243
|
-
)
|
|
244
|
-
def test_validate_positive_int_or_none(args):
|
|
245
|
-
raise_error, value = args
|
|
246
|
-
if raise_error:
|
|
247
|
-
with pytest.raises(ValueError, match=raise_error):
|
|
248
|
-
_validate_positive_int_or_none(value)
|
|
249
|
-
else:
|
|
250
|
-
value = _validate_positive_int_or_none(value)
|
|
251
|
-
assert isinstance(value, int) or value is None
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
@pytest.mark.parametrize(
|
|
255
|
-
"args",
|
|
256
|
-
[
|
|
257
|
-
("Only.+between 0 and 1", -1),
|
|
258
|
-
("Only.+between 0 and 1", "1.3"),
|
|
259
|
-
("not convert to float", "word"),
|
|
260
|
-
(False, "0.6"),
|
|
261
|
-
(False, 0),
|
|
262
|
-
(False, 1),
|
|
263
|
-
],
|
|
264
|
-
)
|
|
265
|
-
def test_validate_probability(args):
|
|
266
|
-
raise_error, value = args
|
|
267
|
-
if raise_error:
|
|
268
|
-
with pytest.raises(ValueError, match=raise_error):
|
|
269
|
-
_validate_probability(value)
|
|
270
|
-
else:
|
|
271
|
-
value = _validate_probability(value)
|
|
272
|
-
assert isinstance(value, float)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
### Test integration of rcParams in ArviZ ###
|
|
276
|
-
def test_data_load():
|
|
277
|
-
rcParams["data.load"] = "lazy"
|
|
278
|
-
idata_lazy = load_arviz_data("centered_eight")
|
|
279
|
-
assert isinstance(
|
|
280
|
-
idata_lazy.posterior.mu.variable._data, # pylint: disable=protected-access
|
|
281
|
-
MemoryCachedArray,
|
|
282
|
-
)
|
|
283
|
-
assert rcParams["data.load"] == "lazy"
|
|
284
|
-
rcParams["data.load"] = "eager"
|
|
285
|
-
idata_eager = load_arviz_data("centered_eight")
|
|
286
|
-
assert isinstance(
|
|
287
|
-
idata_eager.posterior.mu.variable._data, np.ndarray # pylint: disable=protected-access
|
|
288
|
-
)
|
|
289
|
-
assert rcParams["data.load"] == "eager"
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
def test_stats_information_criterion(models):
|
|
293
|
-
rcParams["stats.information_criterion"] = "waic"
|
|
294
|
-
df_comp = compare({"model1": models.model_1, "model2": models.model_2})
|
|
295
|
-
assert "elpd_waic" in df_comp.columns
|
|
296
|
-
rcParams["stats.information_criterion"] = "loo"
|
|
297
|
-
df_comp = compare({"model1": models.model_1, "model2": models.model_2})
|
|
298
|
-
assert "elpd_loo" in df_comp.columns
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
def test_http_type_request(monkeypatch):
|
|
302
|
-
def _urlretrive(url, _):
|
|
303
|
-
raise ValueError(f"URL Retrieved: {url}")
|
|
304
|
-
|
|
305
|
-
# Hijack url retrieve to inspect url passed
|
|
306
|
-
monkeypatch.setattr(datasets, "urlretrieve", _urlretrive)
|
|
307
|
-
|
|
308
|
-
# Test HTTPS default
|
|
309
|
-
with pytest.raises(ValueError) as error:
|
|
310
|
-
datasets.load_arviz_data("radon")
|
|
311
|
-
assert "https://" in str(error)
|
|
312
|
-
|
|
313
|
-
# Test HTTP setting
|
|
314
|
-
with pytest.raises(ValueError) as error:
|
|
315
|
-
rcParams["data.http_protocol"] = "http"
|
|
316
|
-
datasets.load_arviz_data("radon")
|
|
317
|
-
assert "http://" in str(error)
|