From e107350d57c95a27fa8f727b623820bcb6606ce1 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Mon, 12 Oct 2015 18:20:57 +0200 Subject: [PATCH] Only cast pandas Series or DataFrame to numpy if dtype is not 'O'. 'O' has before been a pass-through dtype that allowed users to pass in values that were not strictly numpy arrays. HDDM for example passed in pandas DataFrames which it then expected in the likelihood. With commit 7c7be9a52581bc666411fbc42420e997d71e34cc HDDM broke. With these changes, it works again. --- pymc/PyMCObjects.py | 6 +++--- pymc/distributions.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pymc/PyMCObjects.py b/pymc/PyMCObjects.py index 425b9ef5..787640e7 100644 --- a/pymc/PyMCObjects.py +++ b/pymc/PyMCObjects.py @@ -305,7 +305,7 @@ def gen_lazy_function(self): parameter] = lazy_logp_partial_gradients def get_logp(self): - + if self.verbose > 1: print_('\t' + self.__name__ + ': log-probability accessed.') logp = self._logp.get() @@ -736,9 +736,9 @@ def __init__(self, # Initialize value, either from value provided or from random function. try: - # Convert Pandas DataFrames and Series to numpy arrays - value = getattr(value, 'values', value) if dtype.kind != 'O' and value is not None: + # Convert Pandas DataFrames and Series to numpy arrays + value = getattr(value, 'values', value) self._value = np.array(value, dtype=dtype) self._value.flags['W'] = False else: diff --git a/pymc/distributions.py b/pymc/distributions.py index 967d224a..b9592486 100755 --- a/pymc/distributions.py +++ b/pymc/distributions.py @@ -797,7 +797,7 @@ def bernoulli_like(x, p): - :math:`Var(x)= p(1-p)` """ - + return flib.bernoulli(x, p) bernoulli_grad_like = {'p': flib.bern_grad_p} @@ -2976,8 +2976,6 @@ def valuewrapper(f, arguments=None): """ def wrapper(**kwds): value = kwds.pop('value') - # Handle Pandas DataFrames - value = getattr(value, 'values', value) return f(value, **kwds) if arguments is None: