# Buggy code
def lcl(pressure, temperature, dewpt, max_iters=50, eps=1e-5):
    r"""Calculate the lifted condensation level (LCL) using from the starting point.

    The starting state for the parcel is defined by `temperature`, `dewpt`,
    and `pressure`.

    Parameters
    ----------
    pressure : `pint.Quantity`
        The starting atmospheric pressure
    temperature : `pint.Quantity`
        The starting temperature
    dewpt : `pint.Quantity`
        The starting dew point

    Returns
    -------
    `(pint.Quantity, pint.Quantity)`
        The LCL pressure and temperature

    Other Parameters
    ----------------
    max_iters : int, optional
        The maximum number of iterations to use in calculation, defaults to 50.
    eps : float, optional
        The desired relative error in the calculated value, defaults to 1e-5.

    See Also
    --------
    parcel_profile

    Notes
    -----
    This function is implemented using an iterative approach to solve for the
    LCL. The basic algorithm is:

    1. Find the dew point from the LCL pressure and starting mixing ratio
    2. Find the LCL pressure from the starting temperature and dewpoint
    3. Iterate until convergence

    The function is guaranteed to finish by virtue of the `max_iters` counter.

    """

    def _lcl_iter(p, p0, w, t):
        td = dewpoint(vapor_pressure(units.Quantity(p, pressure.units), w))
        return (p0 * (td / t) ** (1.0 / kappa)).m

    w = mixing_ratio(saturation_vapor_pressure(dewpt), pressure)
    fp = so.fixed_point(
        _lcl_iter,
        pressure.m,
        args=(pressure.m, w, temperature),
        xtol=eps,
        maxiter=max_iters,
    )
    lcl_p = units.Quantity(fp, pressure.units)
    return lcl_p, dewpoint(vapor_pressure(lcl_p, w))


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/metpydev/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
343             method = get_real_method(obj, self.print_method)
344             if method is not None:
--> 345                 return method()
346             return None
347         else:

~/miniconda3/envs/metpydev/lib/python3.6/site-packages/pint/quantity.py in _repr_html_(self)
213     # IPython related code
214     def _repr_html_(self):
--> 215         return self.__format__('H')
216
217     def _repr_latex_(self):

~/miniconda3/envs/metpydev/lib/python3.6/site-packages/pint/quantity.py in __format__(self, spec)
177                 # this is required to have the magnitude and unit in the same line
178                 allf = r'\[{0} {1}\]'
--> 179                 parts = ndarray_to_latex_parts(obj.magnitude, mspec)
180
181                 if len(parts) > 1:

~/miniconda3/envs/metpydev/lib/python3.6/site-packages/pint/formatting.py in ndarray_to_latex_parts(ndarr, fmtfun, dim)
304                 ret += [header % elno + ' = ' + matrix_to_latex(el, fmtfun)]
305         else:
--> 306             for elno, el in enumerate(ndarr):
307                 ret += ndarray_to_latex_parts(el, fmtfun, dim + (elno, ))
308

TypeError: iteration over a 0-d array

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/metpydev/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
343             method = get_real_method(obj, self.print_method)
344             if method is not None:
--> 345                 return method()
346             return None
347         else:

~/miniconda3/envs/metpydev/lib/python3.6/site-packages/pint/quantity.py in _repr_latex_(self)
216
217     def _repr_latex_(self):
--> 218         return "$" + self.__format__('L') + "$"
219
220     @property

~/miniconda3/envs/metpydev/lib/python3.6/site-packages/pint/quantity.py in __format__(self, spec)
173         if isinstance(self.magnitude, ndarray):
174             if 'L' in spec:
--> 175                 mstr = ndarray_to_latex(obj.magnitude, mspec)
176             elif 'H' in spec:
177                 # this is required to have the magnitude and unit in the same line

~/miniconda3/envs/metpydev/lib/python3.6/site-packages/pint/formatting.py in ndarray_to_latex(ndarr, fmtfun, dim)
311
312 def ndarray_to_latex(ndarr, fmtfun=lambda x: format(x, '.2f'), dim=()):
--> 313         return '\n'.join(ndarray_to_latex_parts(ndarr, fmtfun, dim))

~/miniconda3/envs/metpydev/lib/python3.6/site-packages/pint/formatting.py in ndarray_to_latex_parts(ndarr, fmtfun, dim)
304                 ret += [header % elno + ' = ' + matrix_to_latex(el, fmtfun)]
305         else:
--> 306             for elno, el in enumerate(ndarr):
307                 ret += ndarray_to_latex_parts(el, fmtfun, dim + (elno, ))
308

TypeError: iteration over a 0-d array

Out[27]:
<Quantity(929.7098864382868, 'hectopascal')>

# Fixed code
def lcl(pressure, temperature, dewpt, max_iters=50, eps=1e-5):
    r"""Calculate the lifted condensation level (LCL) using from the starting point.

    The starting state for the parcel is defined by `temperature`, `dewpt`,
    and `pressure`.

    Parameters
    ----------
    pressure : `pint.Quantity`
        The starting atmospheric pressure
    temperature : `pint.Quantity`
        The starting temperature
    dewpt : `pint.Quantity`
        The starting dew point

    Returns
    -------
    `(pint.Quantity, pint.Quantity)`
        The LCL pressure and temperature

    Other Parameters
    ----------------
    max_iters : int, optional
        The maximum number of iterations to use in calculation, defaults to 50.
    eps : float, optional
        The desired relative error in the calculated value, defaults to 1e-5.

    See Also
    --------
    parcel_profile

    Notes
    -----
    This function is implemented using an iterative approach to solve for the
    LCL. The basic algorithm is:

    1. Find the dew point from the LCL pressure and starting mixing ratio
    2. Find the LCL pressure from the starting temperature and dewpoint
    3. Iterate until convergence

    The function is guaranteed to finish by virtue of the `max_iters` counter.

    """

    def _lcl_iter(p, p0, w, t):
        td = dewpoint(vapor_pressure(units.Quantity(p, pressure.units), w))
        return (p0 * (td / t) ** (1.0 / kappa)).m

    w = mixing_ratio(saturation_vapor_pressure(dewpt), pressure)
    fp = so.fixed_point(
        _lcl_iter,
        pressure.m,
        args=(pressure.m, w, temperature),
        xtol=eps,
        maxiter=max_iters,
    )
    lcl_p = fp * pressure.units
    return lcl_p, dewpoint(vapor_pressure(lcl_p, w))