{"id":8839,"library":"arviz-base","title":"ArviZ Base","description":"arviz-base is a Python package that provides core ArviZ features and converters, serving as a fundamental component of the modular ArviZ 1.0 ecosystem. It focuses on data structures, primarily leveraging `xarray.DataTree`, and conversion utilities from various probabilistic programming languages (PPLs). This library, currently at version 1.0.0, is under active development as part of the broader ArviZ refactoring, aiming for increased flexibility and a minimal dependency footprint.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/arviz-devs/arviz-base","tags":["bayesian","statistical-modeling","data-analysis","xarray","inference","probabilistic-programming"],"install":[{"cmd":"pip install arviz-base","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core data structure (DataTree) and data manipulation.","package":"xarray","optional":false},{"reason":"Fundamental numerical computing.","package":"numpy","optional":false},{"reason":"Type hinting support.","package":"typing-extensions","optional":false},{"reason":"Optional I/O backend for NetCDF files.","package":"netcdf4","optional":true},{"reason":"Optional I/O backend for HDF5-backed NetCDF files.","package":"h5netcdf","optional":true},{"reason":"Optional I/O backend for Zarr arrays.","package":"zarr","optional":true}],"imports":[{"note":"arviz-base uses its own namespace; the old `arviz.InferenceData` has been replaced by `xarray.DataTree` in 1.0.","wrong":"import arviz as az_old; az_old.InferenceData()","symbol":"arviz_base","correct":"import arviz_base as az"},{"note":"Used for loading pre-packaged ArviZ example datasets.","symbol":"load_arviz_data","correct":"from arviz_base import load_arviz_data"},{"note":"Used for converting Python dictionaries to `xarray.DataTree` following ArviZ conventions.","symbol":"from_dict","correct":"from arviz_base import from_dict"}],"quickstart":{"code":"import arviz_base as az\nimport numpy as np\n\n# Load an example dataset provided by ArviZ Base\nidata = az.load_arviz_data(\"centered_eight\")\nprint(f\"Loaded DataTree with groups: {list(idata.keys())}\")\n\n# Extract a specific group, e.g., 'posterior', combining chain and draw dimensions\nextracted_data = az.extract(idata, group=\"posterior\")\nprint(f\"\\nExtracted posterior data shape: {extracted_data.sizes}\")\n\n# Convert a simple dictionary to a DataTree\nmy_data = {\n    \"posterior\": {\n        \"alpha\": np.random.normal(0, 1, size=(4, 500)),\n        \"beta\": np.random.normal(0, 0.5, size=(4, 500))\n    }\n}\ncustom_idata = az.from_dict(my_data)\nprint(f\"\\nCustom DataTree with groups: {list(custom_idata.keys())}\")","lang":"python","description":"This quickstart demonstrates loading an example dataset using `load_arviz_data` and then extracting data with `extract`. It also shows how to convert raw Python dictionaries containing NumPy arrays into an ArviZ-compatible `xarray.DataTree` using `from_dict`."},"warnings":[{"fix":"Migrate your data handling to use `xarray.DataTree` structures and `arviz_base`'s new conversion and extraction functions. Consult the ArviZ migration guide.","message":"ArviZ 1.0, of which arviz-base is a part, introduces a major refactoring. The central `arviz.InferenceData` object has been replaced by `xarray.DataTree`. Code relying on `InferenceData` attributes or methods will break.","severity":"breaking","affected_versions":"0.x to 1.0.0+"},{"fix":"If you require statistical summaries or visualizations, install `arviz-stats` (`pip install arviz-stats`) and `arviz-plots` (`pip install arviz-plots`), or install `arviz` with relevant I/O and plotting extras (e.g., `pip install \"arviz[netcdf4,matplotlib]\"`).","message":"arviz-base is a minimal package focused on data structures and converters. For statistical computations or plotting, you will need `arviz-stats` and `arviz-plots` respectively, or install the overarching `arviz` package with necessary extras.","severity":"gotcha","affected_versions":"1.0.0+"},{"fix":"Install the specific I/O backend you need separately, e.g., `pip install netcdf4` or `pip install zarr`. When installing `arviz` (the meta-package), these can be specified as extras, e.g., `pip install \"arviz[netcdf4]\"`.","message":"I/O functionalities for formats like NetCDF, HDF5, or Zarr are provided via optional dependencies. `arviz-base` itself does not have these as hard requirements to maintain a minimal footprint.","severity":"gotcha","affected_versions":"1.0.0+"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install xarray: `pip install xarray` or `pip install \"arviz-base\"` (which should pull `xarray` as a dependency).","cause":"The core dependency `xarray` is not installed, which is essential for `arviz-base`'s data structures like `DataTree`.","error":"ModuleNotFoundError: No module named 'xarray'"},{"fix":"Update your code to use `xarray.DataTree` or `arviz_base`'s conversion functions like `from_dict` or `from_cmdstanpy` to create `DataTree` objects. Refer to the ArviZ migration guide for detailed steps.","cause":"Attempting to use the deprecated `arviz.InferenceData` object directly with an ArviZ 1.0+ installation (or `arviz-base`). The `InferenceData` object has been replaced by `xarray.DataTree`.","error":"AttributeError: module 'arviz' has no attribute 'InferenceData'"},{"fix":"Ensure that the input arrays have consistent shapes and the correct number of dimensions corresponding to the `chain`, `draw`, and variable-specific dimensions expected by ArviZ. For instance, posterior samples usually require `(chain, draw, *variable_dimensions)`.","cause":"This error typically occurs when the input data (e.g., NumPy arrays or dictionaries) provided to conversion functions like `from_dict` or other ArviZ functions do not conform to the expected dimensionality or shape for creating a `DataTree` group.","error":"ValueError: setting an array element with a sequence. The above exception was the direct cause of the following exception: ValueError: could not broadcast input array from shape (X,Y) into shape (Z,)"}]}