Skip to content

Commit 2c9fb26

Browse files
author
Chris Fonnesbeck
authored
Merge pull request #1302 from tyarkoni/string-checking
fixes string checking for Python 2/3 compatibility; closes #1301
2 parents 636bddb + 1a78390 commit 2c9fb26

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pymc3/distributions/distribution.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

89

910
__all__ = ['DensityDist', 'Distribution', 'Continuous', 'Discrete', 'NoDistribution', 'TensorType', 'draw_values']
@@ -19,7 +20,7 @@ def __new__(cls, name, *args, **kwargs):
1920
"use the Normal('x', 0,1) syntax. "
2021
"Add a 'with model:' block")
2122

22-
if isinstance(name, str):
23+
if isinstance(name, string_types):
2324
data = kwargs.pop('observed', None)
2425
dist = cls.dist(*args, **kwargs)
2526
return model.Var(name, dist, data)
@@ -65,7 +66,7 @@ def get_test_val(self, val, defaults):
6566

6667

6768
def getattr_value(self, val):
68-
if isinstance(val, str):
69+
if isinstance(val, string_types):
6970
val = getattr(self, val)
7071

7172
if isinstance(val, tt.TensorVariable):

pymc3/vartypes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
__all__ = ['bool_types', 'int_types', 'float_types', 'complex_types', 'continuous_types',
24
'discrete_types', 'default_type', 'typefilter']
35

@@ -21,6 +23,11 @@
2123
default_type = {'discrete': 'int64',
2224
'continuous': 'float64'}
2325

26+
if sys.version_info[0] == 3:
27+
string_types = str
28+
else:
29+
string_types = basestring
30+
2431

2532
def typefilter(vars, types):
2633
# Returns variables of type `types` from `vars`

0 commit comments

Comments
 (0)