@@ -1292,15 +1292,15 @@ def test_to_string_no_index(self):
12921292
12931293 df_s = df .to_string (index = False )
12941294 # Leading space is expected for positive numbers.
1295- expected = (" x y z\n "
1296- " 11 33 AAA\n "
1297- " 22 -44 " )
1295+ expected = (" x y z\n "
1296+ "11 33 AAA\n "
1297+ "22 -44 " )
12981298 assert df_s == expected
12991299
13001300 df_s = df [['y' , 'x' , 'z' ]].to_string (index = False )
1301- expected = (" y x z\n "
1302- " 33 11 AAA\n "
1303- "-44 22 " )
1301+ expected = (" y x z\n "
1302+ " 33 11 AAA\n "
1303+ "-44 22 " )
13041304 assert df_s == expected
13051305
13061306 def test_to_string_line_width_no_index (self ):
@@ -1315,7 +1315,7 @@ def test_to_string_line_width_no_index(self):
13151315 df = DataFrame ({'x' : [11 , 22 , 33 ], 'y' : [4 , 5 , 6 ]})
13161316
13171317 df_s = df .to_string (line_width = 1 , index = False )
1318- expected = " x \\ \n 11 \n 22 \n 33 \n \n y \n 4 \n 5 \n 6 "
1318+ expected = " x \\ \n 11 \n 22 \n 33 \n \n y \n 4 \n 5 \n 6 "
13191319
13201320 assert df_s == expected
13211321
@@ -1888,7 +1888,7 @@ def test_to_string_without_index(self):
18881888 # GH 11729 Test index=False option
18891889 s = Series ([1 , 2 , 3 , 4 ])
18901890 result = s .to_string (index = False )
1891- expected = (u (' 1\n ' ) + ' 2\n ' + ' 3\n ' + ' 4' )
1891+ expected = (u ('1\n ' ) + '2\n ' + '3\n ' + '4' )
18921892 assert result == expected
18931893
18941894 def test_unicode_name_in_footer (self ):
@@ -2380,6 +2380,15 @@ def test_to_string_header(self):
23802380 exp = '0 0\n ..\n 9 9'
23812381 assert res == exp
23822382
2383+ @pytest .mark .parametrize ("inputs, expected" , [
2384+ ([' a' , ' b' ], ' a\n b' ),
2385+ (['.1' , '1' ], '.1\n 1' ),
2386+ (['10' , '-10' ], ' 10\n -10' )
2387+ ])
2388+ def test_to_string_index_false_corner_case (self , inputs , expected ):
2389+ s = pd .Series (inputs ).to_string (index = False )
2390+ assert s == expected
2391+
23832392
23842393def _three_digit_exp ():
23852394 return '{x:.4g}' .format (x = 1.7e8 ) == '1.7e+008'
@@ -2780,6 +2789,31 @@ def test_format_percentiles():
27802789 fmt .format_percentiles ([0.1 , 0.5 , 'a' ])
27812790
27822791
2792+ @pytest .mark .parametrize ("input_array, expected" , [
2793+ ("a" , "a" ),
2794+ (["a" , "b" ], "a\n b" ),
2795+ ([1 , "a" ], "1\n a" ),
2796+ (1 , "1" ),
2797+ ([0 , - 1 ], " 0\n -1" ),
2798+ (1.0 , '1.0' )
2799+ ])
2800+ def test_format_remove_leading_space_series (input_array , expected ):
2801+ # GH: 24980
2802+ s = pd .Series (input_array ).to_string (index = False )
2803+ assert s == expected
2804+
2805+
2806+ @pytest .mark .parametrize ("input_array, expected" , [
2807+ ({"A" : ["a" ]}, "A\n a" ),
2808+ ({"A" : ["a" , "b" ], "B" : ["c" , "dd" ]}, "A B\n a c\n b dd" ),
2809+ ({"A" : ["a" , 1 ], "B" : ["aa" , 1 ]}, "A B\n a aa\n 1 1" )
2810+ ])
2811+ def test_format_remove_leading_space_dataframe (input_array , expected ):
2812+ # GH: 24980
2813+ df = pd .DataFrame (input_array ).to_string (index = False )
2814+ assert df == expected
2815+
2816+
27832817def test_repr_html_ipython_config (ip ):
27842818 code = textwrap .dedent ("""\
27852819 import pandas as pd
0 commit comments