Skip to content

Commit

Permalink
Give Data model-relative names.
Browse files Browse the repository at this point in the history
Use Model.name_for() to relativize pm.Data names.
  • Loading branch information
rpgoldman committed Mar 19, 2020
1 parent a054d40 commit 909d773
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pymc3/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,6 @@ class Data:
https://docs.pymc.io/notebooks/data_container.html
"""
def __new__(self, name, value):
# `pm.model.pandas_to_array` takes care of parameter `value` and
# transforms it to something digestible for pymc3
shared_object = theano.shared(pm.model.pandas_to_array(value), name)

# To draw the node for this variable in the graphviz Digraph we need
# its shape.
shared_object.dshape = tuple(shared_object.shape.eval())

# Add data container to the named variables of the model.
try:
Expand All @@ -494,6 +487,18 @@ def __new__(self, name, value):
raise TypeError("No model on context stack, which is needed to "
"instantiate a data container. Add variable "
"inside a 'with model:' block.")

name = model.name_for(name)

# `pm.model.pandas_to_array` takes care of parameter `value` and
# transforms it to something digestible for pymc3
shared_object = theano.shared(pm.model.pandas_to_array(value), name)

# To draw the node for this variable in the graphviz Digraph we need
# its shape.
shared_object.dshape = tuple(shared_object.shape.eval())


model.add_random_variable(shared_object)

return shared_object

0 comments on commit 909d773

Please sign in to comment.