Skip to content

Commit c23c130

Browse files
simonjayhawkinsjreback
authored andcommitted
TYPING: type hints for io.formats.latex (#27734)
1 parent 66ada8c commit c23c130

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

pandas/io/formats/latex.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""
22
Module for formatting output data in Latex.
33
"""
4+
from typing import IO, List, Optional, Tuple
5+
46
import numpy as np
57

68
from pandas.core.dtypes.generic import ABCMultiIndex
79

8-
from pandas.io.formats.format import TableFormatter
10+
from pandas.io.formats.format import DataFrameFormatter, TableFormatter
911

1012

1113
class LatexFormatter(TableFormatter):
@@ -28,12 +30,12 @@ class LatexFormatter(TableFormatter):
2830

2931
def __init__(
3032
self,
31-
formatter,
32-
column_format=None,
33-
longtable=False,
34-
multicolumn=False,
35-
multicolumn_format=None,
36-
multirow=False,
33+
formatter: DataFrameFormatter,
34+
column_format: Optional[str] = None,
35+
longtable: bool = False,
36+
multicolumn: bool = False,
37+
multicolumn_format: Optional[str] = None,
38+
multirow: bool = False,
3739
):
3840
self.fmt = formatter
3941
self.frame = self.fmt.frame
@@ -44,7 +46,7 @@ def __init__(
4446
self.multicolumn_format = multicolumn_format
4547
self.multirow = multirow
4648

47-
def write_result(self, buf):
49+
def write_result(self, buf: IO[str]) -> None:
4850
"""
4951
Render a DataFrame to a LaTeX tabular/longtable environment output.
5052
"""
@@ -124,7 +126,7 @@ def pad_empties(x):
124126
if self.fmt.has_index_names and self.fmt.show_index_names:
125127
nlevels += 1
126128
strrows = list(zip(*strcols))
127-
self.clinebuf = []
129+
self.clinebuf = [] # type: List[List[int]]
128130

129131
for i, row in enumerate(strrows):
130132
if i == nlevels and self.fmt.header:
@@ -186,7 +188,7 @@ def pad_empties(x):
186188
else:
187189
buf.write("\\end{longtable}\n")
188190

189-
def _format_multicolumn(self, row, ilevels):
191+
def _format_multicolumn(self, row: List[str], ilevels: int) -> List[str]:
190192
r"""
191193
Combine columns belonging to a group to a single multicolumn entry
192194
according to self.multicolumn_format
@@ -227,7 +229,9 @@ def append_col():
227229
append_col()
228230
return row2
229231

230-
def _format_multirow(self, row, ilevels, i, rows):
232+
def _format_multirow(
233+
self, row: List[str], ilevels: int, i: int, rows: List[Tuple[str, ...]]
234+
) -> List[str]:
231235
r"""
232236
Check following rows, whether row should be a multirow
233237
@@ -254,7 +258,7 @@ def _format_multirow(self, row, ilevels, i, rows):
254258
self.clinebuf.append([i + nrow - 1, j + 1])
255259
return row
256260

257-
def _print_cline(self, buf, i, icol):
261+
def _print_cline(self, buf: IO[str], i: int, icol: int) -> None:
258262
"""
259263
Print clines after multirow-blocks are finished
260264
"""

0 commit comments

Comments
 (0)