TypeError with arviz.compare

I’m pretty new to PyMC and ArviZ. Using versions pymc => 4.2.2 and arviz => 0.12.1. I’m exploring arviz.compare. The first argument is a dictionary of InferenceData objects, which coincides with the return type of pymc.sample. However the following simple example blows up with a TypeError. It looks like another post may contain a solution, but my setup is managed by conda, not pip. Any recommendations?

y_obs = stats.norm.rvs(size=100)

# Normal with fixed μ=0 and σ free.
with pm.Model() as model:
    σ = pm.HalfNormal('σ', 1)
    y = pm.Normal('y', 0, sigma=σ, observed=y_obs)
    idata_1 = pm.sample(1000)

# SkewNormal with μ=0, α=1 and σ free.
with pm.Model() as model:
    σ = pm.HalfNormal('σ', 1)
    y = pm.SkewNormal('y', sigma=σ, observed=y_obs)
    idata_2 = pm.sample(1000)

az.compare({'1': idata_1, '2': idata_2})

TypeError                                 Traceback (most recent call last)
File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/pandas/core/indexes/base.py:3803, in Index.get_loc(self, key, method, tolerance)
   3802 try:
-> 3803     return self._engine.get_loc(casted_key)
   3804 except KeyError as err:

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/pandas/_libs/index.pyx:138, in pandas._libs.index.IndexEngine.get_loc()

File ~/miniconda3/envs/pymc/lib/python3.10/site-packages/pandas/_libs/index.pyx:144, in pandas._libs.index.IndexEngine.get_loc()

TypeError: 'slice(None, None, None)' is an invalid key
...

Welcome!

Your code works for me. What version of PyMC/Arivz are you using?

Try using conda install arviz==0.14.0 to make sure you are using the latest ArviZ version, you probably have 0.12.1 or something similar installed where that bug was present.

1 Like

Awesome, thanks @OriolAbril. I needed to run conda install -c conda-forge arviz, and it auto-updated to the lates version, which is 0.14. That also resolved the issue.

I always forget about specifying conda-forge because it is automatic for me, sorry about that. I recommend you install everything from conda forge. I found this tips and tricks page in conda forge docs very helpful.

Thanks! That’s helpful, and I’ll update my local configs. My experience is mostly Linux / server, anything Python is usually managed by pip or pipenv, so still learning to navigate conda.

1 Like