Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: ndarray is not C-contiguous #20

Closed
jburos opened this issue Jan 16, 2019 · 0 comments
Closed

ValueError: ndarray is not C-contiguous #20

jburos opened this issue Jan 16, 2019 · 0 comments

Comments

@jburos
Copy link
Member

jburos commented Jan 16, 2019

Encounter an error when testing hammelab/survivalstan@feature/royston-parmar (build log on wide data.

A reproducible example is:

import survivalstan
import numpy as np
import pandas as pd
from stancache import stancache

model_code = survivalstan.models.royston_parmar_survival_model

d = stancache.cached(
    survivalstan.sim.sim_data_exp_correlated,
    N=100,
    censor_time=20,
    rate_form='1 + sex',
    rate_coefs=[-3, 0.5],
)
d['age_centered'] = d['age'] - d['age'].mean()

testfit = survivalstan.fit_stan_survival_model(
    model_cohort = 'test model',
    model_code = model_code,
    df = d,
    formula = 'surv(event_status = event, time = t) ~ age_centered + sex',
    iter = 5000,
    chains = 4,
    seed = 9001,
    FIT_FUN = stancache.cached_stan_fit,
    )

Which generates the following output (with debug logging on):

DEBUG:stancache.stancache:cache_dir set to .cached_models
DEBUG:stancache.stancache:processing item (N) as int
DEBUG:stancache.stancache:processing item (censor_time) as int
DEBUG:stancache.stancache:processing item (rate_coefs) as other (using xxhash)
DEBUG:stancache.stancache:processing item (rate_coefs) as other (using pickle)
DEBUG:stancache.stancache:note: item (rate_coefs) is of type: <class 'list'>
DEBUG:stancache.stancache:processing item (rate_form) as str
INFO:stancache.stancache:sim_data_exp_correlated: cache_filename set to sim_data_exp_correlated.cached.N_100.censor_time_20.rate_coefs_54462717316.rate_form_1 + sex.pkl
DEBUG:stancache.stancache:sim_data_exp_correlated: cache_filepath set to .cached_models/sim_data_exp_correlated.cached.N_100.censor_time_20.rate_coefs_54462717316.rate_form_1 + sex.pkl
INFO:stancache.stancache:sim_data_exp_correlated: Loading result from cache
/home/jacki/projects/survivalstan/survivalstan/formulas.py:132: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  
/home/jacki/projects/survivalstan/survivalstan/formulas.py:133: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  class WideSurvData(SurvData):
/home/jacki/projects/survivalstan/survivalstan/formulas.py:132: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  
/home/jacki/projects/survivalstan/survivalstan/formulas.py:133: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  class WideSurvData(SurvData):
/home/jacki/projects/survivalstan/survivalstan/formulas.py:132: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  
/home/jacki/projects/survivalstan/survivalstan/formulas.py:133: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  class WideSurvData(SurvData):
/home/jacki/projects/survivalstan/survivalstan/formulas.py:132: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  
/home/jacki/projects/survivalstan/survivalstan/formulas.py:133: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  class WideSurvData(SurvData):
DEBUG:stancache.stancache:cache_dir set to .cached_models
DEBUG:stancache.stancache:processing item (cython) as str
DEBUG:stancache.stancache:processing item (model_code) as other (using xxhash)
DEBUG:stancache.stancache:note: item (model_code) is of type: <class 'str'>
DEBUG:stancache.stancache:processing item (pystan) as str
DEBUG:stancache.stancache:processing item (chains) as int
DEBUG:stancache.stancache:processing item (data) as dict
DEBUG:stancache.stancache:processing item (data-D) as int
DEBUG:stancache.stancache:processing item (data-M) as int
DEBUG:stancache.stancache:processing item (data-N) as int
DEBUG:stancache.stancache:processing item (data-basis_evals) as np.ndarray
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-33-1baa659d7e65> in <module>
     23     chains = 4,
     24     seed = 9001,
---> 25     FIT_FUN = stancache.cached_stan_fit,
     26     )

~/projects/survivalstan/survivalstan/survivalstan.py in fit_stan_survival_model(df, formula, event_col, model_code, file, model_cohort, time_col, sample_id_col, sample_col, group_id_col, group_col, timepoint_id_col, timepoint_end_col, make_inits, stan_data, grp_coef_type, FIT_FUN, drop_intercept, input_data, *args, **kwargs)
    165         data=input_data.data,
    166         *args,
--> 167         **kwargs
    168         )
    169 

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in cached_stan_fit(iter, chains, seed, *args, **kwargs)
    249     if seed is None:
    250         seed = config.get_setting_value('SEED')
--> 251     return _cached_stan_fit(seed=seed, iter=iter, chains=chains, **kwargs)
    252 
    253 

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in _cached_stan_fit(model_name, file, model_code, force, cache_dir, cache_only, fit_cachefile, **kwargs)
    213     model_cachefile, fit_cachefile = cached_stan_file(model_name=model_name, file=file, model_code=model_code,
    214                                                       cache_dir=cache_dir, fit_cachefile=fit_cachefile,
--> 215                                                       include_modelfile=True, **kwargs)
    216     cache_dir = _get_cache_dir(cache_dir)
    217     model_name = _sanitize_model_name(model_name)

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in cached_stan_file(model_name, file, model_code, cache_dir, fit_cachefile, cache_only, force, include_modelfile, prefix_only, **kwargs)
    174                                                       cache_dir=cache_dir, fit_cachefile=fit_cachefile, include_prefix=True)
    175     if not fit_cachefile:
--> 176         fit_cachefile = '.'.join([model_prefix, 'stanfit', _make_digest(dict(**kwargs)), 'pkl'])
    177     if include_modelfile:
    178         return model_cachefile, fit_cachefile

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in _make_digest(k, **kwargs)
    110     """
    111     result = list()
--> 112     result_dict = _make_digest_dict(k, **kwargs)
    113     if result_dict is None:
    114         return 'default'

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in _make_digest_dict(k, prefix)
     68             logger.debug('processing item ({}) as dict'.format(pre_key))
     69             item = dict(sorted(item.items()))
---> 70             s = _make_digest(item, prefix=key+'-')
     71             result.update({pre_key: _digest(s.encode())})
     72         elif isinstance(item, pd.DataFrame):

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in _make_digest(k, **kwargs)
    110     """
    111     result = list()
--> 112     result_dict = _make_digest_dict(k, **kwargs)
    113     if result_dict is None:
    114         return 'default'

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in _make_digest_dict(k, prefix)
     80         elif isinstance(item, np.ndarray):
     81             logger.debug('processing item ({}) as np.ndarray'.format(pre_key))
---> 82             s = _xxhash_item(item)
     83             result.update({pre_key: s})
     84         elif isinstance(item, types.FunctionType):

/srv/conda/lib/python3.6/site-packages/stancache/stancache.py in _xxhash_item(item)
     38 
     39 def _xxhash_item(item):
---> 40     h = xxhash.xxh64(item)
     41     s = h.intdigest()
     42     return s

ValueError: ndarray is not C-contiguous
@jburos jburos closed this as completed in ee3ceb3 Jan 16, 2019
jburos added a commit that referenced this issue Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant