Skip to content

Commit 02cb4da

Browse files
committed
BUG/OFMT: fix spurious tuple repring of bytes types in python 3
1 parent 218ba11 commit 02cb4da

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ pandas 0.13
119119
called using the top level matplotlib API (:issue:`4408`)
120120
- Fixed a bug where calling ``Series.astype(str)`` would truncate the string
121121
(:issue:`4405`, :issue:`4437`)
122+
- Fixed a py3 compat issue where bytes were being repr'd as tuples
123+
(:issue:`4455`)
122124

123125
pandas 0.12
124126
===========

pandas/core/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,8 @@ def _is_sequence(x):
16131613
try:
16141614
iter(x)
16151615
len(x) # it has a length
1616-
return not isinstance(x, compat.string_types) and True
1616+
return not isinstance(x, compat.string_types +
1617+
(compat.binary_type,)) and True
16171618
except Exception:
16181619
return False
16191620

@@ -2053,8 +2054,7 @@ def as_escaped_unicode(thing,escape_chars=escape_chars):
20532054

20542055
return compat.text_type(result)
20552056

2056-
if (compat.PY3 and hasattr(thing, '__next__')) or \
2057-
hasattr(thing, 'next'):
2057+
if (compat.PY3 and hasattr(thing, '__next__')) or hasattr(thing, 'next'):
20582058
return compat.text_type(thing)
20592059
elif (isinstance(thing, dict) and
20602060
_nest_lvl < get_option("display.pprint_nest_depth")):

pandas/tests/test_common.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from datetime import datetime
2-
import sys
32
import re
43

54
import nose
5+
from nose.tools import assert_equal
66
import unittest
77

88
from pandas import Series, DataFrame, date_range, DatetimeIndex, Timestamp
9-
from pandas.compat import range, long, lrange, lmap, u, map
9+
from pandas.compat import range, long, lrange, lmap, u
1010
from pandas.core.common import notnull, isnull
1111
import pandas.core.common as com
1212
import pandas.util.testing as tm
@@ -147,6 +147,21 @@ def test_all_not_none():
147147
assert(not com._all_not_none(None, None, None, None))
148148

149149

150+
def test_repr_binary_type():
151+
import string
152+
letters = string.ascii_letters
153+
btype = compat.binary_type
154+
try:
155+
raw = btype(letters, encoding=cf.get_option('display.encoding'))
156+
except TypeError:
157+
raw = btype(letters)
158+
b = compat.text_type(compat.bytes_to_str(raw))
159+
res = com.pprint_thing(b, quote_strings=True)
160+
assert_equal(res, repr(b))
161+
res = com.pprint_thing(b, quote_strings=False)
162+
assert_equal(res, b)
163+
164+
150165
def test_rands():
151166
r = com.rands(10)
152167
assert(len(r) == 10)

0 commit comments

Comments
 (0)