Skip to content

TYP: check_untyped_defs io.sas.sasreader #30659

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
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pandas/io/sas/sas7bdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pandas.io.common import get_filepath_or_buffer
from pandas.io.sas._sas import Parser
import pandas.io.sas.sas_constants as const
from pandas.io.sas.sasreader import ReaderBase


class _subheader_pointer:
Expand All @@ -37,7 +38,7 @@ class _column:


# SAS7BDAT represents a SAS data file in SAS7BDAT format.
class SAS7BDATReader(abc.Iterator):
class SAS7BDATReader(ReaderBase, abc.Iterator):
"""
Read SAS files in SAS7BDAT format.

Expand Down
3 changes: 2 additions & 1 deletion pandas/io/sas/sas_xport.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pandas as pd

from pandas.io.common import get_filepath_or_buffer
from pandas.io.sas.sasreader import ReaderBase

_correct_line1 = (
"HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!"
Expand Down Expand Up @@ -239,7 +240,7 @@ def _parse_float_vec(vec):
return ieee


class XportReader(abc.Iterator):
class XportReader(ReaderBase, abc.Iterator):
__doc__ = _xport_reader_doc

def __init__(
Expand Down
19 changes: 19 additions & 0 deletions pandas/io/sas/sasreader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
"""
Read SAS sas7bdat or xport files.
"""

from abc import ABCMeta, abstractmethod

from pandas.io.common import stringify_path


# TODO: replace with Protocol in Python 3.8
class ReaderBase(metaclass=ABCMeta):
"""
Protocol for XportReader and SAS7BDATReader classes.
"""

@abstractmethod
def read(self, nrows=None):
pass

@abstractmethod
def close(self):
pass


def read_sas(
filepath_or_buffer,
format=None,
Expand Down Expand Up @@ -62,6 +80,7 @@ def read_sas(
else:
raise ValueError("unable to infer format of SAS file")

reader: ReaderBase
if format.lower() == "xport":
from pandas.io.sas.sas_xport import XportReader

Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ check_untyped_defs=False
[mypy-pandas.io.sas.sas7bdat]
check_untyped_defs=False

[mypy-pandas.io.sas.sasreader]
check_untyped_defs=False

[mypy-pandas.io.stata]
check_untyped_defs=False

Expand Down