Skip to content

Commit 95678eb

Browse files
author
y-p
committed
ENH: Index.__repr__ now uses pprint_thing/_encoded().
result should not change, unless unicode is present.
1 parent d968508 commit 95678eb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pandas/core/index.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pandas.lib as lib
1313
import pandas._algos as _algos
1414
from pandas.lib import Timestamp
15+
from pandas.util import py3compat
1516

1617
__all__ = ['Index']
1718

@@ -132,12 +133,11 @@ def _shallow_copy(self):
132133
return self.view()
133134

134135
def __repr__(self):
135-
try:
136-
result = np.ndarray.__repr__(self)
137-
except UnicodeEncodeError:
138-
result = 'Index([%s])' % (', '.join([repr(x) for x in self]))
139-
140-
return result
136+
if py3compat.PY3:
137+
prepr = com.pprint_thing(self)
138+
else:
139+
prepr = com.pprint_thing_encoded(self)
140+
return 'Index(%s, dtype=%s)' % (prepr,self.dtype)
141141

142142
def astype(self, dtype):
143143
return Index(self.values.astype(dtype), name=self.name,

0 commit comments

Comments
 (0)