# Buggy code
def from_formula(cls, formula, data, subset=None, *args, **kwargs):
    """
    Create a Model from a formula and dataframe.

    Parameters
    ----------
    formula : str or generic Formula object
        The formula specifying the model
    data : array-like
        The data for the model. See Notes.
    subset : array-like
        An array-like object of booleans, integers, or index values that
        indicate the subset of df to use in the model. Assumes df is a
        `pandas.DataFrame`
    args : extra arguments
        These are passed to the model
    kwargs : extra keyword arguments
        These are passed to the model with one exception. The
        ``eval_env`` keyword is passed to patsy. It can be either a
        :class:`patsy:patsy.EvalEnvironment` object or an integer
        indicating the depth of the namespace to use. For example, the
        default ``eval_env=0`` uses the calling namespace. If you wish
        to use a "clean" environment set ``eval_env=-1``.


    Returns
    -------
    model : Model instance

    Notes
    ------
    data must define __getitem__ with the keys in the formula terms
    args and kwargs are passed on to the model instantiation. E.g.,
    a numpy structured or rec array, a dictionary, or a pandas DataFrame.
    """
    # TODO: provide a docs template for args/kwargs from child models
    # TODO: subset could use syntax. issue #469.
    if subset is not None:
        data = data.ix[subset]
    eval_env = kwargs.pop("eval_env", None)
    if eval_env is None:
        eval_env = 2
    elif eval_env == -1:
        from patsy import EvalEnvironment

        eval_env = EvalEnvironment({})
    else:
        eval_env += 1  # we're going down the stack again
    missing = kwargs.get("missing", "drop")
    if missing == "none":  # with patys it's drop or raise. let's raise.
        missing = "raise"
    (endog, exog), missing_idx = handle_formula_data(
        data, None, formula, depth=eval_env, missing=missing
    )
    kwargs.update({"missing_idx": missing_idx, "missing": missing})
    mod = cls(endog, exog, *args, **kwargs)
    mod.formula = formula

    # since we got a dataframe, attach the original
    mod.data.frame = data
    return mod


# Traceback (AttributeError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/adrian/Desktop/ToDo/statsmodels_debugging/OLS.py", line 34, in <module>
fit.predict( exog=data[:-1] ) # fails
File "/usr/local/lib/python2.7/dist-packages/statsmodels-0.6.1-py2.7-linux-i686.egg/statsmodels/base/model.py", line 739, in predict
exog = dmatrix(self.model.data.orig_exog.design_info.builder,
File "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 1936, in __getattr__
(type(self).__name__, name))
AttributeError: 'DataFrame' object has no attribute 'design_info'

# Fixed code
def from_formula(cls, formula, data, subset=None, *args, **kwargs):
    """
    Create a Model from a formula and dataframe.

    Parameters
    ----------
    formula : str or generic Formula object
        The formula specifying the model
    data : array-like
        The data for the model. See Notes.
    subset : array-like
        An array-like object of booleans, integers, or index values that
        indicate the subset of df to use in the model. Assumes df is a
        `pandas.DataFrame`
    args : extra arguments
        These are passed to the model
    kwargs : extra keyword arguments
        These are passed to the model with one exception. The
        ``eval_env`` keyword is passed to patsy. It can be either a
        :class:`patsy:patsy.EvalEnvironment` object or an integer
        indicating the depth of the namespace to use. For example, the
        default ``eval_env=0`` uses the calling namespace. If you wish
        to use a "clean" environment set ``eval_env=-1``.


    Returns
    -------
    model : Model instance

    Notes
    ------
    data must define __getitem__ with the keys in the formula terms
    args and kwargs are passed on to the model instantiation. E.g.,
    a numpy structured or rec array, a dictionary, or a pandas DataFrame.
    """
    # TODO: provide a docs template for args/kwargs from child models
    # TODO: subset could use syntax. issue #469.
    if subset is not None:
        data = data.ix[subset]
    eval_env = kwargs.pop("eval_env", None)
    if eval_env is None:
        eval_env = 2
    elif eval_env == -1:
        from patsy import EvalEnvironment

        eval_env = EvalEnvironment({})
    else:
        eval_env += 1  # we're going down the stack again
    missing = kwargs.get("missing", "drop")
    if missing == "none":  # with patys it's drop or raise. let's raise.
        missing = "raise"
    ((endog, exog), missing_idx, design_info) = handle_formula_data(
        data, None, formula, depth=eval_env, missing=missing
    )
    kwargs.update(
        {"missing_idx": missing_idx, "missing": missing, "design_info": design_info}
    )
    mod = cls(endog, exog, *args, **kwargs)
    mod.formula = formula

    # since we got a dataframe, attach the original
    mod.data.frame = data
    return mod