class_docstr: Container for inference data storage using xarray.
  
  For a detailed introduction to ``InferenceData`` objects and their usage, see
  :ref:`xarray_for_arviz`. This page provides help and documentation
  on ``InferenceData`` methods and their low level implementation.
class_docstr_tok: ["Container","for","inference","data","storage","using","xarray",".","For","a","detailed","introduction","to","``","InferenceData","``","objects","and","their","usage",",","see",":","ref",":","`","xarray_for_arviz","`",".","This","page","provides","help","and","documentation","on","``","InferenceData","``","methods","and","their","low","level","implementation","."]
docstr: Perform an xarray stacking on all groups.
  
  Stack any number of existing dimensions into a single new dimension.
  Loops groups to perform Dataset.stack(key=value)
  for every kwarg if value is a dimension of the dataset.
  The selection is performed on all relevant groups (like
  posterior, prior, sample stats) while non relevant groups like observed data are
  omitted. See :meth:`xarray:xarray.Dataset.stack`
  
  Parameters
  ----------
  dimensions : dict, optional
      Names of new dimensions, and the existing dimensions that they replace.
  groups: str or list of str, optional
      Groups where the selection is to be applied. Can either be group names
      or metagroup names.
  filter_groups : {None, "like", "regex"}, optional
      If `None` (default), interpret groups as the real group or metagroup names.
      If "like", interpret groups as substrings of the real group or metagroup names.
      If "regex", interpret groups as regular expressions on the real group or
      metagroup names. A la `pandas.filter`.
  inplace : bool, optional
      If ``True``, modify the InferenceData object inplace,
      otherwise, return the modified copy.
  kwargs : dict, optional
      It must be accepted by :meth:`xarray:xarray.Dataset.stack`.
  
  Returns
  -------
  InferenceData
      A new InferenceData object by default.
      When `inplace==True` perform selection in-place and return `None`
  
  Examples
  --------
  Use ``stack`` to stack any number of existing dimensions into a single new dimension.
  We first check the original object:
  
  .. jupyter-execute::
  
      import arviz as az
      idata = az.load_arviz_data("rugby")
      idata
  
  In order to stack two dimensions ``chain`` and ``draw`` to ``sample``, we can use:
  
  .. jupyter-execute::
  
      idata.stack(sample=["chain", "draw"], inplace=True)
      idata
  
  We can also take the example of custom InferenceData object and perform stacking. We first
  check the original object:
  
  .. jupyter-execute::
  
      import numpy as np
      datadict = {
          "a": np.random.randn(100),
          "b": np.random.randn(1, 100, 10),
          "c": np.random.randn(1, 100, 3, 4),
      }
      coords = {
          "c1": np.arange(3),
          "c99": np.arange(4),
          "b1": np.arange(10),
      }
      dims = {"c": ["c1", "c99"], "b": ["b1"]}
      idata = az.from_dict(
          posterior=datadict, posterior_predictive=datadict, coords=coords, dims=dims
      )
      idata
  
  In order to stack two dimensions ``c1`` and ``c99`` to ``z``, we can use:
  
  .. jupyter-execute::
  
      idata.stack(z=["c1", "c99"], inplace=True)
      idata
  
  See Also
  --------
  xarray.Dataset.stack : Stack any number of existing dimensions into a single new dimension.
  unstack : Perform an xarray unstacking on all groups of InferenceData object.
