File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -356,7 +356,10 @@ def get_col_type(dtype):
356
356
357
357
if column_format is None :
358
358
dtypes = self .frame .dtypes .values
359
- column_format = 'l%s' % '' .join (map (get_col_type , dtypes ))
359
+ if self .index :
360
+ column_format = 'l%s' % '' .join (map (get_col_type , dtypes ))
361
+ else :
362
+ column_format = '%s' % '' .join (map (get_col_type , dtypes ))
360
363
elif not isinstance (column_format , basestring ):
361
364
raise AssertionError (('column_format must be str or unicode, not %s'
362
365
% type (column_format )))
Original file line number Diff line number Diff line change @@ -1355,6 +1355,31 @@ def test_to_latex(self):
1355
1355
# it works!
1356
1356
self .frame .to_latex ()
1357
1357
1358
+ df = DataFrame ({'a' : [1 , 2 ],
1359
+ 'b' : ['b1' , 'b2' ]})
1360
+ withindex_result = df .to_latex ()
1361
+ withindex_expected = r"""\begin{tabular}{lrl}
1362
+ \toprule
1363
+ {} & a & b \\
1364
+ \midrule
1365
+ 0 & 1 & b1 \\
1366
+ 1 & 2 & b2 \\
1367
+ \bottomrule
1368
+ \end{tabular}
1369
+ """
1370
+ self .assertEqual (withindex_result , withindex_expected )
1371
+
1372
+ withoutindex_result = df .to_latex (index = False )
1373
+ withoutindex_expected = r"""\begin{tabular}{rl}
1374
+ \toprule
1375
+ a & b \\
1376
+ \midrule
1377
+ 1 & b1 \\
1378
+ 2 & b2 \\
1379
+ \bottomrule
1380
+ \end{tabular}
1381
+ """
1382
+ self .assertEqual (withoutindex_result , withoutindex_expected )
1358
1383
1359
1384
class TestSeriesFormatting (unittest .TestCase ):
1360
1385
_multiprocess_can_split_ = True
You can’t perform that action at this time.
0 commit comments