Skip to content

Commit

Permalink
Disallow "__sample__" as a dimension name
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Wiecki <thomas.wiecki@gmail.com>
  • Loading branch information
michaelosthege and twiecki committed May 15, 2021
1 parent 9ab831d commit fbcce93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pymc3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,17 +959,18 @@ def add_coord(
----------
name : str
Name of the dimension.
Forbidden: {"chain", "draw"}
Forbidden: {"chain", "draw", "__sample__"}
values : optional, array-like
Coordinate values or ``None`` (for auto-numbering).
If ``None`` is passed, a ``length`` must be specified.
length : optional, scalar
A symbolic scalar of the dimensions length.
Defaults to ``aesara.shared(len(values))``.
"""
if name in {"draw", "chain"}:
if name in {"draw", "chain", "__sample__"}:
raise ValueError(
"Dimensions can not be named `draw` or `chain`, as they are reserved for the sampler's outputs."
"Dimensions can not be named `draw`, `chain` or `__sample__`, "
"as those are reserved for use in `InferenceData`."
)
if values is None and length is None:
raise ValueError(
Expand All @@ -981,7 +982,7 @@ def add_coord(
)
if name in self.coords:
if not values.equals(self.coords[name]):
raise ValueError("Duplicate and incompatiple coordinate: %s." % name)
raise ValueError(f"Duplicate and incompatiple coordinate: {name}.")
else:
self._coords[name] = values
self._dim_lengths[name] = length or aesara.shared(len(values))
Expand Down
2 changes: 1 addition & 1 deletion pymc3/tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_return_inferencedata(self, monkeypatch):
return_inferencedata=True,
discard_tuned_samples=True,
idata_kwargs={"prior": prior},
random_seed=-1
random_seed=-1,
)
assert "prior" in result
assert isinstance(result, InferenceData)
Expand Down

0 comments on commit fbcce93

Please sign in to comment.