Permalink
Browse files

BUG: DataFrame column formatting issue in length-truncated column close

  • Loading branch information...
1 parent 82b0d2a commit 67121af2dcaf07acded45c624b25f3292aaf46c4 @wesm wesm committed Sep 13, 2012
Showing with 31 additions and 5 deletions.
  1. +1 −0 RELEASE.rst
  2. +14 −5 pandas/core/format.py
  3. +15 −0 pandas/tests/test_frame.py
  4. +1 −0 pandas/tseries/tests/test_timeseries.py
View
@@ -160,6 +160,7 @@ pandas 0.9.0
window (#1884)
- Fix unicode sheet name failure in to_excel (#1828)
- Override DatetimeIndex.min/max to return Timestamp objects (#1895)
+ - Fix column name formatting issue in length-truncated column (#1906)
pandas 0.8.1
============
View
@@ -219,15 +219,20 @@ def _to_str_columns(self, force_unicode=False):
if self.header:
fmt_values = self._format_col(i)
cheader = str_columns[i]
+
+ max_colwidth = max(_strlen(x) for x in cheader)
+
+ fmt_values = _make_fixed_width(fmt_values, self.justify,
+ minimum=max_colwidth)
+
max_len = max(max(_strlen(x) for x in fmt_values),
- max(len(x) for x in cheader))
+ max_colwidth)
if self.justify == 'left':
cheader = [x.ljust(max_len) for x in cheader]
else:
cheader = [x.rjust(max_len) for x in cheader]
- fmt_values = cheader + fmt_values
- stringified.append(_make_fixed_width(fmt_values,
- self.justify))
+
+ stringified.append(cheader + fmt_values)
else:
stringified = [_make_fixed_width(self._format_col(i),
self.justify)
@@ -704,11 +709,15 @@ def _format_datetime64(x, tz=None):
return stamp._repr_base
-def _make_fixed_width(strings, justify='right'):
+def _make_fixed_width(strings, justify='right', minimum=None):
if len(strings) == 0:
return strings
max_len = max(_strlen(x) for x in strings)
+
+ if minimum is not None:
+ max_len = max(minimum, max_len)
+
conf_max = print_config.max_colwidth
if conf_max is not None and max_len > conf_max:
max_len = conf_max
@@ -2614,6 +2614,21 @@ def test_very_wide_info_repr(self):
columns=[tm.rands(10) for _ in xrange(20)])
repr(df)
+ def test_repr_column_name_unicode_truncation_bug(self):
+ # #1906
+ df = DataFrame({'Id': [7117434],
+ 'StringCol': ('Is it possible to modify drop plot code'
+ ' so that the output graph is displayed '
+ 'in iphone simulator, Is it possible to '
+ 'modify drop plot code so that the '
+ 'output graph is \xe2\x80\xa8displayed '
+ 'in iphone simulator.Now we are adding '
+ 'the CSV file externally. I want to Call'
+ ' the File through the code..')})
+
+ result = repr(df)
+ self.assert_('StringCol' in result)
+
def test_head_tail(self):
assert_frame_equal(self.frame.head(), self.frame[:5])
assert_frame_equal(self.frame.tail(), self.frame[-5:])
@@ -2151,3 +2151,4 @@ def test_hash_equivalent(self):
if __name__ == '__main__':
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
exit=False)
+

0 comments on commit 67121af

Please sign in to comment.