Skip to content

Commit 4323a62

Browse files
committed
Start repr work
1 parent d92c597 commit 4323a62

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

pandas/core/dtypes/dtypes.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ def __eq__(self, other):
203203

204204
return isinstance(other, CategoricalDtype)
205205

206+
def __unicode__(self):
207+
tpl = 'CategoricalDtype({}, ordered={})'
208+
if self.categories is None:
209+
data = "None"
210+
else:
211+
data = self.categories._format_data(name=self.__class__.__name__)
212+
return tpl.format(data, self.ordered)
213+
214+
def __repr__(self):
215+
return str(self)
216+
206217
@staticmethod
207218
def _hash_categories(categories, ordered=True):
208219
from pandas.core.util.hashing import hash_array, _combine_hash_arrays
@@ -230,10 +241,6 @@ def _get_or_create(cls, categories, ordered, hashed):
230241
cls._cache[(hashed, ordered)] = categorical
231242
return categorical
232243

233-
def __unicode__(self):
234-
tpl = 'CategoricalDtype({!r}, ordered={})'
235-
return tpl.format(self.categories, self.ordered)
236-
237244
@classmethod
238245
def construct_from_string(cls, string):
239246
""" attempt to construct this type from a string, raise a TypeError if

pandas/core/indexes/base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ def _formatter_func(self):
833833
"""
834834
return default_pprint
835835

836-
def _format_data(self):
836+
def _format_data(self, name=None):
837837
"""
838838
Return the formatted data as a unicode string
839839
"""
@@ -842,9 +842,11 @@ def _format_data(self):
842842
display_width, _ = get_console_size()
843843
if display_width is None:
844844
display_width = get_option('display.width') or 80
845+
if name is None:
846+
name = self.__class__.__name__
845847

846-
space1 = "\n%s" % (' ' * (len(self.__class__.__name__) + 1))
847-
space2 = "\n%s" % (' ' * (len(self.__class__.__name__) + 2))
848+
space1 = "\n%s" % (' ' * (len(name) + 1))
849+
space2 = "\n%s" % (' ' * (len(name) + 2))
848850

849851
n = len(self)
850852
sep = ','

0 commit comments

Comments
 (0)