Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 67121af2dcaf07acded45c624b25f3292aaf46c4 1 parent 82b0d2a
Wes McKinney authored September 12, 2012
1  RELEASE.rst
Source Rendered
@@ -160,6 +160,7 @@ pandas 0.9.0
160 160
     window (#1884)
161 161
   - Fix unicode sheet name failure in to_excel (#1828)
162 162
   - Override DatetimeIndex.min/max to return Timestamp objects (#1895)
  163
+  - Fix column name formatting issue in length-truncated column (#1906)
163 164
 
164 165
 pandas 0.8.1
165 166
 ============
19  pandas/core/format.py
@@ -219,15 +219,20 @@ def _to_str_columns(self, force_unicode=False):
219 219
             if self.header:
220 220
                 fmt_values = self._format_col(i)
221 221
                 cheader = str_columns[i]
  222
+
  223
+                max_colwidth = max(_strlen(x) for x in cheader)
  224
+
  225
+                fmt_values = _make_fixed_width(fmt_values, self.justify,
  226
+                                               minimum=max_colwidth)
  227
+
222 228
                 max_len = max(max(_strlen(x) for x in fmt_values),
223  
-                              max(len(x) for x in cheader))
  229
+                              max_colwidth)
224 230
                 if self.justify == 'left':
225 231
                     cheader = [x.ljust(max_len) for x in cheader]
226 232
                 else:
227 233
                     cheader = [x.rjust(max_len) for x in cheader]
228  
-                fmt_values = cheader + fmt_values
229  
-                stringified.append(_make_fixed_width(fmt_values,
230  
-                                                     self.justify))
  234
+
  235
+                stringified.append(cheader + fmt_values)
231 236
             else:
232 237
                 stringified = [_make_fixed_width(self._format_col(i),
233 238
                                                  self.justify)
@@ -704,11 +709,15 @@ def _format_datetime64(x, tz=None):
704 709
     return stamp._repr_base
705 710
 
706 711
 
707  
-def _make_fixed_width(strings, justify='right'):
  712
+def _make_fixed_width(strings, justify='right', minimum=None):
708 713
     if len(strings) == 0:
709 714
         return strings
710 715
 
711 716
     max_len = max(_strlen(x) for x in strings)
  717
+
  718
+    if minimum is not None:
  719
+        max_len = max(minimum, max_len)
  720
+
712 721
     conf_max = print_config.max_colwidth
713 722
     if conf_max is not None and max_len > conf_max:
714 723
         max_len = conf_max
15  pandas/tests/test_frame.py
@@ -2614,6 +2614,21 @@ def test_very_wide_info_repr(self):
2614 2614
                        columns=[tm.rands(10) for _ in xrange(20)])
2615 2615
         repr(df)
2616 2616
 
  2617
+    def test_repr_column_name_unicode_truncation_bug(self):
  2618
+        # #1906
  2619
+        df = DataFrame({'Id': [7117434],
  2620
+                        'StringCol': ('Is it possible to modify drop plot code'
  2621
+                                      ' so that the output graph is displayed '
  2622
+                                      'in iphone simulator, Is it possible to '
  2623
+                                      'modify drop plot code so that the '
  2624
+                                      'output graph is \xe2\x80\xa8displayed '
  2625
+                                      'in iphone simulator.Now we are adding '
  2626
+                                      'the CSV file externally. I want to Call'
  2627
+                                      ' the File through the code..')})
  2628
+
  2629
+        result = repr(df)
  2630
+        self.assert_('StringCol' in result)
  2631
+
2617 2632
     def test_head_tail(self):
2618 2633
         assert_frame_equal(self.frame.head(), self.frame[:5])
2619 2634
         assert_frame_equal(self.frame.tail(), self.frame[-5:])
1  pandas/tseries/tests/test_timeseries.py
@@ -2151,3 +2151,4 @@ def test_hash_equivalent(self):
2151 2151
 if __name__ == '__main__':
2152 2152
     nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
2153 2153
                    exit=False)
  2154
+

0 notes on commit 67121af

Please sign in to comment.
Something went wrong with that request. Please try again.