# Buggy code
def find_best_blas_type(arrays=(), dtype=None):
    """Find best-matching BLAS/LAPACK type.

    Arrays are used to determine the optimal prefix of BLAS routines.

    Parameters
    ----------
    arrays : sequence of ndarrays, optional
        Arrays can be given to determine optimal prefix of BLAS
        routines. If not given, double-precision routines will be
        used, otherwise the most generic type in arrays will be used.
    dtype : str or dtype, optional
        Data-type specifier. Not used if `arrays` is non-empty.

    Returns
    -------
    prefix : str
        BLAS/LAPACK prefix character.
    dtype : dtype
        Inferred Numpy data type.
    prefer_fortran : bool
        Whether to prefer Fortran order routines over C order.

    """
    dtype = _np.dtype(dtype)
    prefer_fortran = False

    if arrays:
        # use the most generic type in arrays
        dtypes = [ar.dtype for ar in arrays]
        dtype = _np.find_common_type(dtypes, ())
        try:
            index = dtypes.index(dtype)
        except ValueError:
            index = 0
        if arrays[index].flags["FORTRAN"]:
            # prefer Fortran for leading array with column major order
            prefer_fortran = True

    prefix = _type_conv.get(dtype.char, "d")
    if dtype.char not in "fdFD":
        dtype = _np.dtype("d")

    return prefix, dtype, prefer_fortran


# Traceback (ValueError)
A = np.array([[1,2,3],[4,5,6],[7,8,9]])
b = [3,2,1]
dt=np.complex256; la.lstsq(array(A, dtype=dt), array(b, dtype=dt), lapack_driver='gelsd')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-45-1282c50dbc51> in <module>()
----> 1 dt=np.complex256; la.lstsq(array(A, dtype=dt), array(b, dtype=dt), lapack_driver='gelsd')

/usr/lib/python3.5/site-packages/scipy/linalg/basic.py in lstsq(a, b, cond, overwrite_a, overwrite_b, check_finite, lapack_driver)
867         elif driver == 'gelsd':
868             if real_data:
--> 869                 lwork, iwork = _compute_lwork(lapack_lwork, m, n, nrhs, cond)
870                 if iwork == 0:
871                     # this is LAPACK bug 0038: dgelsd does not provide the

ValueError: too many values to unpack (expected 2)

# Fixed code
def find_best_blas_type(arrays=(), dtype=None):
    """Find best-matching BLAS/LAPACK type.

    Arrays are used to determine the optimal prefix of BLAS routines.

    Parameters
    ----------
    arrays : sequence of ndarrays, optional
        Arrays can be given to determine optimal prefix of BLAS
        routines. If not given, double-precision routines will be
        used, otherwise the most generic type in arrays will be used.
    dtype : str or dtype, optional
        Data-type specifier. Not used if `arrays` is non-empty.

    Returns
    -------
    prefix : str
        BLAS/LAPACK prefix character.
    dtype : dtype
        Inferred Numpy data type.
    prefer_fortran : bool
        Whether to prefer Fortran order routines over C order.

    """
    dtype = _np.dtype(dtype)
    prefer_fortran = False

    if arrays:
        # use the most generic type in arrays
        dtypes = [ar.dtype for ar in arrays]
        dtype = _np.find_common_type(dtypes, ())
        try:
            index = dtypes.index(dtype)
        except ValueError:
            index = 0
        if arrays[index].flags["FORTRAN"]:
            # prefer Fortran for leading array with column major order
            prefer_fortran = True

    prefix = _type_conv.get(dtype.char, "d")
    if dtype.char == "G":
        # complex256 -> complex128 (i.e., C long double -> C double)
        dtype = _np.dtype("D")
    elif dtype.char not in "fdFD":
        dtype = _np.dtype("d")

    return prefix, dtype, prefer_fortran