Skip to content

Commit 16eeb84

Browse files
committed
BUG: unicode and tuple fixes, address GH #138
1 parent afe964b commit 16eeb84

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

pandas/core/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def _pfixed(s, space, nanRep=None, float_format=None):
196196

197197
return formatted.ljust(space)
198198
else:
199-
return (' %s' % s)[:space].ljust(space)
199+
stringified = _stringify(s)
200+
return (' %s' % stringified)[:space].ljust(space)
200201

201202
def _stringify(col):
202203
# unicode workaround
@@ -210,7 +211,7 @@ def _format(s, nanRep=None, float_format=None):
210211
if nanRep is not None and isnull(s):
211212
if np.isnan(s):
212213
s = nanRep
213-
return (' %s' % str(s))
214+
return ' %s' % s
214215

215216
if float_format:
216217
formatted = float_format(s)
@@ -225,7 +226,7 @@ def _format(s, nanRep=None, float_format=None):
225226

226227
return formatted
227228
else:
228-
return ' %s' % str(s)
229+
return ' %s' % _stringify(s)
229230

230231
#-------------------------------------------------------------------------------
231232
# miscellaneous python tools

pandas/tests/test_frame.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,34 @@ def test_repr(self):
11631163
common.set_printoptions(precision=3, column_space=10)
11641164
repr(self.frame)
11651165

1166+
def test_repr_tuples(self):
1167+
buf = StringIO()
1168+
1169+
arr = np.empty(10, dtype=object)
1170+
arr[:] = zip(range(10), range(10))
1171+
df = DataFrame({'tups' : arr})
1172+
repr(df)
1173+
df.to_string(colSpace=10, buf=buf)
1174+
1175+
def test_to_string_unicode(self):
1176+
buf = StringIO()
1177+
1178+
unicode_values = [u'\u03c3'] * 10
1179+
unicode_values = np.array(unicode_values, dtype=object)
1180+
df = DataFrame({'unicode' : unicode_values})
1181+
df.to_string(colSpace=10, buf=buf)
1182+
1183+
def test_to_string_unicode_columns(self):
1184+
df = DataFrame({u'\u03c3' : np.arange(10.)})
1185+
1186+
buf = StringIO()
1187+
df.to_string(buf=buf)
1188+
buf.getvalue()
1189+
1190+
buf = StringIO()
1191+
df.info(buf=buf)
1192+
buf.getvalue()
1193+
11661194
def test_head_tail(self):
11671195
assert_frame_equal(self.frame.head(), self.frame[:5])
11681196
assert_frame_equal(self.frame.tail(), self.frame[-5:])
@@ -1195,17 +1223,6 @@ def test_to_string(self):
11951223
frame = DataFrame(index=np.arange(1000))
11961224
frame.to_string(buf=buf)
11971225

1198-
def test_to_string_unicode_columns(self):
1199-
df = DataFrame({u'\u03c3' : np.arange(10.)})
1200-
1201-
buf = StringIO()
1202-
df.to_string(buf=buf)
1203-
buf.getvalue()
1204-
1205-
buf = StringIO()
1206-
df.info(buf=buf)
1207-
buf.getvalue()
1208-
12091226
def test_insert(self):
12101227
df = DataFrame(np.random.randn(5, 3), index=np.arange(5),
12111228
columns=['c', 'b', 'a'])

0 commit comments

Comments
 (0)