Skip to content

Commit c4327b7

Browse files
remove leading space
1 parent 1314059 commit c4327b7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pandas/io/formats/format.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,13 @@ def _get_formatted_index(self):
252252

253253
def _get_formatted_values(self):
254254
values_to_format = self.tr_series._formatting_values()
255-
return format_array(values_to_format, None,
256-
float_format=self.float_format, na_rep=self.na_rep)
255+
if self.index:
256+
return format_array(values_to_format, None,
257+
float_format=self.float_format, na_rep=self.na_rep)
258+
else:
259+
return format_array(values_to_format, None,
260+
float_format=self.float_format, na_rep=self.na_rep,
261+
leading_space=False)
257262

258263
def to_string(self):
259264
series = self.tr_series

pandas/tests/io/formats/test_format.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,3 +2729,13 @@ def test_format_percentiles():
27292729
fmt.format_percentiles([2, 0.1, 0.5])
27302730
with pytest.raises(ValueError, match=msg):
27312731
fmt.format_percentiles([0.1, 0.5, 'a'])
2732+
2733+
2734+
@pytest.mark.parametrize("input_array, expected", [
2735+
("a", "a"),
2736+
(["a", "b"], "a\nb")
2737+
])
2738+
def test_format_remove_leading_space(input_array, expected):
2739+
# GH: 24980
2740+
s = pd.Series(input_array).to_string(index=False)
2741+
assert s == expected

0 commit comments

Comments
 (0)