Repository: arviz-devs/arviz

Issue:
InferenceData.map docstring examples are broken in docs
See https://arviz-devs.github.io/arviz/generated/arviz.InferenceData.map.html#arviz.InferenceData.map

```
In [1]: import arviz as az
   ...: idata = az.load_arviz_data("non_centered_eight")
   ...: idata_shifted_obs = idata.map(lambda x: x + 3, groups="observed_RVs")
   ...: print(idata_shifted_obs.observed_data)
   ...: print(idata_shifted_obs.posterior_predictive)
   ...: 
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/work/1/s/arviz/data/inference_data.py in _group_names(self, groups, filter_groups)
    367         try:
--> 368             group_names = _subset_list(sel_groups, all_groups, filter_items=filter_groups)
    369         except KeyError as err:

~/work/1/s/arviz/utils.py in _subset_list(subset, whole_list, filter_items, warn)
    133         if not np.all(existing_items):
--> 134             raise KeyError("{} are not present".format(np.array(subset)[~existing_items]))
    135 

KeyError: "['observed_RVs'] are not present"

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-1-94d841b8790b> in <module>
      1 import arviz as az
      2 idata = az.load_arviz_data("non_centered_eight")
----> 3 idata_shifted_obs = idata.map(lambda x: x + 3, groups="observed_RVs")
      4 print(idata_shifted_obs.observed_data)
      5 print(idata_shifted_obs.posterior_predictive)

~/work/1/s/arviz/data/inference_data.py in map(self, fun, groups, filter_groups, inplace, args, **kwargs)
    412         if args is None:
    413             args = []
--> 414         groups = self._group_names(groups, filter_groups)
    415 
    416         out = self if inplace else deepcopy(self)

~/work/1/s/arviz/data/inference_data.py in _group_names(self, groups, filter_groups)
    369         except KeyError as err:
    370             msg = " ".join(("groups:", f"{err}", "in InferenceData"))
--> 371             raise KeyError(msg)
    372         return group_names
    373 

KeyError: 'groups: "[\'observed_RVs\'] are not present" in InferenceData'
```


Discussion:
Hi, yeah, there is a typo

    observed_RVs --> observed_data
I'll fix this straight away, thanks! I'll also try to tackle some of the questions in #1252 
Thanks for the quick response!

Resolving patch:
diff --git a/arviz/data/inference_data.py b/arviz/data/inference_data.py
--- a/arviz/data/inference_data.py
+++ b/arviz/data/inference_data.py
@@ -374,20 +374,28 @@ def _group_names(self, groups, filter_groups=None):
     def map(self, fun, groups=None, filter_groups=None, inplace=False, args=None, **kwargs):
         """Apply a function to multiple groups.
 
+        Applies ``fun`` groupwise to the selected ``InferenceData`` groups and overwrites the
+        group with the result of the function.
+
         Parameters
         ----------
-        fun: callable
-            Function to be applied to each group.
-        groups: str or list of str, optional
+        fun : callable
+            Function to be applied to each group. Assumes the function is called as
+            ``fun(dataset, *args, **kwargs)``.
+        groups : str or list of str, optional
             Groups where the selection is to be applied. Can either be group names
             or metagroup names.
-        inplace: bool, optional
+        filter_groups : {None, "like", "regex"}, optional
+            If `None` (default), interpret var_names as the real variables names. If "like",
+            interpret var_names as substrings of the real variables names. If "regex",
+            interpret var_names as regular expressions on the real variables names. A la
+            `pandas.filter`.
+        inplace : bool, optional
             If ``True``, modify the InferenceData object inplace,
             otherwise, return the modified copy.
-        args: array_like, optional
-            Positional arguments passed to ``fun``. Assumes the function is called as
-            ``fun(dataset, *args, **kwargs)``.
-        **kwargs: mapping, optional
+        args : array_like, optional
+            Positional arguments passed to ``fun``.
+        **kwargs : mapping, optional
             Keyword arguments passed to ``fun``.
 
         Returns
@@ -404,10 +412,40 @@ def map(self, fun, groups=None, filter_groups=None, inplace=False, args=None, **
 
             In [1]: import arviz as az
                ...: idata = az.load_arviz_data("non_centered_eight")
-               ...: idata_shifted_obs = idata.map(lambda x: x + 3, groups="observed_RVs")
+               ...: idata_shifted_obs = idata.map(lambda x: x + 3, groups="observed_vars")
                ...: print(idata_shifted_obs.observed_data)
                ...: print(idata_shifted_obs.posterior_predictive)
 
+        Rename and update the coordinate values in both posterior and prior groups.
+
+        .. ipython::
+
+            In [1]: idata = az.load_arviz_data("radon")
+               ...: idata = idata.map(
+               ...:     lambda ds: ds.rename({"gamma_dim_0": "uranium_coefs"}).assign(
+               ...:         uranium_coefs=["intercept", "u_slope", "xbar_slope"]
+               ...:     ),
+               ...:     groups=["posterior", "prior"]
+               ...: )
+               ...: idata.posterior
+
+        Add extra coordinates to all groups containing observed variables
+
+        .. ipython::
+
+            In [1]: idata = az.load_arviz_data("rugby")
+               ...: home_team, away_team = np.array([
+               ...:     m.split() for m in idata.observed_data.match.values
+               ...: ]).T
+               ...: idata = idata.map(
+               ...:     lambda ds, **kwargs: ds.assign_coords(**kwargs),
+               ...:     groups="observed_vars",
+               ...:     home_team=("match", home_team),
+               ...:     away_team=("match", away_team),
+               ...: )
+               ...: print(idata.posterior_predictive)
+               ...: print(idata.observed_data)
+
         """
         if args is None:
             args = []
@@ -455,7 +493,7 @@ def _wrap_xarray_method(
 
             In [1]: import arviz as az
                ...: idata = az.load_arviz_data("non_centered_eight")
-               ...: idata_means = idata._wrap_xarray_method("mean", groups="latent_RVs")
+               ...: idata_means = idata._wrap_xarray_method("mean", groups="latent_vars")
                ...: print(idata_means.posterior)
                ...: print(idata_means.observed_data)
 


Test patch: