stan-dev / pystan

PyStan, a Python interface to Stan, a platform for statistical modeling. Documentation: https://pystan.readthedocs.io
ISC License
340 stars 58 forks source link

Verify `data` is JSON-serializable and has correct form #51

Closed riddell-stan closed 5 years ago

riddell-stan commented 5 years ago

Before sending data to the backend (httpstan), it needs to be:

  1. JSON serializable
  2. Have the appropriate structure for Stan C++/array_var_context (see https://github.com/stan-dev/httpstan/blob/master/httpstan/utils.py)

Checking for this needs to be done on the pystan(-next) side in order to give the user useful feedback.

L619 commented 5 years ago

@riddell-stan ,But I modify the dat to array, still have same error "TypeError: Object of type 'Series' is not JSON serializable". Could you please help fix it again? Thank you.

The modified code is(now seasonal_features is numpy.ndarray type): dat = {'T': history.shape[0], 'K': seasonal_features.shape[1], 'S': len(self.changepoints_t), 'y': np.array(history['y_scaled'].values), 't': np.array(history['t'].values), 't_change': np.array(self.changepoints_t), 'X': seasonal_features.values, 'sigmas': np.array(prior_scales), 'tau': self.changepoint_prior_scale, ... }

riddell-stan commented 5 years ago

@L619 try adding tolist() everywhere so you are using lists, e.g., history['y_scaled'].values.tolist()

(Also, this sort of question belongs on the Stan forum since it doesn't relate to solving this particular issue. Next time please post on the forum.)

For anyone else reading this -- PyStan 3 is not quite ready for public use. This is indicated by the warning in the README: "NOTE: This is an experimental version of PyStan 3. Do not use!"