If you have ever fitted a Bayesian model with PyMC, NumPyro or Stan, you have almost certainly leaned on ArviZ to compute R-hat, effective sample size, LOO or a trace plot. And if you manage environments for a research group, you have also felt the other side of that relationship: a plotting library that drags in a GUI toolkit, a diagnostics upgrade that silently changes a number in your paper, and the dreaded import error after a routine pip install. Tools in the Bayesian stack tend to sit right in the middle of the dependency graph, where every conflict is personal.

So when ArviZ — a NumFOCUS community project, cited via a 2026 JOSS paper as “a modular and flexible library for exploratory analysis of Bayesian models” — announced its 1.x refactor, it deserved more than a changelog skim. The old single-library layout is gone. Today the arviz package on PyPI is something unusual: a metapackage whose entire shipping source is one Python file, src/arviz/__init__.py, exactly 128 lines long. The real machinery — data structures in arviz_base, diagnostics in arviz_stats, visualization in arviz_plots — lives in sibling “ArviZverse” packages that this one stitches together.

That stitching is where the interesting engineering went. The file choreographs three wildcard imports, builds a human-readable status string, enforces a strict minor-version lockstep across independent packages, and uses a PEP 562 module __getattr__ to catch every legacy arviz.InferenceData access with a warning that links to a migration guide. We cloned the repo’s main branch, read every line of that file, its test suite, its CI workflows and its docs redirects, and mapped the whole assembly in the two diagrams below.

ArviZ overview architecture: namespace shim, ArviZverse packages, storage aliases, legacy bridge, tests and release flow

Overview of the arviz metapackage: one shim file assembling three ArviZverse libraries, with the version guard, storage aliases, docs redirects and release automation around them.

Reading the overview from left to right, these are the anchors worth opening in the source:

  • from_netcdf, L21 — the old NetCDF reader is now a straight alias: from xarray import open_datatree as from_netcdf.
  • from_zarr, L23 — one line of functools.partial(from_netcdf, engine="zarr") keeps the Zarr entry point alive.
  • from arviz_base import *, L35 — the first of three wildcard imports, each wrapped in its own try block.
  • __version__, L87 — set deliberately last, with a comment explaining it must not be overwritten by imported libraries.
  • pat, L91 — the regex arviz_(base|stats|plots)\s([0-9]+\.[0-9]+) that scans the status string for minor versions.
  • raise ImportError, L105 — where a mixed-version install dies loudly, with a sorted bullet list of offenders.
  • MigrationWarning, L30 — dual-inherits UserWarning, FutureWarning so legacy access is visible now and flagged as scheduled breakage.
  • __getattr__, L110 — the PEP 562 hook that intercepts arviz.InferenceData and returns xarray’s DataTree itself.
  • test_aliases, L36 — the test that walks the whole public namespace and asserts every object comes from an arviz_* module, never from arviz itself.

The detail view goes one level deeper, into the guard clauses, the lockstep tests and the release automation.

ArviZ detail architecture: import guards, version lockstep, storage aliases, legacy bridge, docs migration and CI release

Detail view: namespace assembly and import guards, version lockstep with reload tests, storage alias identities, the InferenceData bridge and its 164 doc redirects, plus CI and publishing.

A package that is one file on purpose

The docstring at line 15 states the contract plainly: “Expose features from ArviZverse refactored packages together in the arviz namespace.” Everything after it is assembly. Three try blocks wildcard-import arviz_base, arviz_stats and arviz_plots; after each one, an import arviz_base as base grabs the module only to read its __version__, compose a status line, and then del base so the alias never leaks into the public namespace. The strings accumulate into a single info variable, which becomes arviz.info — a diagnostic surface users can print to see exactly which ArviZverse versions are live. Line 89 wraps it with Status information for ArviZ 1.3.0, and line 128 cleans house with a del of every helper: functools, logging, matches, pat, re, and the rest. Even the module’s own version is defensive: the comment at line 86 says “define version last so it isn’t overwritten by the respective attribute in the imported libraries.”

The packaging mirrors this minimalism. pyproject.toml declares flit_core >=3.4,<4 as the build backend — no setup.py at all — and its dependency list is just three packages, each pinned to the same minor window: arviz_base>=1.3.0,<1.4.0, arviz_stats[xarray]>=1.3.0,<1.4.0, arviz_plots>=1.3.0,<1.4.0. The optional-dependency blocks are pure forwarding: netcdf4 = ["arviz_base[netcdf4]"], zarr = ["arviz_base[zarr]"], and the visualization stacks matplotlib, bokeh and plotly all point at arviz_plots extras. That last one matters if you render figures for the web: the bokeh extra wires in the interactive browser backend (bokeh), while plotly hands the same specifications to another rendering stack (plotly). The metapackage owns none of these libraries; it only routes to them.

The import contract: friendly errors without masking

Missing-dependency handling is usually where metapackages get sloppy, and this file refuses the two classic mistakes. Mistake one: swallowing the real error. Each except ModuleNotFoundError checks err.name — only if the missing module is the ArviZverse package itself does it raise the friendly ImportError("arviz's dependency arviz_base is not installed", name="arviz"); otherwise a bare raise re-throws untouched, so a missing transitive dependency of arviz_stats propagates with its true name. Mistake two: masking with except Exception. The guards are precise.

