# Buggy code
def fit(self, data, *args, **kwds):
    floc = kwds.get("floc", None)
    if floc is None:
        # loc is not fixed.  Use the default fit method.
        return super(lognorm_gen, self).fit(data, *args, **kwds)

    f0 = kwds.get("f0", None) or kwds.get("fs", None) or kwds.get("fix_s", None)
    fscale = kwds.get("fscale", None)

    if len(args) > 1:
        raise TypeError("Too many input arguments.")
    for name in ["f0", "fs", "fix_s", "floc", "fscale", "loc", "scale", "optimizer"]:
        kwds.pop(name, None)
    if kwds:
        raise TypeError("Unknown arguments: %s." % kwds)

    # Special case: loc is fixed.  Use the maximum likelihood formulas
    # instead of the numerical solver.

    if f0 is not None and fscale is not None:
        # This check is for consistency with `rv_continuous.fit`.
        raise ValueError("All parameters fixed. There is nothing to optimize.")

    data = np.asarray(data)
    floc = float(floc)
    if floc != 0:
        # Shifting the data by floc. Don't do the subtraction in-place,
        # because `data` might be a view of the input array.
        data = data - floc
    if np.any(data <= 0):
        raise FitDataError("lognorm", lower=floc, upper=np.inf)
    lndata = np.log(data)

    # Three cases to handle:
    # * shape and scale both free
    # * shape fixed, scale free
    # * shape free, scale fixed

    if fscale is None:
        # scale is free.
        scale = np.exp(lndata.mean())
        if f0 is None:
            # shape is free.
            shape = lndata.std()
        else:
            # shape is fixed.
            shape = float(f0)
    else:
        # scale is fixed, shape is free
        scale = float(fscale)
        shape = np.sqrt(((lndata - np.log(scale)) ** 2).mean())

    return shape, floc, scale


# Traceback (RuntimeError)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-86-fb3d43a0acaa> in <module>
13        1.5754, 2.2669, 1.6383, 1.7696, 1.9079, 1.0955, 1.5637, 2.66  ,
14        1.746 , 1.5319, 2.0958,    np.nan])
---> 15 K = stats.exponnorm.fit(x)

/anaconda3/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py in fit(self, data, *args, **kwds)
2195                                          'scale' in kwds):
2196             # get distribution specific starting locations
-> 2197             start = self._fitstart(data)
2198             args += start[Narg:-2]
2199         loc = kwds.pop('loc', start[-2])

/anaconda3/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py in _fitstart(self, data, args)
2034         if args is None:
2035             args = (1.0,)*self.numargs
-> 2036         loc, scale = self._fit_loc_scale_support(data, *args)
2037         return args + (loc, scale)
2038

/anaconda3/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py in _fit_loc_scale_support(self, data, *args)
2287             return (data_b - b) + margin, 1
2288         else:
-> 2289             raise RuntimeError
2290
2291     def fit_loc_scale(self, data, *args):

RuntimeError:

# Fixed code
def fit(self, data, *args, **kwds):
    floc = kwds.get("floc", None)
    if floc is None:
        # loc is not fixed.  Use the default fit method.
        return super(lognorm_gen, self).fit(data, *args, **kwds)

    f0 = kwds.get("f0", None) or kwds.get("fs", None) or kwds.get("fix_s", None)
    fscale = kwds.get("fscale", None)

    if len(args) > 1:
        raise TypeError("Too many input arguments.")
    for name in ["f0", "fs", "fix_s", "floc", "fscale", "loc", "scale", "optimizer"]:
        kwds.pop(name, None)
    if kwds:
        raise TypeError("Unknown arguments: %s." % kwds)

    # Special case: loc is fixed.  Use the maximum likelihood formulas
    # instead of the numerical solver.

    if f0 is not None and fscale is not None:
        # This check is for consistency with `rv_continuous.fit`.
        raise ValueError("All parameters fixed. There is nothing to optimize.")

    data = np.asarray(data)

    if not np.isfinite(data).all():
        raise RuntimeError("The data contains non-finite values.")

    floc = float(floc)
    if floc != 0:
        # Shifting the data by floc. Don't do the subtraction in-place,
        # because `data` might be a view of the input array.
        data = data - floc
    if np.any(data <= 0):
        raise FitDataError("lognorm", lower=floc, upper=np.inf)
    lndata = np.log(data)

    # Three cases to handle:
    # * shape and scale both free
    # * shape fixed, scale free
    # * shape free, scale fixed

    if fscale is None:
        # scale is free.
        scale = np.exp(lndata.mean())
        if f0 is None:
            # shape is free.
            shape = lndata.std()
        else:
            # shape is fixed.
            shape = float(f0)
    else:
        # scale is fixed, shape is free
        scale = float(fscale)
        shape = np.sqrt(((lndata - np.log(scale)) ** 2).mean())

    return shape, floc, scale