|
7 | 7 | import numpy as np
|
8 | 8 | from pandas._libs import algos as libalgos, index as libindex, lib, Timestamp
|
9 | 9 |
|
10 |
| -from pandas.compat import range, zip, lrange, lzip, map |
| 10 | +from pandas.compat import range, zip, lrange, lzip, map, u |
11 | 11 | from pandas.compat.numpy import function as nv
|
12 | 12 | from pandas import compat
|
13 | 13 |
|
@@ -609,11 +609,28 @@ def _format_attrs(self):
|
609 | 609 | """
|
610 | 610 | Return a list of tuples of the (attr,formatted_value)
|
611 | 611 | """
|
| 612 | + def to_string_helper(obj, attr_name): |
| 613 | + """converts obj.attr_name to a string. |
| 614 | + """ |
| 615 | + indices = getattr(obj, attr_name) |
| 616 | + if attr_name == 'labels': |
| 617 | + # self.labels is a list of FrozenNDArray, Index._format_data |
| 618 | + # expects a pd.Index |
| 619 | + indices = [Index(i) for i in indices] |
| 620 | + |
| 621 | + _name = u("{}({}=").format(obj.__class__.__name__, attr_name) |
| 622 | + attr_string = [idx._format_data(name=_name) |
| 623 | + for idx in indices] |
| 624 | + attr_string = u("").join(attr_string) |
| 625 | + if attr_string.endswith(u(", ")): # else [1, 2, ], want [1, 2] |
| 626 | + attr_string = attr_string[:-2] |
| 627 | + |
| 628 | + return u("[{}]").format(attr_string) |
| 629 | + |
612 | 630 | attrs = [
|
613 |
| - ('levels', ibase.default_pprint(self._levels, |
614 |
| - max_seq_items=False)), |
615 |
| - ('labels', ibase.default_pprint(self._labels, |
616 |
| - max_seq_items=False))] |
| 631 | + ('levels', to_string_helper(self, attr_name='levels')), |
| 632 | + ('labels', to_string_helper(self, attr_name='labels')), |
| 633 | + ] |
617 | 634 | if com._any_not_none(*self.names):
|
618 | 635 | attrs.append(('names', ibase.default_pprint(self.names)))
|
619 | 636 | if self.sortorder is not None:
|
|
0 commit comments