Skip to content

Commit 6c8bf33

Browse files
committed
ran black on latex.py and test_to_latex.py (pandas-dev#25436)
1 parent bf34040 commit 6c8bf33

File tree

2 files changed

+27
-47
lines changed

2 files changed

+27
-47
lines changed

pandas/io/formats/latex.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def pad_empties(x):
121121
else:
122122
self._write_tabular_begin(buf, column_format)
123123

124-
buf.write('\\toprule\n')
124+
buf.write("\\toprule\n")
125125

126126
ilevels = self.frame.index.nlevels
127127
clevels = self.frame.columns.nlevels
@@ -287,24 +287,21 @@ def _write_tabular_begin(self, buf, column_format):
287287
if self.caption is not None or self.label is not None:
288288
# then write output in a nested table/tabular environment
289289
if self.caption is None:
290-
caption_ = ''
290+
caption_ = ""
291291
else:
292-
caption_ = '\n\\caption{{{}}}'.format(self.caption)
292+
caption_ = "\n\\caption{{{}}}".format(self.caption)
293293

294294
if self.label is None:
295-
label_ = ''
295+
label_ = ""
296296
else:
297-
label_ = '\n\\label{{{}}}'.format(self.label)
297+
label_ = "\n\\label{{{}}}".format(self.label)
298298

299-
buf.write('\\begin{{table}}\n\\centering{}{}\n'.format(
300-
caption_,
301-
label_
302-
))
299+
buf.write("\\begin{{table}}\n\\centering{}{}\n".format(caption_, label_))
303300
else:
304301
# then write output only in a tabular environment
305302
pass
306303

307-
buf.write('\\begin{{tabular}}{{{fmt}}}\n'.format(fmt=column_format))
304+
buf.write("\\begin{{tabular}}{{{fmt}}}\n".format(fmt=column_format))
308305

309306
def _write_tabular_end(self, buf):
310307
"""
@@ -318,10 +315,10 @@ def _write_tabular_end(self, buf):
318315
a string.
319316
320317
"""
321-
buf.write('\\bottomrule\n')
322-
buf.write('\\end{tabular}\n')
318+
buf.write("\\bottomrule\n")
319+
buf.write("\\end{tabular}\n")
323320
if self.caption is not None or self.label is not None:
324-
buf.write('\\end{table}\n')
321+
buf.write("\\end{table}\n")
325322
else:
326323
pass
327324

@@ -341,23 +338,23 @@ def _write_longtable_begin(self, buf, column_format):
341338
for 3 columns
342339
343340
"""
344-
buf.write('\\begin{{longtable}}{{{fmt}}}\n'.format(fmt=column_format))
341+
buf.write("\\begin{{longtable}}{{{fmt}}}\n".format(fmt=column_format))
345342

346343
if self.caption is not None or self.label is not None:
347344
if self.caption is None:
348345
pass
349346
else:
350-
buf.write('\\caption{{{}}}'.format(self.caption))
347+
buf.write("\\caption{{{}}}".format(self.caption))
351348

352349
if self.label is None:
353350
pass
354351
else:
355-
buf.write('\\label{{{}}}'.format(self.label))
352+
buf.write("\\label{{{}}}".format(self.label))
356353

357354
# a double-backslash is required at the end of the line
358355
# as discussed here:
359356
# https://tex.stackexchange.com/questions/219138
360-
buf.write('\\\\\n')
357+
buf.write("\\\\\n")
361358
else:
362359
pass
363360

@@ -373,4 +370,4 @@ def _write_longtable_end(buf):
373370
a string.
374371
375372
"""
376-
buf.write('\\end{longtable}\n')
373+
buf.write("\\end{longtable}\n")

pandas/tests/io/formats/test_to_latex.py

+12-29
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,13 @@ def test_to_latex_longtable(self):
440440

441441
def test_to_latex_caption_label(self):
442442
# GH 25436
443-
the_caption = 'a table in a \\texttt{table/tabular} environment'
444-
the_label = 'tab:table_tabular'
443+
the_caption = "a table in a \\texttt{table/tabular} environment"
444+
the_label = "tab:table_tabular"
445445

446-
df = DataFrame({'a': [1, 2], 'b': ['b1', 'b2']})
446+
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
447447

448448
# test when only the caption is provided
449-
result_c = df.to_latex(
450-
caption=the_caption
451-
)
449+
result_c = df.to_latex(caption=the_caption)
452450

453451
expected_c = r"""\begin{table}
454452
\centering
@@ -466,9 +464,7 @@ def test_to_latex_caption_label(self):
466464
assert result_c == expected_c
467465

468466
# test when only the label is provided
469-
result_l = df.to_latex(
470-
label=the_label
471-
)
467+
result_l = df.to_latex(label=the_label)
472468

473469
expected_l = r"""\begin{table}
474470
\centering
@@ -486,10 +482,7 @@ def test_to_latex_caption_label(self):
486482
assert result_l == expected_l
487483

488484
# test when the caption and the label are provided
489-
result_cl = df.to_latex(
490-
caption=the_caption,
491-
label=the_label
492-
)
485+
result_cl = df.to_latex(caption=the_caption, label=the_label)
493486

494487
expected_cl = r"""\begin{table}
495488
\centering
@@ -509,16 +502,13 @@ def test_to_latex_caption_label(self):
509502

510503
def test_to_latex_longtable_caption_label(self):
511504
# GH 25436
512-
the_caption = 'a table in a \\texttt{longtable} environment'
513-
the_label = 'tab:longtable'
505+
the_caption = "a table in a \\texttt{longtable} environment"
506+
the_label = "tab:longtable"
514507

515-
df = DataFrame({'a': [1, 2], 'b': ['b1', 'b2']})
508+
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
516509

517510
# test when only the caption is provided
518-
result_c = df.to_latex(
519-
longtable=True,
520-
caption=the_caption
521-
)
511+
result_c = df.to_latex(longtable=True, caption=the_caption)
522512

523513
expected_c = r"""\begin{longtable}{lrl}
524514
\caption{a table in a \texttt{longtable} environment}\\
@@ -540,10 +530,7 @@ def test_to_latex_longtable_caption_label(self):
540530
assert result_c == expected_c
541531

542532
# test when only the label is provided
543-
result_l = df.to_latex(
544-
longtable=True,
545-
label=the_label,
546-
)
533+
result_l = df.to_latex(longtable=True, label=the_label)
547534

548535
expected_l = r"""\begin{longtable}{lrl}
549536
\label{tab:longtable}\\
@@ -565,11 +552,7 @@ def test_to_latex_longtable_caption_label(self):
565552
assert result_l == expected_l
566553

567554
# test when the caption and the label are provided
568-
result_cl = df.to_latex(
569-
longtable=True,
570-
caption=the_caption,
571-
label=the_label,
572-
)
555+
result_cl = df.to_latex(longtable=True, caption=the_caption, label=the_label)
573556

574557
expected_cl = r"""\begin{longtable}{lrl}
575558
\caption{a table in a \texttt{longtable} environment}\label{tab:longtable}\\

0 commit comments

Comments
 (0)