Skip to content

Commit 2d30141

Browse files
authored
MAINT: stats._SimpleDomain: ensure that instances do not share symbols (scipy#22139)
* MAINT: stats._SimpleDomain: ensure that instances do not share symbols Co-authored-by: Matt Haberland <[email protected]>
1 parent e7dfd40 commit 2d30141

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

scipy/stats/_distribution_infrastructure.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,10 @@ class _SimpleDomain(_Domain):
267267
268268
"""
269269
def __init__(self, endpoints=(-inf, inf), inclusive=(False, False)):
270+
self.symbols = super().symbols.copy()
270271
a, b = endpoints
271272
self.endpoints = np.asarray(a)[()], np.asarray(b)[()]
272273
self.inclusive = inclusive
273-
# self.all_inclusive = (endpoints == (-inf, inf)
274-
# and inclusive == (True, True))
275274

276275
def define_parameters(self, *parameters):
277276
r""" Records any parameters used to define the endpoints of the domain.

scipy/stats/tests/test_continuous.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ def test_str2(self, a, b, inclusive_a, inclusive_b):
117117
ref = f"{left_bracket}{a}, {b}{right_bracket}"
118118
assert str(domain) == ref
119119

120+
def test_symbols_gh22137(self):
121+
# `symbols` was accidentally shared between instances originally
122+
# Check that this is no longer the case
123+
domain1 = _RealDomain(endpoints=(0, 1))
124+
domain2 = _RealDomain(endpoints=(0, 1))
125+
assert domain1.symbols is not domain2.symbols
126+
127+
120128
def draw_distribution_from_family(family, data, rng, proportions, min_side=0):
121129
# If the distribution has parameters, choose a parameterization and
122130
# draw broadcastable shapes for the parameter arrays.

0 commit comments

Comments
 (0)