class_docstr: Encapsulate InferenceData specific logic.
docstr: Extract sample_stats from PyMC trace.
docstr_tok: ["Extract","sample_stats","from","PyMC","trace","."]
code: def sample_stats_to_xarray(self):
      """Extract sample_stats from PyMC trace."""
      data = {}
      rename_key = {
          "model_logp": "lp",
          "mean_tree_accept": "acceptance_rate",
          "depth": "tree_depth",
          "tree_size": "n_steps",
      }
      data = {}
      data_warmup = {}
      for stat in self.trace.stat_names:
          name = rename_key.get(stat, stat)
          if name == "tune":
              continue
          if self.warmup_trace:
              data_warmup[name] = np.array(
                  self.warmup_trace.get_sampler_stats(
                      stat, combine=False, squeeze=False
                  )
              )
          if self.posterior_trace:
              data[name] = np.array(
                  self.posterior_trace.get_sampler_stats(
                      stat, combine=False, squeeze=False
                  )
              )
  
      return (
          dict_to_dataset(
              data,
              library=pymc,
              dims=None,
              coords=self.coords,
              attrs=self.attrs,
          ),
          dict_to_dataset(
              data_warmup,
              library=pymc,
              dims=None,
              coords=self.coords,
              attrs=self.attrs,
          ),
      )
  
imports: import logging
  import warnings
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
  import numpy
  from arviz import InferenceData, concat, rcParams
  from arviz.data.base import CoordSpec, DimSpec, dict_to_dataset, requires
  from pytensor.graph.basic import Constant
  from pytensor.tensor.sharedvar import SharedVariable
  import pymc
  from pymc.model import Model, modelcontext
  from pymc.pytensorf import extract_obs_data
  from pymc.util import get_default_varnames
label_desc: Use image node_id 4 for calling the InferenceDataConverter obj's underlying member method code with example usage: obj.sample_stats_to_xarray() and returns: dict_to_dataset,  dict_to_dataset