code: def select_draws(
      idata: InferenceData,
      data: pd.DataFrame,
      condition: dict,
      data_var: str,
      group: str = "posterior",
  ) -> xr.DataArray:
      """Select posterior or posterior predictive draws conditioned on the observation
      that produced that draw by passing a `condition` dictionary.
  
      Parameters
      ----------
      idata : InferenceData
          InferenceData object containing the inference data after performing `model.predict`.
      data : pd.DataFrame
          The Dataframe passed as 'data' to `model.predict` to generate predictions.
      condition : dict
          Dictionary of variable names and values used to select draws.
      data_var : str
          Name of data variable in the 'group' to select draws from.
      group : str, optional
          Whether to select draws from the posterior or posterior predictive group.
          Defaults to 'posterior'.
  
      Returns
      -------
      xr.DataArray
          A DataArray containing the selected draws.
  
      Raises
      ------
      ValueError
          If 'condition' is an empty dictionary.
          If 'group' is not 'posterior' or 'posterior_predictive'.
          If the InferenceData object does not contain a 'group' group.
      """
      if not condition:
          raise ValueError(
              "'condition' cannot be empty an empty dictionary"
          )
  
      if group not in ["posterior", "posterior_predictive"]:
          raise ValueError(
              "'group' must be either 'posterior' or 'posterior_predictive'"
          )
      if group not in idata.groups():
          raise ValueError(
              f"InferenceData object does not contain a '{group}' group."
          )
  
      for key, value in condition.items():
          if isinstance(value, (list, np.ndarray)):
              raise ValueError(
                  f"{key} condition value cannot be an array or list"
              )
  
      idata = idata.copy()
      xr_df = xr.Dataset.from_dataframe(data)
      idata_new = _prepare_idata(idata, xr_df)
      coordinate_name = list(idata_new["data"].coords)[0]
  
      # indices of draws that satisfy condition
      condition_idx = np.where(
          np.logical_and.reduce(
              [
                  idata_new["data"][key] == value
                  for key, value in condition.items()
              ]
          )
      )[0]
      draws = idata_new[group].isel(
          {f"{coordinate_name}": condition_idx}
      )[data_var]
  
      # for main and or parent parameters (e.g., distributional models)
      if coordinate_name in draws.coords:
          new_coords = np.arange(len(condition_idx))
          draws = draws.assign_coords({coordinate_name: new_coords})
  
      return draws
  
file_path: bambi/bambi/interpret/helpers.py
imports: from typing import Union
  import warnings
  import numpy
  import pandas
  import xarray
  from arviz import InferenceData
  from bambi import Model
  from bambi.interpret.create_data import create_grid
  from bambi.interpret.utils import ConditionalInfo, VariableInfo
label_desc: Use image node_id 3 for calling a global function with example usage: select_draws(idata, data, condition, data_var, group) and returns: draws