Skip to content

BUG: Calling pm.set_data() on MutableData with dims causes error #6497

Closed
@twiecki

Description

@twiecki

Describe the issue:

For some reaoson, having a pm.MutableData() that sets dims seems to turn it into a ConstantData? At least when calling pm.set_data() to update it, along with updating coords, raises an error. Not having rely it on dims makes it work.

Reproduceable code example:

import pymc as pm

coords = {"x": [1, 2, 3]}
# breaks:
with pm.Model(coords=coords):
    pm.MutableData("y", [0, 0, 0], dims="x")
    pm.set_data({"y": range(5)}, coords={"x": range(5)})

# this works:
coords = {"x": [1, 2, 3]}
with pm.Model(coords=coords):
    pm.MutableData("y", [0, 0, 0])
    pm.set_data({"y": range(5)}, coords={"x": range(5)})

Error message:

ShapeError: Resizing dimension 'x' is impossible, because a `TensorConstant` stores its length. To be able to change the dimension length, pass `mutable=True` when registering the dimension via `model.add_coord`, or define it via a `pm.MutableData` variable.

PyMC version information:

5.0.1

Context for the issue:

Happened during a workshop, confusing for beginners.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions