Skip to content

set_data raises AttributeError #5372

Closed
Closed
@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions