Add type hints and change docstyle to google.
This commit is contained in:
parent
bd3caab7f3
commit
64ea7059d2
|
|
@ -1,5 +1,8 @@
|
||||||
"""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
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
from .parsers import fods, ods
|
from .parsers import fods, ods
|
||||||
from . import algo
|
from . import algo
|
||||||
|
|
@ -8,29 +11,27 @@ from . import algo
|
||||||
EXT_MAP = {".ods": ods, ".fods": fods}
|
EXT_MAP = {".ods": ods, ".fods": fods}
|
||||||
|
|
||||||
|
|
||||||
def read_ods(file_or_path, sheet=1, headers=True, columns=None, skiprows=0):
|
def read_ods(
|
||||||
|
file_or_path: Union[str, Path],
|
||||||
|
sheet: Union[str, int] = 1,
|
||||||
|
headers: bool = True,
|
||||||
|
columns: Optional[list[str]] = None,
|
||||||
|
skiprows: int = 0,
|
||||||
|
) -> pd.DataFrame:
|
||||||
"""
|
"""
|
||||||
Read in the provided ods or .ods file and convert it to `pandas.DataFrame`.
|
Read in the provided ods or .ods file and convert it to `pandas.DataFrame`.
|
||||||
Will detect the filetype based on the file's extension or fall back to
|
Will detect the filetype based on the file's extension or fall back to
|
||||||
ods.
|
ods.
|
||||||
|
|
||||||
Parameters
|
Args:
|
||||||
----------
|
file_or_path: The path to the .ods or .fods file.
|
||||||
file_or_path : str or pathlib.Path
|
sheet: If `int`, the 1 based index of the sheet to be read. If `str`, the
|
||||||
The path to the .ods or .fods file.
|
name of the sheet to be read.
|
||||||
sheet : int or str, default 1
|
headers: If `True`, then the first row is treated as the list of column names.
|
||||||
If `int`, the 1 based index of the sheet to be read. If `str`, the
|
columns: A list of column names to be used as headers.
|
||||||
name of the sheet to be read.
|
skiprows: The number of rows to skip before starting to read data.
|
||||||
headers : bool, default True
|
|
||||||
If `True`, then the first row is treated as the list of column names.
|
|
||||||
columns : list, default None, optional
|
|
||||||
A list of column names to be used as headers.
|
|
||||||
skiprows : int, default 0
|
|
||||||
The number of rows to skip before starting to read data.
|
|
||||||
|
|
||||||
Returns
|
Returns:
|
||||||
-------
|
|
||||||
pandas.DataFrame
|
|
||||||
The content of the specified sheet as a DataFrame.
|
The content of the specified sheet as a DataFrame.
|
||||||
"""
|
"""
|
||||||
backend = EXT_MAP.get(Path(file_or_path).suffix, ods)
|
backend = EXT_MAP.get(Path(file_or_path).suffix, ods)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue