Skip to content

TYP: type annotations for read_sas #34697

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 3 commits into from
Jun 13, 2020
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
45 changes: 37 additions & 8 deletions pandas/io/sas/sasreader.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""
Read SAS sas7bdat or xport files.
"""

from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING, Optional, Union, overload

from pandas._typing import FilePathOrBuffer, Label

from pandas.io.common import stringify_path

if TYPE_CHECKING:
from pandas import DataFrame # noqa: F401


# TODO(PY38): replace with Protocol in Python 3.8
class ReaderBase(metaclass=ABCMeta):
Expand All @@ -22,14 +27,38 @@ def close(self):
pass


@overload
def read_sas(
filepath_or_buffer: FilePathOrBuffer,
format: Optional[str] = ...,
index: Optional[Label] = ...,
encoding: Optional[str] = ...,
chunksize: int = ...,
iterator: bool = ...,
) -> ReaderBase:
...


@overload
def read_sas(
filepath_or_buffer: FilePathOrBuffer,
format: Optional[str] = ...,
index: Optional[Label] = ...,
encoding: Optional[str] = ...,
chunksize: None = ...,
iterator: bool = ...,
) -> Union["DataFrame", ReaderBase]:
...


def read_sas(
filepath_or_buffer,
format=None,
index=None,
encoding=None,
chunksize=None,
iterator=False,
):
filepath_or_buffer: FilePathOrBuffer,
format: Optional[str] = None,
index: Optional[Label] = None,
encoding: Optional[str] = None,
chunksize: Optional[int] = None,
iterator: bool = False,
) -> Union["DataFrame", ReaderBase]:
"""
Read SAS files stored as either XPORT or SAS7BDAT format files.

Expand Down