@@ -252,15 +252,15 @@ def _get_formatted_index(self):
252
252
253
253
def _get_formatted_values (self ):
254
254
values_to_format = self .tr_series ._formatting_values ()
255
- if self .index :
256
- return format_array (values_to_format , None ,
257
- float_format = self .float_format ,
258
- na_rep = self .na_rep )
255
+
256
+ if bool (self .index ):
257
+ leading_space = None
259
258
else :
260
- return format_array (values_to_format , None ,
261
- float_format = self .float_format ,
262
- na_rep = self .na_rep ,
263
- leading_space = False )
259
+ leading_space = False
260
+ return format_array (values_to_format , None ,
261
+ float_format = self .float_format ,
262
+ na_rep = self .na_rep ,
263
+ leading_space = leading_space )
264
264
265
265
def to_string (self ):
266
266
series = self .tr_series
@@ -710,9 +710,15 @@ def _format_col(self, i):
710
710
frame = self .tr_frame
711
711
formatter = self ._get_formatter (i )
712
712
values_to_format = frame .iloc [:, i ]._formatting_values ()
713
+
714
+ if bool (self .index ):
715
+ leading_space = None
716
+ else :
717
+ leading_space = False
713
718
return format_array (values_to_format , formatter ,
714
719
float_format = self .float_format , na_rep = self .na_rep ,
715
- space = self .col_space , decimal = self .decimal )
720
+ space = self .col_space , decimal = self .decimal ,
721
+ leading_space = leading_space )
716
722
717
723
def to_html (self , classes = None , notebook = False , border = None ):
718
724
"""
@@ -1087,7 +1093,11 @@ def format_values_with(float_format):
1087
1093
# The default is otherwise to use str instead of a formatting string
1088
1094
if self .float_format is None :
1089
1095
if self .fixed_width :
1090
- float_format = partial ('{value: .{digits:d}f}' .format ,
1096
+ if self .leading_space is not False :
1097
+ fmt_str = '{value: .{digits:d}f}'
1098
+ else :
1099
+ fmt_str = '{value:.{digits:d}f}'
1100
+ float_format = partial (fmt_str .format ,
1091
1101
digits = self .digits )
1092
1102
else :
1093
1103
float_format = self .float_format
@@ -1119,7 +1129,11 @@ def format_values_with(float_format):
1119
1129
(abs_vals > 0 )).any ()
1120
1130
1121
1131
if has_small_values or (too_long and has_large_values ):
1122
- float_format = partial ('{value: .{digits:d}e}' .format ,
1132
+ if self .leading_space is not False :
1133
+ fmt_str = '{value: .{digits:d}e}'
1134
+ else :
1135
+ fmt_str = '{value:.{digits:d}e}'
1136
+ float_format = partial (fmt_str .format ,
1123
1137
digits = self .digits )
1124
1138
formatted_values = format_values_with (float_format )
1125
1139
@@ -1136,7 +1150,12 @@ def _format_strings(self):
1136
1150
class IntArrayFormatter (GenericArrayFormatter ):
1137
1151
1138
1152
def _format_strings (self ):
1139
- formatter = self .formatter or (lambda x : '{x: d}' .format (x = x ))
1153
+ if self .leading_space is False :
1154
+ fmt_str = '{x:d}'
1155
+ else :
1156
+ fmt_str = '{x: d}'
1157
+ formatter = self .formatter or (lambda x : fmt_str .format (x = x ))
1158
+ # formatter = self.formatter or (lambda x: '{x: d}'.format(x=x))
1140
1159
fmt_values = [formatter (x ) for x in self .values ]
1141
1160
return fmt_values
1142
1161
0 commit comments