docstr_tok: ["Perform","an","xarray","stacking","on","all","groups",".","Stack","any","number","of","existing","dimensions","into","a","single","new","dimension",".","Loops","groups","to","perform","Dataset.stack","(","key=value",")","for","every","kwarg","if","value","is","a","dimension","of","the","dataset",".","The","selection","is","performed","on","all","relevant","groups","(","like","posterior",",","prior",",","sample","stats",")","while","non","relevant","groups","like","observed","data","are","omitted",".","See",":","meth",":","`","xarray",":","xarray.Dataset.stack","`","Parameters","--","--","--","--","--","dimensions",":","dict",",","optional","Names","of","new","dimensions",",","and","the","existing","dimensions","that","they","replace",".","groups",":","str","or","list","of","str",",","optional","Groups","where","the","selection","is","to","be","applied",".","Can","either","be","group","names","or","metagroup","names",".","filter_groups",":","{","None",",","``","like","''",",","``","regex","''","}",",","optional","If","`","None","`","(","default",")",",","interpret","groups","as","the","real","group","or","metagroup","names",".","If","``","like","''",",","interpret","groups","as","substrings","of","the","real","group","or","metagroup","names",".","If","``","regex","''",",","interpret","groups","as","regular","expressions","on","the","real","group","or","metagroup","names",".","A","la","`","pandas.filter","`",".","inplace",":","bool",",","optional","If","``","True","``",",","modify","the","InferenceData","object","inplace",",","otherwise",",","return","the","modified","copy",".","kwargs",":","dict",",","optional","It","must","be","accepted","by",":","meth",":","`","xarray",":","xarray.Dataset.stack","`",".","Returns","--","--","--","-","InferenceData","A","new","InferenceData","object","by","default",".","When","`","inplace==True","`","perform","selection","in-place","and","return","`","None","`","Examples","--","--","--","--","Use","``","stack","``","to","stack","any","number","of","existing","dimensions","into","a","single","new","dimension",".","We","first","check","the","original","object",":","..","jupyter-execute",":",":","import","arviz","as","az","idata","=","az.load_arviz_data","(","``","rugby","''",")","idata","In","order","to","stack","two","dimensions","``","chain","``","and","``","draw","``","to","``","sample","``",",","we","can","use",":","..","jupyter-execute",":",":","idata.stack","(","sample=","[","``","chain","''",",","``","draw","''","]",",","inplace=True",")","idata","We","can","also","take","the","example","of","custom","InferenceData","object","and","perform","stacking",".","We","first","check","the","original","object",":","..","jupyter-execute",":",":","import","numpy","as","np","datadict","=","{","``","a","''",":","np.random.randn","(","100",")",",","``","b","''",":","np.random.randn","(","1",",","100",",","10",")",",","``","c","''",":","np.random.randn","(","1",",","100",",","3",",","4",")",",","}","coords","=","{","``","c1","''",":","np.arange","(","3",")",",","``","c99","''",":","np.arange","(","4",")",",","``","b1","''",":","np.arange","(","10",")",",","}","dims","=","{","``","c","''",":","[","``","c1","''",",","``","c99","''","]",",","``","b","''",":","[","``","b1","''","]","}","idata","=","az.from_dict","(","posterior=datadict",",","posterior_predictive=datadict",",","coords=coords",",","dims=dims",")","idata","In","order","to","stack","two","dimensions","``","c1","``","and","``","c99","``","to","``","z","``",",","we","can","use",":","..","jupyter-execute",":",":","idata.stack","(","z=","[","``","c1","''",",","``","c99","''","]",",","inplace=True",")","idata","See","Also","--","--","--","--","xarray.Dataset.stack",":","Stack","any","number","of","existing","dimensions","into","a","single","new","dimension",".","unstack",":","Perform","an","xarray","unstacking","on","all","groups","of","InferenceData","object","."]
code: def stack(
      self,
      dimensions=None,
      groups=None,
      filter_groups=None,
      inplace=False,
      **kwargs,
  ):
      """Perform an xarray stacking on all groups.
  
      Stack any number of existing dimensions into a single new dimension.
      Loops groups to perform Dataset.stack(key=value)
      for every kwarg if value is a dimension of the dataset.
      The selection is performed on all relevant groups (like
      posterior, prior, sample stats) while non relevant groups like observed data are
      omitted. See :meth:`xarray:xarray.Dataset.stack`
  
      Parameters
      ----------
      dimensions : dict, optional
          Names of new dimensions, and the existing dimensions that they replace.
      groups: str or list of str, optional
          Groups where the selection is to be applied. Can either be group names
          or metagroup names.
      filter_groups : {None, "like", "regex"}, optional
          If `None` (default), interpret groups as the real group or metagroup names.
          If "like", interpret groups as substrings of the real group or metagroup names.
          If "regex", interpret groups as regular expressions on the real group or
          metagroup names. A la `pandas.filter`.
      inplace : bool, optional
          If ``True``, modify the InferenceData object inplace,
          otherwise, return the modified copy.
      kwargs : dict, optional
          It must be accepted by :meth:`xarray:xarray.Dataset.stack`.
  
      Returns
      -------
      InferenceData
          A new InferenceData object by default.
          When `inplace==True` perform selection in-place and return `None`
  
      Examples
      --------
      Use ``stack`` to stack any number of existing dimensions into a single new dimension.
      We first check the original object:
  
      .. jupyter-execute::
  
          import arviz as az
          idata = az.load_arviz_data("rugby")
          idata
  
      In order to stack two dimensions ``chain`` and ``draw`` to ``sample``, we can use:
  
      .. jupyter-execute::
  
          idata.stack(sample=["chain", "draw"], inplace=True)
          idata
  
      We can also take the example of custom InferenceData object and perform stacking. We first
      check the original object:
  
      .. jupyter-execute::
  
          import numpy as np
          datadict = {
              "a": np.random.randn(100),
              "b": np.random.randn(1, 100, 10),
              "c": np.random.randn(1, 100, 3, 4),
          }
          coords = {
              "c1": np.arange(3),
              "c99": np.arange(4),
              "b1": np.arange(10),
          }
          dims = {"c": ["c1", "c99"], "b": ["b1"]}
          idata = az.from_dict(
              posterior=datadict, posterior_predictive=datadict, coords=coords, dims=dims
          )
          idata
  
      In order to stack two dimensions ``c1`` and ``c99`` to ``z``, we can use:
  
      .. jupyter-execute::
  
          idata.stack(z=["c1", "c99"], inplace=True)
          idata
  
      See Also
      --------
      xarray.Dataset.stack : Stack any number of existing dimensions into a single new dimension.
      unstack : Perform an xarray unstacking on all groups of InferenceData object.
      """
      groups = self._group_names(groups, filter_groups)
  
      dimensions = {} if dimensions is None else dimensions
      dimensions.update(kwargs)
      out = self if inplace else deepcopy(self)
      for group in groups:
          dataset = getattr(self, group)
          kwarg_dict = {}
          for key, value in dimensions.items():
              try:
                  if not set(value).difference(dataset.dims):
                      kwarg_dict[key] = value
              except TypeError:
                  kwarg_dict[key] = value
          dataset = dataset.stack(**kwarg_dict)
          setattr(out, group, dataset)
      if inplace:
          return None
      else:
          return out
  
imports: import os
  import re
  import sys
  import uuid
  import warnings
  from collections import OrderedDict, defaultdict
  from collections.abc import MutableMapping, Sequence
  from copy import copy
  from copy import deepcopy
  from datetime import datetime
  from html import escape
  from typing import TYPE_CHECKING, Any, Iterable, Iterator, List, Mapping, Optional, Tuple, TypeVar, Union, overload
  import numpy
  import xarray
  from packaging import version
  from ..rcparams import rcParams
  from ..utils import HtmlTemplate, _subset_list, _var_names, either_dict_or_kwargs
  from .base import _extend_xr_method, _make_json_serializable, dict_to_dataset
label_desc: Use image node_id 28 for calling the InferenceData obj's underlying member method code with example usage: obj.stack(dimensions, groups, filter_groups, inplace) and returns: None, out