Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 40fa8df

Browse files
authored
Merge pull request #154 from bosd/Various-fixes
Various fixes
2 parents b6a9327 + 7743a17 commit 40fa8df

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

camelot/core.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""Contains the core functions to parse tables from PDFs."""
22

3+
from __future__ import annotations
4+
35
import math
46
import os
57
import sqlite3
68
import tempfile
79
import zipfile
810
from operator import itemgetter
11+
from typing import Iterable
12+
from typing import Iterator
913

1014
import cv2
1115
import pandas as pd
@@ -723,14 +727,11 @@ def to_excel(self, path, **kwargs):
723727
Output filepath.
724728
725729
"""
726-
kw = {
727-
"sheet_name": f"page-{self.page}-table-{self.order}",
728-
"encoding": "utf-8",
729-
}
730+
kw = {"encoding": "utf-8"}
731+
sheet_name = f"page-{self.page}-table-{self.order}"
730732
kw.update(kwargs)
731733
writer = pd.ExcelWriter(path)
732-
self.df.to_excel(writer, **kw)
733-
writer.save()
734+
self.df.to_excel(writer, sheet_name=sheet_name, **kw)
734735

735736
def to_html(self, path, **kwargs):
736737
"""Write Table(s) to an HTML file.
@@ -794,31 +795,34 @@ class TableList:
794795
795796
"""
796797

797-
def __init__(self, tables): # noqa D105
798-
self._tables = tables
798+
def __init__(self, tables: Iterable[Table]) -> None: # noqa D105
799+
self._tables: Iterable[Table] = tables
799800

800801
def __repr__(self): # noqa D105
801802
return f"<{self.__class__.__name__} n={self.n}>"
802803

803804
def __len__(self): # noqa D105
804805
return len(self._tables)
805806

806-
def __getitem__(self, idx): # noqa D105
807+
def __getitem__(self, idx) -> Table: # noqa D105
807808
return self._tables[idx]
808809

809-
def __iter__(self): # noqa D105
810-
yield from self._tables
810+
def __iter__(self) -> Iterator[Table]: # noqa D105
811+
return iter(self._tables)
812+
813+
def __next__(self) -> Table: # noqa D105
814+
return next(self)
811815

812816
@staticmethod
813817
def _format_func(table, f):
814818
return getattr(table, f"to_{f}")
815819

816820
@property
817-
def n(self):
821+
def n(self) -> int:
818822
"""The number of tables in the list."""
819823
return len(self)
820824

821-
def _write_file(self, f=None, **kwargs):
825+
def _write_file(self, f=None, **kwargs) -> None:
822826
dirname = kwargs.get("dirname")
823827
root = kwargs.get("root")
824828
ext = kwargs.get("ext")
@@ -828,7 +832,7 @@ def _write_file(self, f=None, **kwargs):
828832
to_format = self._format_func(table, f)
829833
to_format(filepath)
830834

831-
def _compress_dir(self, **kwargs):
835+
def _compress_dir(self, **kwargs) -> None:
832836
path = kwargs.get("path")
833837
dirname = kwargs.get("dirname")
834838
root = kwargs.get("root")

0 commit comments

Comments
 (0)