Skip to content

Commit 25fe9fc

Browse files
TYP: check_untyped_defs io.sas.sasreader (pandas-dev#30659)
1 parent 5ef5dfb commit 25fe9fc

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

pandas/io/sas/sas7bdat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pandas.io.common import get_filepath_or_buffer
2727
from pandas.io.sas._sas import Parser
2828
import pandas.io.sas.sas_constants as const
29+
from pandas.io.sas.sasreader import ReaderBase
2930

3031

3132
class _subheader_pointer:
@@ -37,7 +38,7 @@ class _column:
3738

3839

3940
# SAS7BDAT represents a SAS data file in SAS7BDAT format.
40-
class SAS7BDATReader(abc.Iterator):
41+
class SAS7BDATReader(ReaderBase, abc.Iterator):
4142
"""
4243
Read SAS files in SAS7BDAT format.
4344

pandas/io/sas/sas_xport.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pandas as pd
2020

2121
from pandas.io.common import get_filepath_or_buffer
22+
from pandas.io.sas.sasreader import ReaderBase
2223

2324
_correct_line1 = (
2425
"HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!"
@@ -239,7 +240,7 @@ def _parse_float_vec(vec):
239240
return ieee
240241

241242

242-
class XportReader(abc.Iterator):
243+
class XportReader(ReaderBase, abc.Iterator):
243244
__doc__ = _xport_reader_doc
244245

245246
def __init__(

pandas/io/sas/sasreader.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
"""
22
Read SAS sas7bdat or xport files.
33
"""
4+
5+
from abc import ABCMeta, abstractmethod
6+
47
from pandas.io.common import stringify_path
58

69

10+
# TODO: replace with Protocol in Python 3.8
11+
class ReaderBase(metaclass=ABCMeta):
12+
"""
13+
Protocol for XportReader and SAS7BDATReader classes.
14+
"""
15+
16+
@abstractmethod
17+
def read(self, nrows=None):
18+
pass
19+
20+
@abstractmethod
21+
def close(self):
22+
pass
23+
24+
725
def read_sas(
826
filepath_or_buffer,
927
format=None,
@@ -62,6 +80,7 @@ def read_sas(
6280
else:
6381
raise ValueError("unable to infer format of SAS file")
6482

83+
reader: ReaderBase
6584
if format.lower() == "xport":
6685
from pandas.io.sas.sas_xport import XportReader
6786

setup.cfg

-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,6 @@ check_untyped_defs=False
291291
[mypy-pandas.io.sas.sas7bdat]
292292
check_untyped_defs=False
293293

294-
[mypy-pandas.io.sas.sasreader]
295-
check_untyped_defs=False
296-
297294
[mypy-pandas.io.stata]
298295
check_untyped_defs=False
299296

0 commit comments

Comments
 (0)