Skip to content

Commit 9871550

Browse files
all in one
1 parent 6449bc1 commit 9871550

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pandas/io/formats/format.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -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-
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,
258+
na_rep=self.na_rep)
259+
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)
257264

258265
def to_string(self):
259266
series = self.tr_series

pandas/tests/io/formats/test_format.py

+10
Original file line numberDiff line numberDiff line change
@@ -2777,3 +2777,13 @@ def test_format_percentiles():
27772777
fmt.format_percentiles([2, 0.1, 0.5])
27782778
with pytest.raises(ValueError, match=msg):
27792779
fmt.format_percentiles([0.1, 0.5, 'a'])
2780+
2781+
2782+
@pytest.mark.parametrize("input_array, expected", [
2783+
("a", "a"),
2784+
(["a", "b"], "a\nb")
2785+
])
2786+
def test_format_remove_leading_space(input_array, expected):
2787+
# GH: 24980
2788+
s = pd.Series(input_array).to_string(index=False)
2789+
assert s == expected

0 commit comments

Comments
 (0)