Skip to content

set_data raises AttributeError #5372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jan 19, 2022 · 3 comments
Closed

set_data raises AttributeError #5372

ghost opened this issue Jan 19, 2022 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 19, 2022

Description of your problem

After creating a model that uses pm.Data objects for all data inputs, using set_data following sampling to swap in new predictor values for prediction results in an AttributeError

coords = {
    'age': ages.values.astype(int),
    'obs_id': np.arange(df_clean.shape[0])
}
with pm.Model(coords=coords) as age_model:

    age_ind = pm.Data('age_ind', age_indices, dims='obs_id')

    ...


with age_model:
    pm.set_data({"age_ind": nola.age.values - 20})
    post_pred = pm.sample_posterior_predictive(trace)

    ...

Please provide the full traceback.

Complete error traceback
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-67-459704977541> in <module>()
      1 with age_model:
----> 2     pm.set_data({"age_ind": nola.age.values - 20})
      3     post_pred = pm.sample_posterior_predictive(trace)

1 frames
/usr/local/lib/python3.7/dist-packages/pymc/model.py in set_data(new_data, model)
   1759 
   1760     for variable_name, new_value in new_data.items():
-> 1761         model.set_data(variable_name, new_value)
   1762 
   1763 

/usr/local/lib/python3.7/dist-packages/pymc/model.py in set_data(self, name, values, coords)
   1175             # NOTE: If there are multiple pm.MutableData containers sharing this dim, but the user only
   1176             #       changes the values for one of them, they will run into shape problems nonetheless.
-> 1177             length_belongs_to = length_tensor.owner.inputs[0].owner.inputs[0]
   1178             if not isinstance(length_belongs_to, SharedVariable) and length_changed:
   1179                 raise ShapeError(

AttributeError: 'NoneType' object has no attribute 'inputs'

Versions and main components

  • PyMC/PyMC3 Version: 4.0.0b2
  • Aesara/Theano Version: 2.3.4
  • Python Version: 3.7.12
  • Operating system: Linux (Colab)
  • How did you install PyMC/PyMC3: pip
@ghost
Copy link
Author

ghost commented Jan 19, 2022

This appears to be due to my using a dims argument on the original Data which does not correspond to the new data. At any rate, there should be a more informative error message here.

@ricardoV94
Copy link
Member

CC @michaelosthege

@michaelosthege
Copy link
Member

I remember that we changed something related to this, but it looks like we didn't link this issue.

import numpy as np
import pymc as pm

print(pm.__version__)

coords = {
    'age': np.arange(3),
    'obs_id': np.arange(5),
}
with pm.Model(coords=coords) as age_model:
    age_ind = pm.MutableData('age_ind', [1,2,3,4,5], dims='obs_id')


with age_model:
    pm.set_data({"age_ind": [6,7,8,9,10]})
print("green")
# 4.1.7
# green

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants