# Buggy code
def pandas_to_array(data):
    if hasattr(data, "values"):  # pandas
        if data.isnull().any().any():  # missing values
            ret = np.ma.MaskedArray(data.values, data.isnull().values)
        else:
            ret = data.values
    elif hasattr(data, "mask"):
        ret = data
    elif isinstance(data, theano.gof.graph.Variable):
        ret = data
    elif sps.issparse(data):
        ret = data
    elif isgenerator(data):
        ret = generator(data)
    else:
        ret = np.asarray(data)
    return pm.floatX(ret)


# Traceback (ValueError)
/usr/local/lib/python3.6/dist-packages/pymc3/model.py:1331: UserWarning: Data in X_t contains missing values and will be automatically imputed from the sampling distribution.
warnings.warn(impute_message, UserWarning)
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [coef, Intercept_t, X_t_missing, Xmu_t]
Sampling 2 chains: 100%|██████████| 3000/3000 [00:15<00:00, 195.87draws/s]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-44-457eee33d21f> in <module>()
9     y_prob = pm.math.sigmoid(intercept + coef * X_modeled)
10     y_t = pm.Bernoulli('y', y_prob, observed=y)
---> 11     trace = pm.sample(1000, tune=500, chains=2, cores=2, init='adapt_diag')

3 frames
/usr/local/lib/python3.6/dist-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, **kwargs)
464                 warnings.warn("The number of samples is too small to check convergence reliably.")
465             else:
--> 466                 trace.report._run_convergence_checks(trace, model)
467
468         trace.report._log_summary()

/usr/local/lib/python3.6/dist-packages/pymc3/backends/report.py in _run_convergence_checks(self, trace, model)
86
87         warnings = []
---> 88         rhat_max = max(val.max() for val in gelman_rubin.values())
89         if rhat_max > 1.4:
90             msg = ("The gelman-rubin statistic is larger than 1.4 for some "

/usr/local/lib/python3.6/dist-packages/pymc3/backends/report.py in <genexpr>(.0)
86
87         warnings = []
---> 88         rhat_max = max(val.max() for val in gelman_rubin.values())
89         if rhat_max > 1.4:
90             msg = ("The gelman-rubin statistic is larger than 1.4 for some "

/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py in _amax(a, axis, out, keepdims, initial)
26 def _amax(a, axis=None, out=None, keepdims=False,
27           initial=_NoValue):
---> 28     return umr_maximum(a, axis, None, out, keepdims, initial)
29
30 def _amin(a, axis=None, out=None, keepdims=False,

ValueError: zero-size array to reduction operation maximum which has no identity

# Fixed code
def pandas_to_array(data):
    if hasattr(data, "values"):  # pandas
        if data.isnull().any().any():  # missing values
            ret = np.ma.MaskedArray(data.values, data.isnull().values)
        else:
            ret = data.values
    elif hasattr(data, "mask"):
        if data.mask.any():
            ret = data
        else:  # empty mask
            ret = data.filled()
    elif isinstance(data, theano.gof.graph.Variable):
        ret = data
    elif sps.issparse(data):
        ret = data
    elif isgenerator(data):
        ret = generator(data)
    else:
        ret = np.asarray(data)
    return pm.floatX(ret)