# Buggy code
def from_product(cls, iterables, sortorder=None, names=None):
    """
    Make a MultiIndex from the cartesian product of multiple iterables

    Parameters
    ----------
    iterables : list / sequence of iterables
        Each iterable has unique labels for each level of the index.
    sortorder : int or None
        Level of sortedness (must be lexicographically sorted by that
        level).
    names : list / sequence of strings or None
        Names for the levels in the index.

    Returns
    -------
    index : MultiIndex

    Examples
    --------
    >>> numbers = [0, 1, 2]
    >>> colors = [u'green', u'purple']
    >>> MultiIndex.from_product([numbers, colors],
                                 names=['number', 'color'])
    MultiIndex(levels=[[0, 1, 2], [u'green', u'purple']],
               labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
               names=[u'number', u'color'])

    See Also
    --------
    MultiIndex.from_arrays : Convert list of arrays to MultiIndex
    MultiIndex.from_tuples : Convert list of tuples to MultiIndex
    """
    from pandas.core.categorical import _factorize_from_iterables
    from pandas.tools.util import cartesian_product

    labels, levels = _factorize_from_iterables(iterables)
    labels = cartesian_product(labels)

    return MultiIndex(levels=levels, labels=labels, sortorder=sortorder, names=names)


# Traceback (KeyError)
df2.sort_index().loc['b':'d']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)

# a lot of lines omitted here.

/Users/yimengzh/miniconda/envs/cafferc3/lib/python2.7/site-packages/pandas/indexes/multi.py in _partial_tup_index(self, tup, side)
1488             raise KeyError('Key length (%d) was greater than MultiIndex'
1489                            ' lexsort depth (%d)' %
-> 1490                            (len(tup), self.lexsort_depth))
1491
1492         n = len(tup)

KeyError: 'Key length (1) was greater than MultiIndex lexsort depth (0)'

# Fixed code
def from_product(cls, iterables, sortorder=None, names=None):
    """
    Make a MultiIndex from the cartesian product of multiple iterables

    Parameters
    ----------
    iterables : list / sequence of iterables
        Each iterable has unique labels for each level of the index.
    sortorder : int or None
        Level of sortedness (must be lexicographically sorted by that
        level).
    names : list / sequence of strings or None
        Names for the levels in the index.

    Returns
    -------
    index : MultiIndex

    Examples
    --------
    >>> numbers = [0, 1, 2]
    >>> colors = [u'green', u'purple']
    >>> MultiIndex.from_product([numbers, colors],
                                 names=['number', 'color'])
    MultiIndex(levels=[[0, 1, 2], [u'green', u'purple']],
               labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
               names=[u'number', u'color'])

    See Also
    --------
    MultiIndex.from_arrays : Convert list of arrays to MultiIndex
    MultiIndex.from_tuples : Convert list of tuples to MultiIndex
    """
    from pandas.core.categorical import _factorize_from_iterables
    from pandas.tools.util import cartesian_product

    labels, levels = _factorize_from_iterables(iterables)
    labels = cartesian_product(labels)
    return MultiIndex(levels, labels, sortorder=sortorder, names=names)