Skip to content

Commit 445736d

Browse files
committed
unicode, bytes
1 parent b312fe4 commit 445736d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pandas/core/arrays/base.py

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import operator
1111

12+
from pandas import compat
13+
from pandas.core.config import get_option
1214
from pandas.core.dtypes.generic import ABCSeries, ABCIndexClass
1315
from pandas.errors import AbstractMethodError
1416
from pandas.compat.numpy import function as nv
@@ -662,6 +664,19 @@ def copy(self, deep=False):
662664
# ------------------------------------------------------------------------
663665
# Printing
664666
# ------------------------------------------------------------------------
667+
def __unicode__(self):
668+
result = str(self)
669+
if compat.PY2:
670+
encoding = get_option("display.encoding")
671+
result = result.decode(encoding)
672+
return result
673+
674+
def __bytes__(self):
675+
result = str(self)
676+
if compat.PY3:
677+
encoding = get_option("display.encoding")
678+
result = result.encode(encoding)
679+
return result
665680

666681
def __repr__(self):
667682
from pandas.io.formats.printing import format_object_summary

pandas/tests/extension/base/printing.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import io
22

33
import pandas as pd
4+
from pandas import compat
45
import pytest
56

67
from .base import BaseExtensionTests
@@ -23,6 +24,17 @@ def test_array_repr(self, data, size):
2324
if size == 'big':
2425
assert '...' in result
2526

27+
def test_array_repr_bytes(self, data):
28+
result = bytes(data)
29+
if compat.PY2:
30+
assert isinstance(result, str)
31+
else:
32+
assert isinstance(result, bytes)
33+
34+
def test_array_repr_unicode(self, data):
35+
result = compat.u(data)
36+
assert isinstance(result, compat.text_type)
37+
2638
def test_series_repr(self, data):
2739
ser = pd.Series(data)
2840
assert data.dtype.name in repr(ser)

0 commit comments

Comments
 (0)