@@ -252,8 +252,15 @@ def _get_formatted_index(self):
252252
253253 def _get_formatted_values (self ):
254254 values_to_format = self .tr_series ._formatting_values ()
255+
256+ if self .index :
257+ leading_space = 'compat'
258+ else :
259+ leading_space = False
255260 return format_array (values_to_format , None ,
256- float_format = self .float_format , na_rep = self .na_rep )
261+ float_format = self .float_format ,
262+ na_rep = self .na_rep ,
263+ leading_space = leading_space )
257264
258265 def to_string (self ):
259266 series = self .tr_series
@@ -703,9 +710,15 @@ def _format_col(self, i):
703710 frame = self .tr_frame
704711 formatter = self ._get_formatter (i )
705712 values_to_format = frame .iloc [:, i ]._formatting_values ()
713+
714+ if self .index :
715+ leading_space = 'compat'
716+ else :
717+ leading_space = False
706718 return format_array (values_to_format , formatter ,
707719 float_format = self .float_format , na_rep = self .na_rep ,
708- space = self .col_space , decimal = self .decimal )
720+ space = self .col_space , decimal = self .decimal ,
721+ leading_space = leading_space )
709722
710723 def to_html (self , classes = None , notebook = False , border = None ):
711724 """
@@ -847,7 +860,7 @@ def _get_column_name_list(self):
847860
848861def format_array (values , formatter , float_format = None , na_rep = 'NaN' ,
849862 digits = None , space = None , justify = 'right' , decimal = '.' ,
850- leading_space = None ):
863+ leading_space = 'compat' ):
851864 """
852865 Format an array for printing.
853866
@@ -861,7 +874,7 @@ def format_array(values, formatter, float_format=None, na_rep='NaN',
861874 space
862875 justify
863876 decimal
864- leading_space : bool, optional
877+ leading_space : bool, default is 'compat'
865878 Whether the array should be formatted with a leading space.
866879 When an array as a column of a Series or DataFrame, we do want
867880 the leading space to pad between columns.
@@ -911,7 +924,7 @@ class GenericArrayFormatter(object):
911924
912925 def __init__ (self , values , digits = 7 , formatter = None , na_rep = 'NaN' ,
913926 space = 12 , float_format = None , justify = 'right' , decimal = '.' ,
914- quoting = None , fixed_width = True , leading_space = None ):
927+ quoting = None , fixed_width = True , leading_space = 'compat' ):
915928 self .values = values
916929 self .digits = digits
917930 self .na_rep = na_rep
@@ -963,12 +976,12 @@ def _format(x):
963976
964977 is_float_type = lib .map_infer (vals , is_float ) & notna (vals )
965978 leading_space = self .leading_space
966- if leading_space is None :
979+ if leading_space == 'compat' :
967980 leading_space = is_float_type .any ()
968981
969982 fmt_values = []
970983 for i , v in enumerate (vals ):
971- if not is_float_type [i ] and leading_space :
984+ if not is_float_type [i ] and leading_space is True :
972985 fmt_values .append (u' {v}' .format (v = _format (v )))
973986 elif is_float_type [i ]:
974987 fmt_values .append (float_format (v ))
@@ -1087,7 +1100,11 @@ def format_values_with(float_format):
10871100 # The default is otherwise to use str instead of a formatting string
10881101 if self .float_format is None :
10891102 if self .fixed_width :
1090- float_format = partial ('{value: .{digits:d}f}' .format ,
1103+ if self .leading_space is not False :
1104+ fmt_str = '{value: .{digits:d}f}'
1105+ else :
1106+ fmt_str = '{value:.{digits:d}f}'
1107+ float_format = partial (fmt_str .format ,
10911108 digits = self .digits )
10921109 else :
10931110 float_format = self .float_format
@@ -1119,7 +1136,11 @@ def format_values_with(float_format):
11191136 (abs_vals > 0 )).any ()
11201137
11211138 if has_small_values or (too_long and has_large_values ):
1122- float_format = partial ('{value: .{digits:d}e}' .format ,
1139+ if self .leading_space is not False :
1140+ fmt_str = '{value: .{digits:d}e}'
1141+ else :
1142+ fmt_str = '{value:.{digits:d}e}'
1143+ float_format = partial (fmt_str .format ,
11231144 digits = self .digits )
11241145 formatted_values = format_values_with (float_format )
11251146
@@ -1136,7 +1157,12 @@ def _format_strings(self):
11361157class IntArrayFormatter (GenericArrayFormatter ):
11371158
11381159 def _format_strings (self ):
1139- formatter = self .formatter or (lambda x : '{x: d}' .format (x = x ))
1160+ if self .leading_space is False :
1161+ fmt_str = '{x:d}'
1162+ else :
1163+ fmt_str = '{x: d}'
1164+ formatter = self .formatter or (lambda x : fmt_str .format (x = x ))
1165+ # formatter = self.formatter or (lambda x: '{x: d}'.format(x=x))
11401166 fmt_values = [formatter (x ) for x in self .values ]
11411167 return fmt_values
11421168
0 commit comments