def write_result(self, buf):
<EOL>if len(self.frame.columns) == <NUM_LIT:0> or len(self.frame.index) == <NUM_LIT:0>:<EOL><INDENT>info_line = ('<STR_LIT>'<EOL>.format(name=type(self.frame).__name__,<EOL>col=self.frame.columns,<EOL>idx=self.frame.index))<EOL>strcols = [[info_line]]<EOL><DEDENT>else:<EOL><INDENT>strcols = self.fmt._to_str_columns()<EOL><DEDENT>def get_col_type(dtype):<EOL><INDENT>if issubclass(dtype.type, np.number):<EOL><INDENT>return '<STR_LIT:r>'<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT:l>'<EOL><DEDENT><DEDENT>if self.fmt.index and isinstance(self.frame.index, ABCMultiIndex):<EOL><INDENT>out = self.frame.index.format(<EOL>adjoin=False, sparsify=self.fmt.sparsify,<EOL>names=self.fmt.has_index_names, na_rep=self.fmt.na_rep<EOL>)<EOL>def pad_empties(x):<EOL><INDENT>for pad in reversed(x):<EOL><INDENT>if pad:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return [x[<NUM_LIT:0>]] + [i if i else '<STR_LIT:U+0020>' * len(pad) for i in x[<NUM_LIT:1>:]]<EOL><DEDENT>out = (pad_empties(i) for i in out)<EOL>clevels = self.frame.columns.nlevels<EOL>out = [['<STR_LIT:U+0020>' * len(i[-<NUM_LIT:1>])] * clevels + i for i in out]<EOL>cnames = self.frame.columns.names<EOL>if any(cnames):<EOL><INDENT>new_names = [i if i else '<STR_LIT:{}>' for i in cnames]<EOL>out[self.frame.index.nlevels - <NUM_LIT:1>][:clevels] = new_names<EOL><DEDENT>strcols = out + strcols[<NUM_LIT:1>:]<EOL><DEDENT>column_format = self.column_format<EOL>if column_format is None:<EOL><INDENT>dtypes = self.frame.dtypes._values<EOL>column_format = '<STR_LIT>'.join(map(get_col_type, dtypes))<EOL>if self.fmt.index:<EOL><INDENT>index_format = '<STR_LIT:l>' * self.frame.index.nlevels<EOL>column_format = index_format + column_format<EOL><DEDENT><DEDENT>elif not isinstance(column_format, str):  <EOL><INDENT>raise AssertionError('<STR_LIT>'<EOL>'<STR_LIT>'.format(typ=type(column_format)))<EOL><DEDENT>if not self.longtable:<EOL><INDENT>buf.write('<STR_LIT>'<EOL>.format(fmt=column_format))<EOL>buf.write('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>buf.write('<STR_LIT>'<EOL>.format(fmt=column_format))<EOL>buf.write('<STR_LIT>')<EOL><DEDENT>ilevels = self.frame.index.nlevels<EOL>clevels = self.frame.columns.nlevels<EOL>nlevels = clevels<EOL>if self.fmt.has_index_names and self.fmt.show_index_names:<EOL><INDENT>nlevels += <NUM_LIT:1><EOL><DEDENT>strrows = list(zip(*strcols))<EOL>self.clinebuf = []<EOL>for i, row in enumerate(strrows):<EOL><INDENT>if i == nlevels and self.fmt.header:<EOL><INDENT>buf.write('<STR_LIT>')  <EOL>if self.longtable:<EOL><INDENT>buf.write('<STR_LIT>')<EOL>buf.write('<STR_LIT>')<EOL>buf.write('<STR_LIT>'<EOL>'<STR_LIT>'.format(n=len(row)))<EOL>buf.write('<STR_LIT>')<EOL>buf.write('<STR_LIT>')<EOL>buf.write('<STR_LIT>')<EOL>buf.write('<STR_LIT>')<EOL><DEDENT><DEDENT>if self.fmt.kwds.get('<STR_LIT>', True):<EOL><INDENT>crow = [(x.replace('<STR_LIT:\\>', '<STR_LIT>')<EOL>.replace('<STR_LIT:_>', '<STR_LIT>')<EOL>.replace('<STR_LIT:%>', '<STR_LIT>').replace('<STR_LIT:$>', '<STR_LIT>')<EOL>.replace('<STR_LIT:#>', '<STR_LIT>').replace('<STR_LIT:{>', '<STR_LIT>')<EOL>.replace('<STR_LIT:}>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>')<EOL>.replace('<STR_LIT>', '<STR_LIT>')<EOL>.replace('<STR_LIT:&>', '<STR_LIT>')<EOL>if (x and x != '<STR_LIT:{}>') else '<STR_LIT:{}>') for x in row]<EOL><DEDENT>else:<EOL><INDENT>crow = [x if x else '<STR_LIT:{}>' for x in row]<EOL><DEDENT>if self.bold_rows and self.fmt.index:<EOL><INDENT>crow = ['<STR_LIT>'.format(x=x)<EOL>if j < ilevels and x.strip() not in ['<STR_LIT>', '<STR_LIT:{}>'] else x<EOL>for j, x in enumerate(crow)]<EOL><DEDENT>if i < clevels and self.fmt.header and self.multicolumn:<EOL><INDENT>crow = self._format_multicolumn(crow, ilevels)<EOL><DEDENT>if (i >= nlevels and self.fmt.index and self.multirow and<EOL>ilevels > <NUM_LIT:1>):<EOL><INDENT>crow = self._format_multirow(crow, ilevels, i, strrows)<EOL><DEDENT>buf.write('<STR_LIT>'.join(crow))<EOL>buf.write('<STR_LIT>')<EOL>if self.multirow and i < len(strrows) - <NUM_LIT:1>:<EOL><INDENT>self._print_cline(buf, i, len(strcols))<EOL><DEDENT><DEDENT>if not self.longtable:<EOL><INDENT>buf.write('<STR_LIT>')<EOL>buf.write('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>buf.write('<STR_LIT>')<EOL><DEDENT>
Render a DataFrame to a LaTeX tabular/longtable environment output.