# Pm.set\_data throws error

**URL:** <https://discourse.pymc.io/t/pm-set-data-throws-error/11526>\
**Category:** v5\
**Tags:** bug\
**Created:** [March 5, 2023, 2:36pm UTC](https://discourse.pymc.io/t/pm-set-data-throws-error/11526 "2023-03-05T14:36:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal\_Raczycki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/michal_raczycki/32/5583_2.png) [@Michal\_Raczycki](https://discourse.pymc.io/u/Michal_Raczycki)\
**Post date:** [March 5, 2023, 2:36pm UTC](https://discourse.pymc.io/t/pm-set-data-throws-error/11526/1 "2023-03-05T14:36:33Z")

</div>

Hello dear Bayesians!  
I was trying to reproduce models from some of the model\_builder tests, and I’ve encountered this situation:

```python
with pm.Model() as model:
    x = pm.MutableData('x', data['input'].values)
    y_data = pm.MutableData('y_data', data['output'].values)
    
    a = pm.Normal('a', mu = 0, sigma = 10)
    b = pm.Normal('b', mu = 0, sigma = 10)
    obs_error = pm.HalfNormal('σ_model_fmc', sigma = 2)
    
    result = pm.Normal('y_model', mu = a+b*x, sigma = obs_error, shape = x.shape, observed = y_data)
    idata = pm.sample()

```

After this I assigned new x’s

```python
x_pred = [1,2,3,4,5]
with model:
    pm.set_data({'x' : x_pred})

```

But quite fast I’ve realized that the test has different data structure passed as x, so I fixed it to reproduce it 1:1. So after quick fix my new x assignment looked like that:

```python
x_pred2 = np.random.uniform(low=0, high=1, size=100)
prediction_data = pd.DataFrame({'input' : x_pred2})
with model:
    pm.set_data({'x' : prediction_data.input.values})

```

Which went all right, but when I tried to get predictions:

```python
with model:
    idata = pm.sample_posterior_predictive(idata, predictions = True, extend_inferencedata=True)

```

I was given this error:

 ![Zrzut ekranu 2023-03-5 o 15.26.35](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/a/a8f7c8422a072322daaf7a7163293c2a6cb8a48f.png)  
 ![Zrzut ekranu 2023-03-5 o 15.26.43](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/1/12a71c0fca23dd2c89ac19f33cbe964817c6dbae.png)

Is this desired behavior, that I can’t assign new values to the mutable data container without rebuilding the model? If I’d pass something of shape of the first x\_pred, it works fine, otherwise it throws error

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [March 5, 2023, 4:46pm UTC](https://discourse.pymc.io/t/pm-set-data-throws-error/11526/2 "2023-03-05T16:46:16Z")

</div>

Welcome!

If you are running this in a notebook, have you tried restarting the kernel and running everything from scratch? It may be the case that you have group in the `idata` called “posterior\_predictive” and by calling `pm.sample_posterior_predictive()` with `extend_inferencedata=True`, it may be trying to extend the existing posterior predictive data (of one shape) with a new posterior predictive (of a new shape). But that’s just a guess.

---

<div class="post-metadata">

**Author:** ![Michal\_Raczycki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/michal_raczycki/32/5583_2.png) [@Michal\_Raczycki](https://discourse.pymc.io/u/Michal_Raczycki)\
**Post date:** [March 5, 2023, 7:03pm UTC](https://discourse.pymc.io/t/pm-set-data-throws-error/11526/3 "2023-03-05T19:03:18Z")

</div>

Ah! Of course. I completely ignored the extend\_inferencedata, and was failing why it was complaining about dimensions, I was convinced that maybe I’ve discovered some bug. Thank you!