The test suite holds this line with unusual rigor. test_transitive_import_error_not_masked monkeypatches builtins.__import__ so that importing, say, arviz_plots raises ModuleNotFoundError for a fake module called some_transitive_dep, reloads arviz, and asserts the error’s name attribute equals "some_transitive_dep" — and that the friendly message did not appear. test_missing_subpackage_raises_import_error runs the opposite check: when the subpackage itself is missing, the ImportError must carry the original ModuleNotFoundError as its __cause__. Both are parametrized over the SUBPACKAGES = ["arviz_base", "arviz_stats", "arviz_plots"] list at line 105 of the test file. This is the kind of test most projects write for their parser, not their imports.

Version lockstep, enforced at import time

Because three independently-released packages are mashed into one namespace, a mixed install — arviz_stats from an older release next to a fresh arviz_plots — is the likeliest failure mode for users. The guard at lines 91-105 turns that failure into a loud, actionable crash at import time. It scans the assembled info string with the compiled regex, builds a versions dict mapping each package to its minor version, and if the set of unique minors has more than one element, it constructs a message listing every offender in sorted order — lines.append(f"- arviz_{package}: {version}") — before raise ImportError("\n".join(lines)). The error literally tells you which package to upgrade.

The tests treat this as a first-class behavior. test_incompatible_package_versions monkeypatches the three __version__ attributes to 0.7.0, 0.6.0 and 0.7.0, calls importlib.reload(az), and asserts the raised message contains - arviz_stats: 0.6 and “must share the same minor version”. The mirror case, test_compatible_package_versions, loads a same-minor trio 0.7.0/0.7.1/0.7.2 and asserts the reload succeeds and arviz.info reports each exact version. There is one charming fossil here too: line 55 carries a TODO: remove patch. 0.7 version of arviz-stats didn't expose the __version__ attribute, with getattr(stats, "__version__", "0.7.0") as the workaround. The whole CI matrix runs with warnings as errors — filterwarnings = ["error"] in pyproject.toml — so even a stray DeprecationWarning fails the run under pytest, and pytest.ini adds --strict -rsf --durations=20 -p no:warnings on top.

From InferenceData to DataTree: migration without a cliff

The rename that hits every 0.x user is InferenceData, the beloved container with its posterior, sample_stats and observed_data groups and its NetCDF and Zarr round-trips. In 1.x that role belongs to xarray’s DataTree, and the shim makes the transition almost impossible to miss. Accessing arviz.InferenceData triggers the module-level __getattr__, which emits a MigrationWarning carrying the constant at line 107 — a deep link into the online migration guide — and then returns DataTree itself, not a wrapper. Two tests pin the behavior: one imports from arviz import InferenceData inside pytest.warns, another accesses the attribute, and both assert InferenceData is DataTree, so the warning fires while the object still works.

The docs side repeats the same kindness at URL level. The repository ships 164 redirect pages under docs/source/redirects/ — minimal HTML files with a meta http-equiv="refresh" plus a rel="canonical" link pointing at the new subpackage docs; the page for arviz.rhat, for instance, forwards to the arviz_stats.rhat page in the stats project docs, titled “Redirecting to ArviZverse submodule docs”. Forty-eight of those 164 pages are arviz.InferenceData.* methods — every old doc URL for to_netcdf, sel, isel and friends resolves instead of 404ing. The changelog marks the era boundary precisely: its final 0.x entry is v0.23.0 dated 2025 Des 9, whose notes already mention “idata-datatree conversions”, and the README’s quick links section sends 0.x users straight to the migration guide.

From monolith to metapackage: the build facts

The numbers tell the refactor story. The tracked tree holds 260 files, and exactly one of them is shipping Python. That file is 128 lines with 37 comment-or-blank lines and a pylint suppression banner at line 14 (unused-import, unused-wildcard-import, invalid-name) that legalizes its import tricks. Around it: 164 redirect HTML pages, an 11-function test file that expands to 15 cases under parametrization, two GitHub Actions workflows, and a docs tree. Python floor is 3.12 (requires-python = ">=3.12"), and CI exercises 3.12, 3.13 and 3.14 with fail-fast: false. Supply-chain discipline is explicit: the test workflow bootstraps pip 26.2.2 from a SHA-256-pinned wheel with --require-hashes, installs dependencies the same way, then verifies the pinned pip inside each tox environment before running SKIP=no-commit-to-branch tox. Style is enforced by ruff 0.11.13 plus ruff-format via pre-commit, alongside a no-print-statements hook, a no-commit-to-branch guard on main, and a license-insertion hook that stamps the Apache header onto every file matching ^(src|tests)/.*\.py$. Releases use flit-built packages, GitHub build-provenance attestations, and OpenID Connect trusted publishing to PyPI on v* tags — gated behind a protected publish environment, with persist-credentials: false on checkout.

Honest Limits

Read this repo for what it is — a namespace, not the library. The R-hat, ESS, PSIS and plotting code you may be looking for moved to the arviz_stats and arviz_plots repositories, so a diagnostics source dive must continue there. The lockstep guard also has boundaries: it runs once, at import, parsing the info string rather than installed distribution metadata, so upgrading one subpackage in a live interpreter without reloading arviz escapes the check. Wildcard imports delegate namespace hygiene to the subpackages’ __all__ definitions — the metapackage cannot enforce that itself, only test it after the fact. The legacy bridge covers exactly one name: plot_trace, rhat and friends are gone from the top-level namespace, with doc redirects as the only soft landing, so old code needs real edits, not just tolerance of warnings. And one doc bug remains: the README still suggests python setup.py install for a development install, though the project builds with flit and ships no setup.py. Small, honest cracks — worth knowing before you build on a metapackage whose entire promise is that three projects move as one.

Watch PyShine on YouTube

Contents