Skip to content

Commit 221cee9

Browse files
committed
use repr
1 parent e5f6976 commit 221cee9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

pandas/core/arrays/base.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def __repr__(self):
661661
from pandas.io.formats.printing import format_object_summary
662662

663663
template = (
664-
u'<{class_name}>\n'
664+
u'{class_name}'
665665
u'{data}\n'
666666
u'Length: {length}, dtype: {dtype}'
667667
)
@@ -670,11 +670,17 @@ def __repr__(self):
670670
# any trailing newlines from format_object_summary
671671
data = format_object_summary(self, self._formatter(), name=False,
672672
trailing_comma=False).rstrip()
673-
name = self.__class__.__name__
674-
return template.format(class_name=name, data=data,
673+
class_name = u'<{}>\n'.format(self.__class__.__name__)
674+
return template.format(class_name=class_name, data=data,
675675
length=len(self),
676676
dtype=self.dtype)
677677

678+
def __bytes__(self):
679+
from pandas.core.config import get_option
680+
681+
encoding = get_option("display.encoding")
682+
return str(self).encode(encoding, 'replace')
683+
678684
def _formatter(self, formatter=None):
679685
# type: (Optional[ExtensionArrayFormatter]) -> Callable[[Any], str]
680686
"""Formatting function for scalar values.
@@ -705,7 +711,12 @@ def _formatter(self, formatter=None):
705711
def _formatting_values(self):
706712
# type: () -> np.ndarray
707713
# At the moment, this has to be an array since we use result.dtype
708-
"""An array of values to be printed in, e.g. the Series repr"""
714+
"""An array of values to be printed in, e.g. the Series repr
715+
716+
.. deprecated:: 0.24.0
717+
718+
Use :meth:`ExtensionArray._formatter` instead.
719+
"""
709720
return np.array(self)
710721

711722
# ------------------------------------------------------------------------

pandas/core/arrays/categorical.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def _constructor(self):
499499
def _from_sequence(cls, scalars, dtype=None, copy=False):
500500
return Categorical(scalars, dtype=dtype)
501501

502-
def _formatter(self, formatter):
502+
def _formatter(self, formatter=None):
503503
# backwards compat with old printing.
504504
return None
505505

@@ -1990,6 +1990,9 @@ def __unicode__(self):
19901990

19911991
return result
19921992

1993+
def __repr__(self):
1994+
return super(ExtensionArray, self).__repr__()
1995+
19931996
def _maybe_coerce_indexer(self, indexer):
19941997
""" return an indexer coerced to the codes dtype """
19951998
if isinstance(indexer, np.ndarray) and indexer.dtype.kind == 'i':

0 commit comments

Comments
 (0)