PyMC error: TypeError: dict_to_dataset() got an unexpected keyword argument 'default_dims'

Environment: LINUX
PM Version: pm version is ‘4.0.0b6’

Running the below model is giving me an error I haven’t seen on this site or stackoverflow.

Error pops up after sampling is done. See error below.

Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 54 seconds.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_2309/2471676992.py in <module>
     15     pm.Poisson("predicted_sales", mu = mu_, observed = experimental['eaches'])
     16 
---> 17     trace = pm.sample(tune=1000, chains = 4)

/opt/conda/lib/python3.7/site-packages/pymc/sampling.py in sample(draws, step, init, n_init, initvals, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, callback, jitter_max_retries, return_inferencedata, idata_kwargs, mp_ctx, **kwargs)
    621         if idata_kwargs:
    622             ikwargs.update(idata_kwargs)
--> 623         idata = pm.to_inference_data(mtrace, **ikwargs)
    624 
    625     if compute_convergence_checks:

/opt/conda/lib/python3.7/site-packages/pymc/backends/arviz.py in to_inference_data(trace, prior, posterior_predictive, log_likelihood, coords, dims, model, save_warmup)
    589         dims=dims,
    590         model=model,
--> 591         save_warmup=save_warmup,
    592     ).to_inference_data()
    593 

/opt/conda/lib/python3.7/site-packages/pymc/backends/arviz.py in to_inference_data(self)
    522             "predictions": self.predictions_to_xarray(),
    523             **self.priors_to_xarray(),
--> 524             "observed_data": self.observed_data_to_xarray(),
    525         }
    526         if self.predictions:

/opt/conda/lib/python3.7/site-packages/arviz/data/base.py in wrapped(cls, *args, **kwargs)
     44                 if all([getattr(cls, prop_i) is None for prop_i in prop]):
     45                     return None
---> 46             return func(cls, *args, **kwargs)
     47 
     48         return wrapped

/opt/conda/lib/python3.7/site-packages/arviz/data/base.py in wrapped(cls, *args, **kwargs)
     44                 if all([getattr(cls, prop_i) is None for prop_i in prop]):
     45                     return None
---> 46             return func(cls, *args, **kwargs)
     47 
     48         return wrapped

/opt/conda/lib/python3.7/site-packages/pymc/backends/arviz.py in observed_data_to_xarray(self)
    458             coords=self.coords,
    459             dims=self.dims,
--> 460             default_dims=[],
    461         )
    462 

TypeError: dict_to_dataset() got an unexpected keyword argument 'default_dims'

I don’t see this error message anywhere else on the message board. Does this look familiar?

For context, see the model below:

#define hyper-parameters

#potential number of changes in trends over time
n_changepoints = 5

#make the t
t = np.arange(len(experimental))/len(experimental)
#make the changepoints
s = np.linspace(0, max(t), n_changepoints + 2)[1: -1]

#indicator matrix
A = (t[:, None]>s) * 1

with pm.Model() as model:
    
    k = pm.Normal('k', 0, 1)
    m = pm.Normal('m', 0, 5)
    delta = pm.Laplace('delta', 0, 0.01, shape = n_changepoints)
    
    growth = k + at.dot(A, delta)
    offset = m + at.dot(A, -s * delta)
    trend = growth * t + offset
    
    error = pm.HalfCauchy('sigma', 0.5)
    
    mu_ = trend + error
    
    pm.Poisson("predicted_sales", mu = mu_, observed = experimental['eaches'])
    
    trace = pm.sample(tune=1000, chains = 4)

Which ArviZ version do you have?

Hi @OriolAbril.

I’m using ArviZ version ‘0.11.2’

Your pymc installation didn’t work properly somehow. If you installed the 6th beta release from conda or pip, the minimum required version is 0.11.4: pymc/requirements.txt at v4.0.0b6 · pymc-devs/pymc · GitHub.

If you installed from github (which will also show the same version number as it is updated with releases only, see the init file) you’ll need 0.12.0: pymc/requirements.txt at main · pymc-devs/pymc · GitHub

I figured it out. Data was a float when it should have been an int with the Poisson distribution.

I’m still getting the same error when I try to sample from the posterior though.

Thanks for the help.

1 Like