pd.DataFrame.min() is returning a 0 as an int64, which does not bother my laptop on Ubuntu 21.04, PyStan3.2, etc.
But on my server, Ubuntu 20.04, PyStan3.2, etc, my Stan model won’t even compile:
import stan
import numpy as np
schools_code = """
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // standard error of effect estimates
}
parameters {
real mu; // population treatment effect
real<lower=0> tau; // standard deviation in treatment effects
vector[J] eta; // unscaled deviation from mu by school
}
transformed parameters {
vector[J] theta = mu + tau * eta; // school treatment effects
}
model {
target += normal_lpdf(eta | 0, 1); // prior log-density
target += normal_lpdf(y | theta, sigma); // log-likelihood
}
"""
schools_data = {"J": 8,
'test': np.int64(0),
"y": [28, 8, -3, 7, -1, 1, 18, 12],
"sigma": [15, 10, 16, 11, 9, 11, 10, 18]}
posterior = stan.build(schools_code, data=schools_data, random_seed=1)
results in:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~/papers/focal-responses-paper/bin/pystan3_debugging.py in <module>
26 "y": [28, 8, -3, 7, -1, 1, 18, 12],
27 "sigma": [15, 10, 16, 11, 9, 11, 10, 18]}
---> 28 posterior = stan.build(schools_code, data=schools_data, random_seed=1)
29
30 fit = posterior.sample(num_chains=4, num_samples=1000)
~/.local/lib/python3.8/site-packages/stan/model.py in build(program_code, data, random_seed)
448 """
449 # `data` must be JSON-serializable in order to send to httpstan
--> 450 data = json.loads(DataJSONEncoder().encode(data))
451
452 async def go():
/usr/lib/python3.8/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
/usr/lib/python3.8/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
~/.local/lib/python3.8/site-packages/stan/model.py in default(self, obj)
25 if isinstance(obj, np.ndarray):
26 return obj.tolist()
---> 27 return json.JSONEncoder.default(self, obj)
28
29
/usr/lib/python3.8/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.__class__.__name__} '
180 f'is not JSON serializable')
181
TypeError: Object of type int64 is not JSON serializable
> /usr/lib/python3.8/json/encoder.py(179)default()
177
178 """
--> 179 raise TypeError(f'Object of type {o.__class__.__name__} '
180 f'is not JSON serializable')
181
Feature? Bug?
Btw, .astype(int)
in pandas gives me this int64.
As a naive, very applied, simple user,I have to say, to be honest, sorry, my productivity on my main project has somewhat ground to a halt since I followed the recommendations everywhere to switch from pystan2 to pystan3. (Update: okay, finally learning to use venv
may make me more sane, though developing for both at once).