Skip to content

ERR: DataFrame can get into unprintable state #16098

Closed
@chris-b1

Description

@chris-b1

I know my replication case looks very strange, I had a typo assigning the wrong thing to index=, but the way the error is reported out of this made it very confusing to debug, possibly can do something better:

Code Sample, a copy-pastable example if possible


dct = {'a': pd.DataFrame({'a':[1,2,3]}), 'b': [1, 2, 3], 'c': 5}

df = pd.DataFrame({'a': range(3)}, index=dct.values())

df  # calling repr
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--> 311                 return method()
    312             return None
    313         else:

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\frame.py in _repr_html_(self)
    608 
    609             return self.to_html(max_rows=max_rows, max_cols=max_cols,
--> 610                                 show_dimensions=show_dimensions, notebook=True)
    611         else:
    612             return None

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\frame.py in to_html(self, buf, columns, col_space, header, index, na_rep, formatters, float_format, sparsify, index_names, justify, bold_rows, classes, escape, max_rows, max_cols, show_dimensions, notebook, decimal, border)
   1606                                            decimal=decimal)
   1607         # TODO: a generic formatter wld b in DataFrameFormatter
-> 1608         formatter.to_html(classes=classes, notebook=notebook, border=border)
   1609 
   1610         if buf is None:

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\formats\format.py in to_html(self, classes, notebook, border)
    698                                       border=border)
    699         if hasattr(self.buf, 'write'):
--> 700             html_renderer.write_result(self.buf)
    701         elif isinstance(self.buf, compat.string_types):
    702             with open(self.buf, 'w') as f:

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\formats\format.py in write_result(self, buf)
   1022         indent += self.indent_delta
   1023         indent = self._write_header(indent)
-> 1024         indent = self._write_body(indent)
   1025 
   1026         self.write('</table>', indent)

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\formats\format.py in _write_body(self, indent)
   1181                 self._write_hierarchical_rows(fmt_values, indent)
   1182             else:
-> 1183                 self._write_regular_rows(fmt_values, indent)
   1184         else:
   1185             for i in range(len(self.frame)):

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\formats\format.py in _write_regular_rows(self, fmt_values, indent)
   1203             index_values = self.fmt.tr_frame.index.map(fmt)
   1204         else:
-> 1205             index_values = self.fmt.tr_frame.index.format()
   1206 
   1207         row = []

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\indexes\base.py in format(self, name, formatter, **kwargs)
   1596             return header + list(self.map(formatter))
   1597 
-> 1598         return self._format_with_header(header, **kwargs)
   1599 
   1600     def _format_with_header(self, header, na_rep='NaN', **kwargs):

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\indexes\base.py in _format_with_header(self, header, na_rep, **kwargs)
   1610         if is_object_dtype(values.dtype):
   1611             result = [pprint_thing(x, escape_chars=('\t', '\r', '\n'))
-> 1612                       for x in values]
   1613 
   1614             # could have nans

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\indexes\base.py in <listcomp>(.0)
   1610         if is_object_dtype(values.dtype):
   1611             result = [pprint_thing(x, escape_chars=('\t', '\r', '\n'))
-> 1612                       for x in values]
   1613 
   1614             # could have nans

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\formats\printing.py in pprint_thing(thing, _nest_lvl, escape_chars, default_escapes, quote_strings, max_seq_items)
    218         result = _pprint_seq(thing, _nest_lvl, escape_chars=escape_chars,
    219                              quote_strings=quote_strings,
--> 220                              max_seq_items=max_seq_items)
    221     elif isinstance(thing, compat.string_types) and quote_strings:
    222         if compat.PY3:

C:\Users\chris.bartak\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\formats\printing.py in _pprint_seq(seq, _nest_lvl, max_seq_items, **kwds)
    115     for i in range(min(nitems, len(seq))):  # handle sets, no slicing
    116         r.append(pprint_thing(
--> 117             next(s), _nest_lvl + 1, max_seq_items=max_seq_items, **kwds))
    118     body = ", ".join(r)
    119 

StopIteration: 


pandas 0.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugError ReportingIncorrect or improved errors from pandasOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions