Fix type annotations for 3.8.
This commit is contained in:
parent
e6e32f9108
commit
6c61b8c2cc
|
|
@ -1,14 +1,14 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import Any, Iterator, Union
|
from typing import Any, Dict, Iterator, List, Union
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from .utils import sanitize_df
|
from .utils import sanitize_df
|
||||||
|
|
||||||
|
|
||||||
def get_columns_from_headers(backend: ModuleType, row: Any) -> list[str]:
|
def get_columns_from_headers(backend: ModuleType, row: Any) -> List[str]:
|
||||||
repeat_until = -1
|
repeat_until = -1
|
||||||
repeat_value = None
|
repeat_value = None
|
||||||
# columns as lists in a dictionary
|
# columns as lists in a dictionary
|
||||||
|
|
@ -36,11 +36,11 @@ def get_columns_from_headers(backend: ModuleType, row: Any) -> list[str]:
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
|
|
||||||
def get_generic_columns(row: Any) -> list[str]:
|
def get_generic_columns(row: Any) -> List[str]:
|
||||||
return [f"column.{j}" for j in range(len(row))]
|
return [f"column.{j}" for j in range(len(row))]
|
||||||
|
|
||||||
|
|
||||||
def get_columns(backend: ModuleType, row: Any, headers: bool) -> list[str]:
|
def get_columns(backend: ModuleType, row: Any, headers: bool) -> List[str]:
|
||||||
if headers:
|
if headers:
|
||||||
return get_columns_from_headers(backend, row)
|
return get_columns_from_headers(backend, row)
|
||||||
return get_generic_columns(row)
|
return get_generic_columns(row)
|
||||||
|
|
@ -48,13 +48,13 @@ def get_columns(backend: ModuleType, row: Any, headers: bool) -> list[str]:
|
||||||
|
|
||||||
def parse_data(
|
def parse_data(
|
||||||
backend: ModuleType,
|
backend: ModuleType,
|
||||||
rows: Iterator[list[Any]],
|
rows: Iterator[List[Any]],
|
||||||
headers: bool,
|
headers: bool,
|
||||||
columns: list[str],
|
columns: List[str],
|
||||||
skiprows: int,
|
skiprows: int,
|
||||||
) -> pd.DataFrame:
|
) -> pd.DataFrame:
|
||||||
df_dict: OrderedDict[str, Any] = OrderedDict()
|
df_dict: OrderedDict[str, Any] = OrderedDict()
|
||||||
col_index: dict[int, str] = {}
|
col_index: Dict[int, str] = {}
|
||||||
|
|
||||||
for _ in range(skiprows):
|
for _ in range(skiprows):
|
||||||
next(rows)
|
next(rows)
|
||||||
|
|
@ -90,7 +90,7 @@ def read_data(
|
||||||
file_or_path: Path,
|
file_or_path: Path,
|
||||||
sheet_id: Union[str, int],
|
sheet_id: Union[str, int],
|
||||||
headers: bool,
|
headers: bool,
|
||||||
columns: list[str],
|
columns: List[str],
|
||||||
skiprows: int,
|
skiprows: int,
|
||||||
) -> pd.DataFrame:
|
) -> pd.DataFrame:
|
||||||
doc = backend.get_doc(file_or_path)
|
doc = backend.get_doc(file_or_path)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Imports an ods or fods file into a DataFrame object"""
|
"""Imports an ods or fods file into a DataFrame object"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Union
|
from typing import Optional, List, Union
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@ def read_ods(
|
||||||
file_or_path: Union[str, Path],
|
file_or_path: Union[str, Path],
|
||||||
sheet: Union[str, int] = 1,
|
sheet: Union[str, int] = 1,
|
||||||
headers: bool = True,
|
headers: bool = True,
|
||||||
columns: Optional[list[str]] = None,
|
columns: Optional[List[str]] = None,
|
||||||
skiprows: int = 0,
|
skiprows: int = 0,
|
||||||
) -> pd.DataFrame:
|
) -> pd.DataFrame:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Iterator, Union
|
from typing import Any, Iterator, List, Tuple, Union
|
||||||
|
|
||||||
import ezodf # type: ignore[import]
|
import ezodf # type: ignore[import]
|
||||||
from ezodf.document import FlatXMLDocument, PackagedDocument # type: ignore[import]
|
from ezodf.document import FlatXMLDocument, PackagedDocument # type: ignore[import]
|
||||||
|
|
@ -12,11 +12,11 @@ def get_doc(file_or_path: Path) -> Union[FlatXMLDocument, PackagedDocument]:
|
||||||
def get_rows(
|
def get_rows(
|
||||||
doc: Union[FlatXMLDocument, PackagedDocument],
|
doc: Union[FlatXMLDocument, PackagedDocument],
|
||||||
sheet_id: Union[str, int],
|
sheet_id: Union[str, int],
|
||||||
) -> Iterator[list[ezodf.Cell]]:
|
) -> Iterator[List[ezodf.Cell]]:
|
||||||
if not isinstance(sheet_id, (int, str)):
|
if not isinstance(sheet_id, (int, str)):
|
||||||
raise ValueError("Sheet id has to be either `str` or `int`")
|
raise ValueError("Sheet id has to be either `str` or `int`")
|
||||||
if isinstance(sheet_id, str):
|
if isinstance(sheet_id, str):
|
||||||
sheets: list[str] = [sheet.name for sheet in doc.sheets]
|
sheets: List[str] = [sheet.name for sheet in doc.sheets]
|
||||||
if sheet_id not in sheets:
|
if sheet_id not in sheets:
|
||||||
raise KeyError("There is no sheet named {}".format(sheet_id))
|
raise KeyError("There is no sheet named {}".format(sheet_id))
|
||||||
sheet_id = sheets.index(sheet_id) + 1
|
sheet_id = sheets.index(sheet_id) + 1
|
||||||
|
|
@ -24,5 +24,5 @@ def get_rows(
|
||||||
return sheet.rows()
|
return sheet.rows()
|
||||||
|
|
||||||
|
|
||||||
def get_value(cell: ezodf.Cell, parsed: bool = False) -> tuple[Any, int]:
|
def get_value(cell: ezodf.Cell, parsed: bool = False) -> Tuple[Any, int]:
|
||||||
return cell.value, 0
|
return cell.value, 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue