From 0d53b893bfa36655c5b0cfa4e10db081e1049001 Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 21 Feb 2024 22:37:09 +0100 Subject: [PATCH 1/7] general maintenance --- .azure-pipelines/azure-pipelines-base.yml | 6 +-- arviz/data/inference_data.py | 2 +- arviz/plots/backends/bokeh/bpvplot.py | 4 +- arviz/plots/backends/bokeh/compareplot.py | 11 +++-- arviz/plots/backends/bokeh/forestplot.py | 2 +- arviz/plots/backends/bokeh/pairplot.py | 8 +--- .../plots/backends/matplotlib/compareplot.py | 2 +- arviz/plots/backends/matplotlib/forestplot.py | 2 +- arviz/plots/backends/matplotlib/traceplot.py | 2 +- arviz/plots/bfplot.py | 13 ++--- arviz/plots/bpvplot.py | 4 +- arviz/plots/compareplot.py | 4 +- arviz/plots/elpdplot.py | 2 +- arviz/plots/essplot.py | 4 +- arviz/plots/pairplot.py | 2 +- arviz/plots/ppcplot.py | 4 +- arviz/stats/density_utils.py | 4 +- arviz/stats/diagnostics.py | 4 +- arviz/stats/stats.py | 48 +++++++------------ arviz/stats/stats_utils.py | 2 +- arviz/tests/base_tests/test_data.py | 8 ++-- arviz/tests/base_tests/test_stats_utils.py | 6 +-- .../tests/external_tests/test_data_numpyro.py | 6 +-- arviz/tests/external_tests/test_data_pyro.py | 6 +-- examples/matplotlib/mpl_styles.py | 4 +- requirements-docs.txt | 2 +- setup.py | 4 +- 27 files changed, 74 insertions(+), 92 deletions(-) diff --git a/.azure-pipelines/azure-pipelines-base.yml b/.azure-pipelines/azure-pipelines-base.yml index 82a50ca319..df6f821065 100644 --- a/.azure-pipelines/azure-pipelines-base.yml +++ b/.azure-pipelines/azure-pipelines-base.yml @@ -10,10 +10,10 @@ jobs: timeoutInMinutes: 360 strategy: matrix: - Python_39: - python.version: "3.9" + Python_312: + python.version: "3.12" PyPIGithub: false - name: "Python 3.9" + name: "Python 3.12" Python_311: python.version: "3.11" PyPIGithub: false diff --git a/arviz/data/inference_data.py b/arviz/data/inference_data.py index ce8a8a28eb..e3b8274ecf 100644 --- a/arviz/data/inference_data.py +++ b/arviz/data/inference_data.py @@ -1490,7 +1490,7 @@ def add_groups(self, group_dict=None, coords=None, dims=None, **kwargs): import numpy as np rng = np.random.default_rng(73) - ary = rng.normal(size=(post.dims["chain"], post.dims["draw"], obs.dims["match"])) + ary = rng.normal(size=(post.sizes["chain"], post.sizes["draw"], obs.sizes["match"])) idata.add_groups( log_likelihood={"home_points": ary}, dims={"home_points": ["match"]}, diff --git a/arviz/plots/backends/bokeh/bpvplot.py b/arviz/plots/backends/bokeh/bpvplot.py index 3b9aced0ab..55999799ea 100644 --- a/arviz/plots/backends/bokeh/bpvplot.py +++ b/arviz/plots/backends/bokeh/bpvplot.py @@ -171,8 +171,8 @@ def plot_bpv( ax_i.line(0, 0, legend_label=f"bpv={p_value:.2f}", alpha=0) if plot_mean: - ax_i.circle( - obs_vals.mean(), 0, fill_color=color, line_color="black", size=markersize + ax_i.scatter( + obs_vals.mean(), 0, fill_color=color, line_color="black", size=markersize, marker="circle" ) _title = Title() diff --git a/arviz/plots/backends/bokeh/compareplot.py b/arviz/plots/backends/bokeh/compareplot.py index e5cc02902a..98b8e22934 100644 --- a/arviz/plots/backends/bokeh/compareplot.py +++ b/arviz/plots/backends/bokeh/compareplot.py @@ -69,13 +69,14 @@ def plot_compare( err_ys.append((y, y)) # plot them - dif_tri = ax.triangle( + dif_tri = ax.scatter( comp_df[information_criterion].iloc[1:], yticks_pos[1::2], line_color=plot_kwargs.get("color_dse", "grey"), fill_color=plot_kwargs.get("color_dse", "grey"), line_width=2, size=6, + marker="triangle", ) dif_line = ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get("color_dse", "grey")) @@ -85,13 +86,14 @@ def plot_compare( ax.yaxis.ticker = yticks_pos[::2] ax.yaxis.major_label_overrides = dict(zip(yticks_pos[::2], yticks_labels)) - elpd_circ = ax.circle( + elpd_circ = ax.scatter( comp_df[information_criterion], yticks_pos[::2], line_color=plot_kwargs.get("color_ic", "black"), fill_color=None, line_width=2, size=6, + marker="circle" ) elpd_label = [elpd_circ] @@ -110,7 +112,7 @@ def plot_compare( labels.append(("ELPD", elpd_label)) - scale = comp_df["scale"][0] + scale = comp_df["scale"].iloc[0] if insample_dev: p_ic = comp_df[f"p_{information_criterion.split('_')[1]}"] @@ -120,13 +122,14 @@ def plot_compare( correction = -p_ic elif scale == "deviance": correction = -(2 * p_ic) - insample_circ = ax.circle( + insample_circ = ax.scatter( comp_df[information_criterion] + correction, yticks_pos[::2], line_color=plot_kwargs.get("color_insample_dev", "black"), fill_color=plot_kwargs.get("color_insample_dev", "black"), line_width=2, size=6, + marker="circle" ) labels.append(("In-sample ELPD", [insample_circ])) diff --git a/arviz/plots/backends/bokeh/forestplot.py b/arviz/plots/backends/bokeh/forestplot.py index c2bb231915..dd078e25bf 100644 --- a/arviz/plots/backends/bokeh/forestplot.py +++ b/arviz/plots/backends/bokeh/forestplot.py @@ -640,7 +640,7 @@ def iterator(self): grouped_data = [[(0, datum)] for datum in self.data] skip_dims = self.combine_dims.union({"chain"}) else: - grouped_data = [datum.groupby("chain") for datum in self.data] + grouped_data = [datum.groupby("chain", squeeze=False) for datum in self.data] skip_dims = self.combine_dims label_dict = OrderedDict() diff --git a/arviz/plots/backends/bokeh/pairplot.py b/arviz/plots/backends/bokeh/pairplot.py index 5701140925..61dba8b839 100644 --- a/arviz/plots/backends/bokeh/pairplot.py +++ b/arviz/plots/backends/bokeh/pairplot.py @@ -173,12 +173,8 @@ def plot_pair( source = ColumnDataSource(data=source_dict) if divergences: - source_nondiv = CDSView( - source=source, filters=[GroupFilter(column_name=divergenve_name, group="0")] - ) - source_div = CDSView( - source=source, filters=[GroupFilter(column_name=divergenve_name, group="1")] - ) + source_nondiv = CDSView(filter=GroupFilter(column_name=divergenve_name, group="0")) + source_div = CDSView(filter=GroupFilter(column_name=divergenve_name, group="1")) def get_width_and_height(jointplot, rotate): """Compute subplots dimensions for two or more variables.""" diff --git a/arviz/plots/backends/matplotlib/compareplot.py b/arviz/plots/backends/matplotlib/compareplot.py index ee7f6ac081..2929341c29 100644 --- a/arviz/plots/backends/matplotlib/compareplot.py +++ b/arviz/plots/backends/matplotlib/compareplot.py @@ -84,7 +84,7 @@ def plot_compare( else: ax.set_yticks(yticks_pos[::2]) - scale = comp_df["scale"][0] + scale = comp_df["scale"].iloc[0] if insample_dev: p_ic = comp_df[f"p_{information_criterion.split('_')[1]}"] diff --git a/arviz/plots/backends/matplotlib/forestplot.py b/arviz/plots/backends/matplotlib/forestplot.py index d3bffee129..9e6e9a0edc 100644 --- a/arviz/plots/backends/matplotlib/forestplot.py +++ b/arviz/plots/backends/matplotlib/forestplot.py @@ -536,7 +536,7 @@ def iterator(self): grouped_data = [[(0, datum)] for datum in self.data] skip_dims = self.combine_dims.union({"chain"}) else: - grouped_data = [datum.groupby("chain") for datum in self.data] + grouped_data = [datum.groupby("chain", squeeze=False) for datum in self.data] skip_dims = self.combine_dims label_dict = OrderedDict() diff --git a/arviz/plots/backends/matplotlib/traceplot.py b/arviz/plots/backends/matplotlib/traceplot.py index fb5c591f8c..7b6d6b8e07 100644 --- a/arviz/plots/backends/matplotlib/traceplot.py +++ b/arviz/plots/backends/matplotlib/traceplot.py @@ -430,7 +430,7 @@ def plot_trace( Line2D( [], [], label=chain_id, **dealiase_sel_kwargs(legend_kwargs, chain_prop, chain_id) ) - for chain_id in range(data.dims["chain"]) + for chain_id in range(data.sizes["chain"]) ] if combined: handles.insert( diff --git a/arviz/plots/bfplot.py b/arviz/plots/bfplot.py index bc1d1899f6..8a47178ba3 100644 --- a/arviz/plots/bfplot.py +++ b/arviz/plots/bfplot.py @@ -38,7 +38,7 @@ def plot_bf( algorithm presented in [1]_. Parameters - ----------- + ---------- idata : InferenceData Any object that can be converted to an :class:`arviz.InferenceData` object Refer to documentation of :func:`arviz.convert_to_dataset` for details. @@ -52,16 +52,16 @@ def plot_bf( Tuple of valid Matplotlib colors. First element for the prior, second for the posterior. figsize : (float, float), optional Figure size. If `None` it will be defined automatically. - textsize: float, optional + textsize : float, optional Text size scaling factor for labels, titles and lines. If `None` it will be auto scaled based on `figsize`. - plot_kwargs : dicts, optional + plot_kwargs : dict, optional Additional keywords passed to :func:`matplotlib.pyplot.plot`. - hist_kwargs : dicts, optional + hist_kwargs : dict, optional Additional keywords passed to :func:`arviz.plot_dist`. Only works for discrete variables. ax : axes, optional :class:`matplotlib.axes.Axes` or :class:`bokeh.plotting.Figure`. - backend :{"matplotlib", "bokeh"}, default "matplotlib" + backend : {"matplotlib", "bokeh"}, default "matplotlib" Select plotting backend. backend_kwargs : dict, optional These are kwargs specific to the backend being used, passed to @@ -78,7 +78,7 @@ def plot_bf( References ---------- .. [1] Heck, D., 2019. A caveat on the Savage-Dickey density ratio: - The case of computing Bayes factors for regression parameters. + The case of computing Bayes factors for regression parameters. Examples -------- @@ -92,6 +92,7 @@ def plot_bf( >>> idata = az.from_dict(posterior={"a":np.random.normal(1, 0.5, 5000)}, ... prior={"a":np.random.normal(0, 1, 5000)}) >>> az.plot_bf(idata, var_name="a", ref_val=0) + """ posterior = extract(idata, var_names=var_name).values diff --git a/arviz/plots/bpvplot.py b/arviz/plots/bpvplot.py index d0a7acac5a..2127d972e0 100644 --- a/arviz/plots/bpvplot.py +++ b/arviz/plots/bpvplot.py @@ -230,11 +230,11 @@ def plot_bpv( if flatten_pp is None: if flatten is None: - flatten_pp = list(predictive_dataset.dims.keys()) + flatten_pp = list(predictive_dataset.dims) else: flatten_pp = flatten if flatten is None: - flatten = list(observed.dims.keys()) + flatten = list(observed.dims) if coords is None: coords = {} diff --git a/arviz/plots/compareplot.py b/arviz/plots/compareplot.py index 31953a3cee..97bd74fd3e 100644 --- a/arviz/plots/compareplot.py +++ b/arviz/plots/compareplot.py @@ -90,10 +90,10 @@ def plot_compare( References ---------- .. [1] Vehtari et al. (2016). Practical Bayesian model evaluation using leave-one-out - cross-validation and WAIC https://arxiv.org/abs/1507.04544 + cross-validation and WAIC https://arxiv.org/abs/1507.04544 .. [2] McElreath R. (2022). Statistical Rethinking A Bayesian Course with Examples in - R and Stan, Second edition, CRC Press. + R and Stan, Second edition, CRC Press. Examples -------- diff --git a/arviz/plots/elpdplot.py b/arviz/plots/elpdplot.py index d85e3c6a39..54078ddda3 100644 --- a/arviz/plots/elpdplot.py +++ b/arviz/plots/elpdplot.py @@ -98,7 +98,7 @@ def plot_elpd( References ---------- .. [1] Vehtari et al. (2016). Practical Bayesian model evaluation using leave-one-out - cross-validation and WAIC https://arxiv.org/abs/1507.04544 + cross-validation and WAIC https://arxiv.org/abs/1507.04544 Examples -------- diff --git a/arviz/plots/essplot.py b/arviz/plots/essplot.py index 40839cbb60..dadc51fe83 100644 --- a/arviz/plots/essplot.py +++ b/arviz/plots/essplot.py @@ -202,8 +202,8 @@ def plot_ess( data = get_coords(convert_to_dataset(idata, group="posterior"), coords) var_names = _var_names(var_names, data, filter_vars) - n_draws = data.dims["draw"] - n_samples = n_draws * data.dims["chain"] + n_draws = data.sizes["draw"] + n_samples = n_draws * data.sizes["chain"] ess_tail_dataset = None mean_ess = None diff --git a/arviz/plots/pairplot.py b/arviz/plots/pairplot.py index 4c264aa9a0..78fe4f8e24 100644 --- a/arviz/plots/pairplot.py +++ b/arviz/plots/pairplot.py @@ -229,7 +229,7 @@ def plot_pair( ) if gridsize == "auto": - gridsize = int(dataset.dims["draw"] ** 0.35) + gridsize = int(dataset.sizes["draw"] ** 0.35) numvars = len(flat_var_names) diff --git a/arviz/plots/ppcplot.py b/arviz/plots/ppcplot.py index a9dde7a23d..8d1ee80312 100644 --- a/arviz/plots/ppcplot.py +++ b/arviz/plots/ppcplot.py @@ -269,11 +269,11 @@ def plot_ppc( if flatten_pp is None: if flatten is None: - flatten_pp = list(predictive_dataset.dims.keys()) + flatten_pp = list(predictive_dataset.dims) else: flatten_pp = flatten if flatten is None: - flatten = list(observed_data.dims.keys()) + flatten = list(observed_data.dims) if coords is None: coords = {} diff --git a/arviz/stats/density_utils.py b/arviz/stats/density_utils.py index d28d285fb4..ac0bb79acd 100644 --- a/arviz/stats/density_utils.py +++ b/arviz/stats/density_utils.py @@ -231,8 +231,8 @@ def _fixed_point(t, N, k_sq, a_sq): Z. I. Botev, J. F. Grotowski, and D. P. Kroese. Ann. Statist. 38 (2010), no. 5, 2916--2957. """ - k_sq = np.asfarray(k_sq, dtype=np.float64) - a_sq = np.asfarray(a_sq, dtype=np.float64) + k_sq = np.asarray(k_sq, dtype=np.float64) + a_sq = np.asarray(a_sq, dtype=np.float64) l = 7 f = np.sum(np.power(k_sq, l) * a_sq * np.exp(-k_sq * np.pi**2 * t)) diff --git a/arviz/stats/diagnostics.py b/arviz/stats/diagnostics.py index c14ae5b286..8430479c15 100644 --- a/arviz/stats/diagnostics.py +++ b/arviz/stats/diagnostics.py @@ -457,10 +457,10 @@ def ks_summary(pareto_tail_indices): """ _numba_flag = Numba.numba_flag if _numba_flag: - bins = np.asarray([-np.Inf, 0.5, 0.7, 1, np.Inf]) + bins = np.asarray([-np.inf, 0.5, 0.7, 1, np.inf]) kcounts, *_ = _histogram(pareto_tail_indices, bins) else: - kcounts, *_ = _histogram(pareto_tail_indices, bins=[-np.Inf, 0.5, 0.7, 1, np.Inf]) + kcounts, *_ = _histogram(pareto_tail_indices, bins=[-np.inf, 0.5, 0.7, 1, np.inf]) kprop = kcounts / len(pareto_tail_indices) * 100 df_k = pd.DataFrame( dict(_=["(good)", "(ok)", "(bad)", "(very bad)"], Count=kcounts, Pct=kprop) diff --git a/arviz/stats/stats.py b/arviz/stats/stats.py index 7e17025f33..b58951685a 100644 --- a/arviz/stats/stats.py +++ b/arviz/stats/stats.py @@ -146,6 +146,7 @@ def compare( Compare the centered and non centered models of the eight school problem: .. ipython:: + :okwarning: In [1]: import arviz as az ...: data1 = az.load_arviz_data("non_centered_eight") @@ -157,6 +158,7 @@ def compare( weights using the stacking method. .. ipython:: + :okwarning: In [1]: az.compare(compare_dict, ic="loo", method="stacking", scale="log") @@ -180,37 +182,19 @@ def compare( except Exception as e: raise e.__class__("Encountered error in ELPD computation of compare.") from e names = list(ics_dict.keys()) - if ic == "loo": + if ic in {"loo", "waic"}: df_comp = pd.DataFrame( - index=names, - columns=[ - "rank", - "elpd_loo", - "p_loo", - "elpd_diff", - "weight", - "se", - "dse", - "warning", - "scale", - ], - dtype=np.float_, - ) - elif ic == "waic": - df_comp = pd.DataFrame( - index=names, - columns=[ - "rank", - "elpd_waic", - "p_waic", - "elpd_diff", - "weight", - "se", - "dse", - "warning", - "scale", - ], - dtype=np.float_, + { + "rank": pd.Series(index=names, dtype="int"), + f"elpd_{ic}": pd.Series(index=names, dtype="float"), + f"p_{ic}": pd.Series(index=names, dtype="float"), + "elpd_diff": pd.Series(index=names, dtype="float"), + "weight": pd.Series(index=names, dtype="float"), + "se": pd.Series(index=names, dtype="float"), + "dse": pd.Series(index=names, dtype="float"), + "warning": pd.Series(index=names, dtype="boolean"), + "scale": pd.Series(index=names, dtype="str"), + } ) else: raise NotImplementedError(f"The information criterion {ic} is not supported.") @@ -632,7 +616,7 @@ def _hdi(ary, hdi_prob, circular, skipna): ary = np.sort(ary) interval_idx_inc = int(np.floor(hdi_prob * n)) n_intervals = n - interval_idx_inc - interval_width = np.subtract(ary[interval_idx_inc:], ary[:n_intervals], dtype=np.float_) + interval_width = np.subtract(ary[interval_idx_inc:], ary[:n_intervals], dtype=np.float64) if len(interval_width) == 0: raise ValueError("Too few elements for interval calculation. ") @@ -2096,7 +2080,7 @@ def weight_predictions(idatas, weights=None): weights /= weights.sum() len_idatas = [ - idata.posterior_predictive.dims["chain"] * idata.posterior_predictive.dims["draw"] + idata.posterior_predictive.sizes["chain"] * idata.posterior_predictive.sizes["draw"] for idata in idatas ] diff --git a/arviz/stats/stats_utils.py b/arviz/stats/stats_utils.py index 5a3bc20bb4..e2c3b34323 100644 --- a/arviz/stats/stats_utils.py +++ b/arviz/stats/stats_utils.py @@ -484,7 +484,7 @@ def __str__(self): base += "\n\nThere has been a warning during the calculation. Please check the results." if kind == "loo" and "pareto_k" in self: - bins = np.asarray([-np.Inf, 0.5, 0.7, 1, np.Inf]) + bins = np.asarray([-np.inf, 0.5, 0.7, 1, np.inf]) counts, *_ = _histogram(self.pareto_k.values, bins) extended = POINTWISE_LOO_FMT.format(max(4, len(str(np.max(counts))))) extended = extended.format( diff --git a/arviz/tests/base_tests/test_data.py b/arviz/tests/base_tests/test_data.py index 2f1179a476..a777898b96 100644 --- a/arviz/tests/base_tests/test_data.py +++ b/arviz/tests/base_tests/test_data.py @@ -1241,7 +1241,7 @@ def test_inference_data(self, data, eight_schools_params): self.check_var_names_coords_dims(inference_data.prior_predictive) self.check_var_names_coords_dims(inference_data.sample_stats_prior) - pred_dims = inference_data.predictions.dims["school_pred"] + pred_dims = inference_data.predictions.sizes["school_pred"] assert pred_dims == 8 def test_inference_data_warmup(self, data, eight_schools_params): @@ -1586,8 +1586,8 @@ def test_no_combine(self): idata = load_arviz_data("centered_eight") post = extract(idata, combined=False) assert "sample" not in post.dims - assert post.dims["chain"] == 4 - assert post.dims["draw"] == 500 + assert post.sizes["chain"] == 4 + assert post.sizes["draw"] == 500 def test_var_name_group(self): idata = load_arviz_data("centered_eight") @@ -1607,5 +1607,5 @@ def test_keep_dataset(self): def test_subset_samples(self): idata = load_arviz_data("centered_eight") post = extract(idata, num_samples=10) - assert post.dims["sample"] == 10 + assert post.sizes["sample"] == 10 assert post.attrs == idata.posterior.attrs diff --git a/arviz/tests/base_tests/test_stats_utils.py b/arviz/tests/base_tests/test_stats_utils.py index 1ca8fa8241..8d30d172ff 100644 --- a/arviz/tests/base_tests/test_stats_utils.py +++ b/arviz/tests/base_tests/test_stats_utils.py @@ -344,9 +344,9 @@ def test_variance_bad_data(): def test_histogram(): school = load_arviz_data("non_centered_eight").posterior["mu"].values - k_count_az, k_dens_az, _ = histogram(school, bins=np.asarray([-np.Inf, 0.5, 0.7, 1, np.Inf])) - k_dens_np, *_ = np.histogram(school, bins=[-np.Inf, 0.5, 0.7, 1, np.Inf], density=True) - k_count_np, *_ = np.histogram(school, bins=[-np.Inf, 0.5, 0.7, 1, np.Inf], density=False) + k_count_az, k_dens_az, _ = histogram(school, bins=np.asarray([-np.inf, 0.5, 0.7, 1, np.inf])) + k_dens_np, *_ = np.histogram(school, bins=[-np.inf, 0.5, 0.7, 1, np.inf], density=True) + k_count_np, *_ = np.histogram(school, bins=[-np.inf, 0.5, 0.7, 1, np.inf], density=False) assert np.allclose(k_count_az, k_count_np) assert np.allclose(k_dens_az, k_dens_np) diff --git a/arviz/tests/external_tests/test_data_numpyro.py b/arviz/tests/external_tests/test_data_numpyro.py index e29954ab06..71b828031b 100644 --- a/arviz/tests/external_tests/test_data_numpyro.py +++ b/arviz/tests/external_tests/test_data_numpyro.py @@ -101,8 +101,8 @@ def test_inference_data(self, data, eight_schools_params, predictions_data, pred assert not fails # test dims - dims = inference_data.posterior_predictive.dims["school"] - pred_dims = inference_data.predictions.dims["school_pred"] + dims = inference_data.posterior_predictive.sizes["school"] + pred_dims = inference_data.predictions.sizes["school_pred"] assert dims == 8 assert pred_dims == 8 @@ -240,7 +240,7 @@ def model_constant_data(x, y1=None): def test_inference_data_num_chains(self, predictions_data, chains): predictions = predictions_data inference_data = from_numpyro(predictions=predictions, num_chains=chains) - nchains = inference_data.predictions.dims["chain"] + nchains = inference_data.predictions.sizes["chain"] assert nchains == chains @pytest.mark.parametrize("nchains", [1, 2]) diff --git a/arviz/tests/external_tests/test_data_pyro.py b/arviz/tests/external_tests/test_data_pyro.py index a26dceed60..73b3c1c05c 100644 --- a/arviz/tests/external_tests/test_data_pyro.py +++ b/arviz/tests/external_tests/test_data_pyro.py @@ -83,8 +83,8 @@ def test_inference_data(self, data, eight_schools_params, predictions_data): assert not fails # test dims - dims = inference_data.posterior_predictive.dims["school"] - pred_dims = inference_data.predictions.dims["school_pred"] + dims = inference_data.posterior_predictive.sizes["school"] + pred_dims = inference_data.predictions.sizes["school_pred"] assert dims == 8 assert pred_dims == 8 @@ -225,7 +225,7 @@ def model_constant_data(x, y1=None): def test_inference_data_num_chains(self, predictions_data, chains): predictions = predictions_data inference_data = from_pyro(predictions=predictions, num_chains=chains) - nchains = inference_data.predictions.dims["chain"] + nchains = inference_data.predictions.sizes["chain"] assert nchains == chains @pytest.mark.parametrize("log_likelihood", [True, False]) diff --git a/examples/matplotlib/mpl_styles.py b/examples/matplotlib/mpl_styles.py index 8119235990..0be19a4cd4 100644 --- a/examples/matplotlib/mpl_styles.py +++ b/examples/matplotlib/mpl_styles.py @@ -34,7 +34,7 @@ "arviz-docgrid", ] -fig = plt.figure(figsize=(20, 10)) +fig = plt.figure(figsize=(20, 10), layout="constrained") for idx, style in enumerate(style_list): with az.style.context(style, after_reset=True): ax = fig.add_subplot(5, 4, idx + 1, label=idx) @@ -45,6 +45,4 @@ ax.set_ylabel("f(x)", rotation=0, labelpad=15) ax.set_xticklabels([]) -plt.tight_layout() - plt.show() diff --git a/requirements-docs.txt b/requirements-docs.txt index e9d3ae634e..43ed21e27b 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -9,7 +9,7 @@ myst-parser myst-nb sphinx-notfound-page sphinx-copybutton -bokeh +bokeh<3 contourpy sphinx_design sphinx-codeautolink>=0.9.0 diff --git a/setup.py b/setup.py index cc3a1d99ae..e5f17cc37b 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def get_version(): long_description=get_long_description(), long_description_content_type="text/markdown", include_package_data=True, - python_requires=">=3.9", + python_requires=">=3.10", classifiers=[ "Development Status :: 4 - Beta", "Framework :: Matplotlib", @@ -67,9 +67,9 @@ def get_version(): "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Visualization", "Topic :: Scientific/Engineering :: Mathematics", From be9d320bc4438a8ea4f2e81273c04a0a8f49da2b Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 21 Feb 2024 22:47:05 +0100 Subject: [PATCH 2/7] update changelog and check linters --- CHANGELOG.md | 1 + arviz/plots/backends/bokeh/bpvplot.py | 7 ++++++- arviz/plots/backends/bokeh/compareplot.py | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8092beb43f..30e33851ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### New features ### Maintenance and fixes +- Fix deprecations introduced in latest pandas and xarray versions, and prepare for numpy 2.0 ones ([2315](https://github.com/arviz-devs/arviz/pull/2315))) ### Deprecation diff --git a/arviz/plots/backends/bokeh/bpvplot.py b/arviz/plots/backends/bokeh/bpvplot.py index 55999799ea..5c57cf7c71 100644 --- a/arviz/plots/backends/bokeh/bpvplot.py +++ b/arviz/plots/backends/bokeh/bpvplot.py @@ -172,7 +172,12 @@ def plot_bpv( if plot_mean: ax_i.scatter( - obs_vals.mean(), 0, fill_color=color, line_color="black", size=markersize, marker="circle" + obs_vals.mean(), + 0, + fill_color=color, + line_color="black", + size=markersize, + marker="circle", ) _title = Title() diff --git a/arviz/plots/backends/bokeh/compareplot.py b/arviz/plots/backends/bokeh/compareplot.py index 98b8e22934..3b5c4ea393 100644 --- a/arviz/plots/backends/bokeh/compareplot.py +++ b/arviz/plots/backends/bokeh/compareplot.py @@ -93,7 +93,7 @@ def plot_compare( fill_color=None, line_width=2, size=6, - marker="circle" + marker="circle", ) elpd_label = [elpd_circ] @@ -129,7 +129,7 @@ def plot_compare( fill_color=plot_kwargs.get("color_insample_dev", "black"), line_width=2, size=6, - marker="circle" + marker="circle", ) labels.append(("In-sample ELPD", [insample_circ])) From 1e75ef80e50e1c69e36f3adfcc5020781e46ef84 Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 21 Feb 2024 22:56:49 +0100 Subject: [PATCH 3/7] keep everything bokeh2 --- arviz/plots/backends/bokeh/pairplot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arviz/plots/backends/bokeh/pairplot.py b/arviz/plots/backends/bokeh/pairplot.py index 61dba8b839..cc801c1a4d 100644 --- a/arviz/plots/backends/bokeh/pairplot.py +++ b/arviz/plots/backends/bokeh/pairplot.py @@ -173,8 +173,14 @@ def plot_pair( source = ColumnDataSource(data=source_dict) if divergences: - source_nondiv = CDSView(filter=GroupFilter(column_name=divergenve_name, group="0")) - source_div = CDSView(filter=GroupFilter(column_name=divergenve_name, group="1")) + source_nondiv = CDSView( + source=source, + filters=[GroupFilter(column_name=divergenve_name, group="0")] + ) + source_div = CDSView( + source=source, + filters=[GroupFilter(column_name=divergenve_name, group="1")] + ) def get_width_and_height(jointplot, rotate): """Compute subplots dimensions for two or more variables.""" From 726a7788dc593bb7c39262791dc8b5d7739be086 Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 21 Feb 2024 23:29:43 +0100 Subject: [PATCH 4/7] fix squeeze behaviour --- arviz/plots/backends/bokeh/forestplot.py | 2 +- arviz/plots/backends/matplotlib/forestplot.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arviz/plots/backends/bokeh/forestplot.py b/arviz/plots/backends/bokeh/forestplot.py index dd078e25bf..9406641fbe 100644 --- a/arviz/plots/backends/bokeh/forestplot.py +++ b/arviz/plots/backends/bokeh/forestplot.py @@ -648,7 +648,7 @@ def iterator(self): for name, grouped_datum in zip(self.model_names, grouped_data): for _, sub_data in grouped_datum: datum_iter = xarray_var_iter( - sub_data, + sub_data.squeeze(), var_names=[self.var_name], skip_dims=skip_dims, reverse_selections=True, diff --git a/arviz/plots/backends/matplotlib/forestplot.py b/arviz/plots/backends/matplotlib/forestplot.py index 9e6e9a0edc..67b710bf48 100644 --- a/arviz/plots/backends/matplotlib/forestplot.py +++ b/arviz/plots/backends/matplotlib/forestplot.py @@ -544,7 +544,7 @@ def iterator(self): for name, grouped_datum in zip(self.model_names, grouped_data): for _, sub_data in grouped_datum: datum_iter = xarray_var_iter( - sub_data, + sub_data.squeeze(), var_names=[self.var_name], skip_dims=skip_dims, reverse_selections=True, From 414805c9c3eaf167a0cac9aab3727a4b66f026b6 Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 21 Feb 2024 23:30:01 +0100 Subject: [PATCH 5/7] black --- arviz/plots/backends/bokeh/pairplot.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arviz/plots/backends/bokeh/pairplot.py b/arviz/plots/backends/bokeh/pairplot.py index cc801c1a4d..5701140925 100644 --- a/arviz/plots/backends/bokeh/pairplot.py +++ b/arviz/plots/backends/bokeh/pairplot.py @@ -174,12 +174,10 @@ def plot_pair( if divergences: source_nondiv = CDSView( - source=source, - filters=[GroupFilter(column_name=divergenve_name, group="0")] + source=source, filters=[GroupFilter(column_name=divergenve_name, group="0")] ) source_div = CDSView( - source=source, - filters=[GroupFilter(column_name=divergenve_name, group="1")] + source=source, filters=[GroupFilter(column_name=divergenve_name, group="1")] ) def get_width_and_height(jointplot, rotate): From eae8529355fe32fcd0718384d7176016b1c7e1da Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Thu, 22 Feb 2024 18:57:36 +0100 Subject: [PATCH 6/7] add unconstrained groups to list of recognized groups --- arviz/data/inference_data.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arviz/data/inference_data.py b/arviz/data/inference_data.py index e3b8274ecf..cc95b4ca93 100644 --- a/arviz/data/inference_data.py +++ b/arviz/data/inference_data.py @@ -63,6 +63,8 @@ "observed_data", "constant_data", "predictions_constant_data", + "unconstrained_posterior", + "unconstrained_prior", ] WARMUP_TAG = "warmup_" From 6564adc04599ed644271910d189e685ee42c3b50 Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Thu, 22 Feb 2024 18:59:10 +0100 Subject: [PATCH 7/7] attempt fixing benchmarks --- .azure-pipelines/azure-pipelines-benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure-pipelines/azure-pipelines-benchmarks.yml b/.azure-pipelines/azure-pipelines-benchmarks.yml index 126ac3be6e..412b926f84 100644 --- a/.azure-pipelines/azure-pipelines-benchmarks.yml +++ b/.azure-pipelines/azure-pipelines-benchmarks.yml @@ -29,7 +29,7 @@ jobs: python -m pip install wheel python -m pip install --no-cache-dir -r requirements.txt python -m pip install --no-cache-dir -r requirements-optional.txt - python -m pip install asv + python -m pip install asv!=0.6.2 displayName: 'Install requirements' - script: |