File tree 4 files changed +23
-5
lines changed
4 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 26
26
from pandas .io .common import get_filepath_or_buffer
27
27
from pandas .io .sas ._sas import Parser
28
28
import pandas .io .sas .sas_constants as const
29
+ from pandas .io .sas .sasreader import ReaderBase
29
30
30
31
31
32
class _subheader_pointer :
@@ -37,7 +38,7 @@ class _column:
37
38
38
39
39
40
# SAS7BDAT represents a SAS data file in SAS7BDAT format.
40
- class SAS7BDATReader (abc .Iterator ):
41
+ class SAS7BDATReader (ReaderBase , abc .Iterator ):
41
42
"""
42
43
Read SAS files in SAS7BDAT format.
43
44
Original file line number Diff line number Diff line change 19
19
import pandas as pd
20
20
21
21
from pandas .io .common import get_filepath_or_buffer
22
+ from pandas .io .sas .sasreader import ReaderBase
22
23
23
24
_correct_line1 = (
24
25
"HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!"
@@ -239,7 +240,7 @@ def _parse_float_vec(vec):
239
240
return ieee
240
241
241
242
242
- class XportReader (abc .Iterator ):
243
+ class XportReader (ReaderBase , abc .Iterator ):
243
244
__doc__ = _xport_reader_doc
244
245
245
246
def __init__ (
Original file line number Diff line number Diff line change 1
1
"""
2
2
Read SAS sas7bdat or xport files.
3
3
"""
4
+
5
+ from abc import ABCMeta , abstractmethod
6
+
4
7
from pandas .io .common import stringify_path
5
8
6
9
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
+
7
25
def read_sas (
8
26
filepath_or_buffer ,
9
27
format = None ,
@@ -62,6 +80,7 @@ def read_sas(
62
80
else :
63
81
raise ValueError ("unable to infer format of SAS file" )
64
82
83
+ reader : ReaderBase
65
84
if format .lower () == "xport" :
66
85
from pandas .io .sas .sas_xport import XportReader
67
86
Original file line number Diff line number Diff line change @@ -291,9 +291,6 @@ check_untyped_defs=False
291
291
[mypy-pandas.io.sas.sas7bdat]
292
292
check_untyped_defs =False
293
293
294
- [mypy-pandas.io.sas.sasreader]
295
- check_untyped_defs =False
296
-
297
294
[mypy-pandas.io.stata]
298
295
check_untyped_defs =False
299
296
You can’t perform that action at this time.
0 commit comments