From fbcce93401653da3f262a5596fbb914bfd30c91b Mon Sep 17 00:00:00 2001 From: Michael Osthege Date: Fri, 14 May 2021 21:21:42 +0200 Subject: [PATCH] Disallow "__sample__" as a dimension name Co-authored-by: Thomas Wiecki --- pymc3/model.py | 9 +++++---- pymc3/tests/test_sampling.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pymc3/model.py b/pymc3/model.py index 7567b9ac233..505a5297d40 100644 --- a/pymc3/model.py +++ b/pymc3/model.py @@ -959,7 +959,7 @@ 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. @@ -967,9 +967,10 @@ def add_coord( 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( @@ -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)) diff --git a/pymc3/tests/test_sampling.py b/pymc3/tests/test_sampling.py index 84565f6219c..76071f4bb17 100644 --- a/pymc3/tests/test_sampling.py +++ b/pymc3/tests/test_sampling.py @@ -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)