# Buggy code
def _translate(self):
    """
    Convert the DataFrame in `self.data` and the attrs from `_build_styles`
    into a dictionary of {head, body, uuid, cellstyle}
    """
    table_styles = self.table_styles or []
    caption = self.caption
    ctx = self.ctx
    precision = self.precision
    uuid = self.uuid or str(uuid1()).replace("-", "_")
    ROW_HEADING_CLASS = "row_heading"
    COL_HEADING_CLASS = "col_heading"
    INDEX_NAME_CLASS = "index_name"

    DATA_CLASS = "data"
    BLANK_CLASS = "blank"
    BLANK_VALUE = ""

    def format_attr(pair):
        return "{key}={value}".format(**pair)

    # for sparsifying a MultiIndex
    idx_lengths = _get_level_lengths(self.index)
    col_lengths = _get_level_lengths(self.columns)

    cell_context = dict()

    n_rlvls = self.data.index.nlevels
    n_clvls = self.data.columns.nlevels
    rlabels = self.data.index.tolist()
    clabels = self.data.columns.tolist()

    if n_rlvls == 1:
        rlabels = [[x] for x in rlabels]
    if n_clvls == 1:
        clabels = [[x] for x in clabels]
    clabels = list(zip(*clabels))

    cellstyle = []
    head = []

    for r in range(n_clvls):
        # Blank for Index columns...
        row_es = [
            {
                "type": "th",
                "value": BLANK_VALUE,
                "display_value": BLANK_VALUE,
                "is_visible": True,
                "class": " ".join([BLANK_CLASS]),
            }
        ] * (n_rlvls - 1)

        # ... except maybe the last for columns.names
        name = self.data.columns.names[r]
        cs = [BLANK_CLASS if name is None else INDEX_NAME_CLASS, "level%s" % r]
        name = BLANK_VALUE if name is None else name
        row_es.append(
            {
                "type": "th",
                "value": name,
                "display_value": name,
                "class": " ".join(cs),
                "is_visible": True,
            }
        )

        for c, value in enumerate(clabels[r]):
            cs = [COL_HEADING_CLASS, "level%s" % r, "col%s" % c]
            cs.extend(cell_context.get("col_headings", {}).get(r, {}).get(c, []))
            es = {
                "type": "th",
                "value": value,
                "display_value": value,
                "class": " ".join(cs),
                "is_visible": _is_visible(c, r, col_lengths),
            }
            colspan = col_lengths.get((r, c), 0)
            if colspan > 1:
                es["attributes"] = [format_attr({"key": "colspan", "value": colspan})]
            row_es.append(es)
        head.append(row_es)

    if self.data.index.names and not all(x is None for x in self.data.index.names):
        index_header_row = []

        for c, name in enumerate(self.data.index.names):
            cs = [INDEX_NAME_CLASS, "level%s" % c]
            name = "" if name is None else name
            index_header_row.append(
                {"type": "th", "value": name, "class": " ".join(cs)}
            )

        index_header_row.extend(
            [{"type": "th", "value": BLANK_VALUE, "class": " ".join([BLANK_CLASS])}]
            * len(clabels[0])
        )

        head.append(index_header_row)

    body = []
    for r, idx in enumerate(self.data.index):
        row_es = []
        for c, value in enumerate(rlabels[r]):
            es = {
                "type": "th",
                "is_visible": _is_visible(r, c, idx_lengths),
                "value": value,
                "display_value": value,
                "class": " ".join([ROW_HEADING_CLASS, "level%s" % c, "row%s" % r]),
            }
            rowspan = idx_lengths.get((c, r), 0)
            if rowspan > 1:
                es["attributes"] = [format_attr({"key": "rowspan", "value": rowspan})]
            row_es.append(es)

        for c, col in enumerate(self.data.columns):
            cs = [DATA_CLASS, "row%s" % r, "col%s" % c]
            cs.extend(cell_context.get("data", {}).get(r, {}).get(c, []))
            formatter = self._display_funcs[(r, c)]
            value = self.data.iloc[r, c]
            row_es.append(
                {
                    "type": "td",
                    "value": value,
                    "class": " ".join(cs),
                    "id": "_".join(cs[1:]),
                    "display_value": formatter(value),
                }
            )
            props = []
            for x in ctx[r, c]:
                # have to handle empty styles like ['']
                if x.count(":"):
                    props.append(x.split(":"))
                else:
                    props.append(["", ""])
            cellstyle.append({"props": props, "selector": "row%s_col%s" % (r, c)})
        body.append(row_es)

    return dict(
        head=head,
        cellstyle=cellstyle,
        body=body,
        uuid=uuid,
        precision=precision,
        table_styles=table_styles,
        caption=caption,
        table_attributes=self.table_attributes,
    )


