Skip to content

Commit eaa9c3e

Browse files
committed
Add types for read_metadata()
For type checking.
1 parent 8f2ded3 commit eaa9c3e

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

augur/io/metadata.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import csv
22
import os
3-
from typing import Any, Iterable, Iterator, Sequence, Union
3+
from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Union
44
import pandas as pd
55
from pandas._typing import FilePath, ReadCsvBuffer
66
import pyfastx
@@ -28,39 +28,36 @@ class InvalidDelimiter(Exception):
2828

2929

3030
def read_metadata(
31-
metadata_file,
32-
delimiters=DEFAULT_DELIMITERS,
33-
columns=None,
34-
id_columns=DEFAULT_ID_COLUMNS,
35-
keep_id_as_column=False,
36-
chunk_size=None,
37-
dtype=None,
38-
):
31+
metadata_file: str,
32+
delimiters: Sequence[str] = DEFAULT_DELIMITERS,
33+
columns: Optional[List[str]] = None,
34+
id_columns: Sequence[str] = DEFAULT_ID_COLUMNS,
35+
keep_id_as_column: bool = False,
36+
chunk_size: Optional[int] = None,
37+
dtype: Optional[Union[Dict[str, Any], str]] = None,
38+
) -> Union[pd.DataFrame, Iterator[pd.DataFrame]]:
3939
r"""Read metadata from a given filename and into a pandas `DataFrame` or
40-
`TextFileReader` object.
40+
iterator of DataFrames when `chunk_size` is specified.
4141
4242
Parameters
4343
----------
44-
metadata_file : str
44+
metadata_file
4545
Path to a metadata file to load.
46-
delimiters : list of str
46+
delimiters
4747
List of possible delimiters to check for between columns in the metadata.
4848
Only one delimiter will be inferred.
49-
columns : list of str
49+
columns
5050
List of columns to read. If unspecified, read all columns.
51-
id_columns : list of str
51+
id_columns
5252
List of possible id column names to check for, ordered by priority.
5353
Only one id column will be inferred.
54-
keep_id_as_column : bool
54+
keep_id_as_column
5555
If true, keep the resolved id column as a column in addition to setting it as the DataFrame index.
56-
chunk_size : int
56+
chunk_size
5757
Size of chunks to stream from disk with an iterator instead of loading the entire input file into memory.
58-
dtype : dict or str
58+
dtype
5959
Data types to apply to columns in metadata. If unspecified, pandas data type inference will be used.
6060
See documentation for an argument of the same name to `pandas.read_csv()`.
61-
Returns
62-
-------
63-
pandas.DataFrame or `pandas.io.parsers.TextFileReader`
6461
6562
Raises
6663
------

0 commit comments

Comments
 (0)