Skip to content

TYPING: type hints for io.formats.latex #27734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions pandas/io/formats/latex.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
Module for formatting output data in Latex.
"""
from typing import IO, List, Optional, Tuple

import numpy as np

from pandas.core.dtypes.generic import ABCMultiIndex

from pandas.io.formats.format import TableFormatter
from pandas.io.formats.format import DataFrameFormatter, TableFormatter


class LatexFormatter(TableFormatter):
Expand All @@ -28,12 +30,12 @@ class LatexFormatter(TableFormatter):

def __init__(
self,
formatter,
column_format=None,
longtable=False,
multicolumn=False,
multicolumn_format=None,
multirow=False,
formatter: DataFrameFormatter,
column_format: Optional[str] = None,
longtable: bool = False,
multicolumn: bool = False,
multicolumn_format: Optional[str] = None,
multirow: bool = False,
):
self.fmt = formatter
self.frame = self.fmt.frame
Expand All @@ -44,7 +46,7 @@ def __init__(
self.multicolumn_format = multicolumn_format
self.multirow = multirow

def write_result(self, buf):
def write_result(self, buf: IO[str]) -> None:
"""
Render a DataFrame to a LaTeX tabular/longtable environment output.
"""
Expand Down Expand Up @@ -124,7 +126,7 @@ def pad_empties(x):
if self.fmt.has_index_names and self.fmt.show_index_names:
nlevels += 1
strrows = list(zip(*strcols))
self.clinebuf = []
self.clinebuf = [] # type: List[List[int]]

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

def _format_multicolumn(self, row, ilevels):
def _format_multicolumn(self, row: List[str], ilevels: int) -> List[str]:
r"""
Combine columns belonging to a group to a single multicolumn entry
according to self.multicolumn_format
Expand Down Expand Up @@ -227,7 +229,9 @@ def append_col():
append_col()
return row2

def _format_multirow(self, row, ilevels, i, rows):
def _format_multirow(
self, row: List[str], ilevels: int, i: int, rows: List[Tuple[str, ...]]
) -> List[str]:
r"""
Check following rows, whether row should be a multirow

Expand All @@ -254,7 +258,7 @@ def _format_multirow(self, row, ilevels, i, rows):
self.clinebuf.append([i + nrow - 1, j + 1])
return row

def _print_cline(self, buf, i, icol):
def _print_cline(self, buf: IO[str], i: int, icol: int) -> None:
"""
Print clines after multirow-blocks are finished
"""
Expand Down