# Traceback (IndexError)
In [6]: pd.DataFrame().style.render()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-6-345e1b37074e> in <module>()
----> 1 pd.DataFrame().style.render()

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/formats/style.py in render(self)
416         """
417         self._compute()
--> 418         d = self._translate()
419         # filter out empty styles, every cell will have a class
420         # but the list of props may just be [['', '']].

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/formats/style.py in _translate(self)
252                            "is_visible": True})
253
--> 254             for c in range(len(clabels[0])):
255                 cs = [COL_HEADING_CLASS, "level%s" % r, "col%s" % c]
256                 cs.extend(cell_context.get(

IndexError: list index out of range

# Fixed code
def _translate(self):
    """
    Convert the DataFrame in `self.data` and the attrs from `_build_styles`
    into a dictionary of {head, body, uuid, cellstyle}
    """
    table_styles = self.table_styles or []
    caption = self.caption
    ctx = self.ctx
    precision = self.precision
    uuid = self.uuid or str(uuid1()).replace("-", "_")
    ROW_HEADING_CLASS = "row_heading"
    COL_HEADING_CLASS = "col_heading"
    INDEX_NAME_CLASS = "index_name"

    DATA_CLASS = "data"
    BLANK_CLASS = "blank"
    BLANK_VALUE = ""

    def format_attr(pair):
        return "{key}={value}".format(**pair)

    # for sparsifying a MultiIndex
    idx_lengths = _get_level_lengths(self.index)
    col_lengths = _get_level_lengths(self.columns)

    cell_context = dict()

    n_rlvls = self.data.index.nlevels
    n_clvls = self.data.columns.nlevels
    rlabels = self.data.index.tolist()
    clabels = self.data.columns.tolist()

    if n_rlvls == 1:
        rlabels = [[x] for x in rlabels]
    if n_clvls == 1:
        clabels = [[x] for x in clabels]
    clabels = list(zip(*clabels))

    cellstyle = []
    head = []

    for r in range(n_clvls):
        # Blank for Index columns...
        row_es = [
            {
                "type": "th",
                "value": BLANK_VALUE,
                "display_value": BLANK_VALUE,
                "is_visible": True,
                "class": " ".join([BLANK_CLASS]),
            }
        ] * (n_rlvls - 1)

        # ... except maybe the last for columns.names
        name = self.data.columns.names[r]
        cs = [BLANK_CLASS if name is None else INDEX_NAME_CLASS, "level%s" % r]
        name = BLANK_VALUE if name is None else name
        row_es.append(
            {
                "type": "th",
                "value": name,
                "display_value": name,
                "class": " ".join(cs),
                "is_visible": True,
            }
        )

        if clabels:
            for c, value in enumerate(clabels[r]):
                cs = [COL_HEADING_CLASS, "level%s" % r, "col%s" % c]
                cs.extend(cell_context.get("col_headings", {}).get(r, {}).get(c, []))
                es = {
                    "type": "th",
                    "value": value,
                    "display_value": value,
                    "class": " ".join(cs),
                    "is_visible": _is_visible(c, r, col_lengths),
                }
                colspan = col_lengths.get((r, c), 0)
                if colspan > 1:
                    es["attributes"] = [
                        format_attr({"key": "colspan", "value": colspan})
                    ]
                row_es.append(es)
            head.append(row_es)

    if self.data.index.names and not all(x is None for x in self.data.index.names):
        index_header_row = []

        for c, name in enumerate(self.data.index.names):
            cs = [INDEX_NAME_CLASS, "level%s" % c]
            name = "" if name is None else name
            index_header_row.append(
                {"type": "th", "value": name, "class": " ".join(cs)}
            )

        index_header_row.extend(
            [{"type": "th", "value": BLANK_VALUE, "class": " ".join([BLANK_CLASS])}]
            * len(clabels[0])
        )

        head.append(index_header_row)

    body = []
    for r, idx in enumerate(self.data.index):
        row_es = []
        for c, value in enumerate(rlabels[r]):
            es = {
                "type": "th",
                "is_visible": _is_visible(r, c, idx_lengths),
                "value": value,
                "display_value": value,
                "class": " ".join([ROW_HEADING_CLASS, "level%s" % c, "row%s" % r]),
            }
            rowspan = idx_lengths.get((c, r), 0)
            if rowspan > 1:
                es["attributes"] = [format_attr({"key": "rowspan", "value": rowspan})]
            row_es.append(es)

        for c, col in enumerate(self.data.columns):
            cs = [DATA_CLASS, "row%s" % r, "col%s" % c]
            cs.extend(cell_context.get("data", {}).get(r, {}).get(c, []))
            formatter = self._display_funcs[(r, c)]
            value = self.data.iloc[r, c]
            row_es.append(
                {
                    "type": "td",
                    "value": value,
                    "class": " ".join(cs),
                    "id": "_".join(cs[1:]),
                    "display_value": formatter(value),
                }
            )
            props = []
            for x in ctx[r, c]:
                # have to handle empty styles like ['']
                if x.count(":"):
                    props.append(x.split(":"))
                else:
                    props.append(["", ""])
            cellstyle.append({"props": props, "selector": "row%s_col%s" % (r, c)})
        body.append(row_es)

    return dict(
        head=head,
        cellstyle=cellstyle,
        body=body,
        uuid=uuid,
        precision=precision,
        table_styles=table_styles,
        caption=caption,
        table_attributes=self.table_attributes,
    )