Skip to content

Commit 135da45

Browse files
committed
fixes string checking for Python 2/3 compatibility; closes pymc-devs#1301
1 parent 636bddb commit 135da45

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pymc3/distributions/distribution.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
from ..memoize import memoize
66
from ..model import Model, get_named_nodes
7+
import sys
78

89

910
__all__ = ['DensityDist', 'Distribution', 'Continuous', 'Discrete', 'NoDistribution', 'TensorType', 'draw_values']
1011

1112

13+
if sys.version_info[0] == 3:
14+
string_types = str
15+
else:
16+
string_types = basestring
17+
18+
1219
class Distribution(object):
1320
"""Statistical distribution"""
1421
def __new__(cls, name, *args, **kwargs):
@@ -19,7 +26,7 @@ def __new__(cls, name, *args, **kwargs):
1926
"use the Normal('x', 0,1) syntax. "
2027
"Add a 'with model:' block")
2128

22-
if isinstance(name, str):
29+
if isinstance(name, string_types):
2330
data = kwargs.pop('observed', None)
2431
dist = cls.dist(*args, **kwargs)
2532
return model.Var(name, dist, data)
@@ -65,7 +72,7 @@ def get_test_val(self, val, defaults):
6572

6673

6774
def getattr_value(self, val):
68-
if isinstance(val, str):
75+
if isinstance(val, string_types):
6976
val = getattr(self, val)
7077

7178
if isinstance(val, tt.TensorVariable):

0 commit comments

Comments
 (0)