Skip to content

Commit 6786ab2

Browse files
authored
TYP: read_sas (#47410)
* TYP: read_sas * make __next__ compatibel with empty datafram * df -> da * whatsnew
1 parent 7683563 commit 6786ab2

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ Other API changes
467467
October 2022. (:issue:`46312`)
468468
- :func:`read_json` now raises ``FileNotFoundError`` (previously ``ValueError``) when input is a string ending in ``.json``, ``.json.gz``, ``.json.bz2``, etc. but no such file exists. (:issue:`29102`)
469469
- Operations with :class:`Timestamp` or :class:`Timedelta` that would previously raise ``OverflowError`` instead raise ``OutOfBoundsDatetime`` or ``OutOfBoundsTimedelta`` where appropriate (:issue:`47268`)
470+
- When :func:`read_sas` previously returned ``None``, it now returns an empty :class:`DataFrame` (:issue:`47410`)
470471
-
471472

472473
.. ---------------------------------------------------------------------------

pandas/io/sas/sas7bdat.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ def __init__(
163163
self,
164164
path_or_buf: FilePath | ReadBuffer[bytes],
165165
index=None,
166-
convert_dates=True,
167-
blank_missing=True,
168-
chunksize=None,
169-
encoding=None,
170-
convert_text=True,
171-
convert_header_text=True,
166+
convert_dates: bool = True,
167+
blank_missing: bool = True,
168+
chunksize: int | None = None,
169+
encoding: str | None = None,
170+
convert_text: bool = True,
171+
convert_header_text: bool = True,
172172
compression: CompressionOptions = "infer",
173173
) -> None:
174174

@@ -361,9 +361,9 @@ def _get_properties(self) -> None:
361361
self.encoding or self.default_encoding
362362
)
363363

364-
def __next__(self):
364+
def __next__(self) -> DataFrame:
365365
da = self.read(nrows=self.chunksize or 1)
366-
if da is None:
366+
if da.empty:
367367
self.close()
368368
raise StopIteration
369369
return da
@@ -732,7 +732,7 @@ def _process_format_subheader(self, offset: int, length: int) -> None:
732732
self.column_formats.append(column_format)
733733
self.columns.append(col)
734734

735-
def read(self, nrows: int | None = None) -> DataFrame | None:
735+
def read(self, nrows: int | None = None) -> DataFrame:
736736

737737
if (nrows is None) and (self.chunksize is not None):
738738
nrows = self.chunksize
@@ -744,7 +744,7 @@ def read(self, nrows: int | None = None) -> DataFrame | None:
744744
raise EmptyDataError("No columns to parse from file")
745745

746746
if nrows > 0 and self._current_row_in_file_index >= self.row_count:
747-
return None
747+
return DataFrame()
748748

749749
m = self.row_count - self._current_row_in_file_index
750750
if nrows > m:

pandas/io/sas/sas_xport.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def __init__(
280280
self.close()
281281
raise
282282

283-
def close(self):
283+
def close(self) -> None:
284284
self.handles.close()
285285

286286
def _get_row(self):
@@ -463,7 +463,7 @@ def _missing_double(self, vec):
463463
return miss
464464

465465
@Appender(_read_method_doc)
466-
def read(self, nrows=None):
466+
def read(self, nrows: int | None = None) -> pd.DataFrame:
467467

468468
if nrows is None:
469469
nrows = self.nobs

pandas/io/sas/sasreader.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ class ReaderBase(metaclass=ABCMeta):
3838
"""
3939

4040
@abstractmethod
41-
def read(self, nrows=None):
41+
def read(self, nrows: int | None = None) -> DataFrame:
4242
pass
4343

4444
@abstractmethod
45-
def close(self):
45+
def close(self) -> None:
4646
pass
4747

48-
def __enter__(self):
48+
def __enter__(self) -> ReaderBase:
4949
return self
5050

51-
def __exit__(self, exc_type, exc_value, traceback):
51+
def __exit__(self, exc_type, exc_value, traceback) -> None:
5252
self.close()
5353

5454

pyright_reportGeneralTypeIssues.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@
104104
"pandas/io/parsers/base_parser.py",
105105
"pandas/io/parsers/c_parser_wrapper.py",
106106
"pandas/io/pytables.py",
107-
"pandas/io/sas/sas7bdat.py",
108-
"pandas/io/sas/sasreader.py",
107+
"pandas/io/sas/sas_xport.py",
109108
"pandas/io/sql.py",
110109
"pandas/io/stata.py",
111110
"pandas/io/xml.py",

0 commit comments

Comments
 (0)