Skip to content

Commit d968508

Browse files
author
y-p
committed
TST: repr() should return type str() on py2 and py3
1 parent 7567b65 commit d968508

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pandas/tests/test_format.py

+15
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ def test_repr_truncation(self):
8282
fmt.print_config.max_colwidth = max_len + 2
8383
self.assert_('...' not in repr(df))
8484

85+
def test_repr_should_return_str (self):
86+
"""
87+
http://docs.python.org/py3k/reference/datamodel.html#object.__repr__
88+
http://docs.python.org/reference/datamodel.html#object.__repr__
89+
"...The return value must be a string object."
90+
91+
(str on py2.x, str (unicode) on py3)
92+
93+
"""
94+
data=[8,5,3,5]
95+
index1=[u"\u03c3",u"\u03c4",u"\u03c5",u"\u03c6"]
96+
cols=[u"\u03c8"]
97+
df=DataFrame(data,columns=cols,index=index1)
98+
self.assertTrue(type(df.__repr__() == str)) # both py2 / 3
99+
85100
def test_to_string_repr_unicode(self):
86101
buf = StringIO()
87102

pandas/tests/test_series.py

+14
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,20 @@ def test_repr_name_iterable_indexable(self):
10571057
s.name = (u"\u05d0",) * 2
10581058
repr(s)
10591059

1060+
def test_repr_should_return_str (self):
1061+
"""
1062+
http://docs.python.org/py3k/reference/datamodel.html#object.__repr__
1063+
http://docs.python.org/reference/datamodel.html#object.__repr__
1064+
"...The return value must be a string object."
1065+
1066+
(str on py2.x, str (unicode) on py3)
1067+
1068+
"""
1069+
data=[8,5,3,5]
1070+
index1=[u"\u03c3",u"\u03c4",u"\u03c5",u"\u03c6"]
1071+
df=Series(data,index=index1)
1072+
self.assertTrue(type(df.__repr__() == str)) # both py2 / 3
1073+
10601074
def test_timeseries_repr_object_dtype(self):
10611075
index = Index([datetime(2000, 1, 1) + timedelta(i)
10621076
for i in range(1000)], dtype=object)

0 commit comments

Comments
 (0)