Skip to content
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

TYP: read_sas #47410

Merged
merged 7 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ Other API changes
October 2022. (:issue:`46312`)
- :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`)
- Operations with :class:`Timestamp` or :class:`Timedelta` that would previously raise ``OverflowError`` instead raise ``OutOfBoundsDatetime`` or ``OutOfBoundsTimedelta`` where appropriate (:issue:`47268`)
- When :func:`read_sas` previously returned ``None``, it now returns an empty :class:`DataFrame` (:issue:`47410`)
-

.. ---------------------------------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions pandas/io/sas/sas7bdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ def __init__(
self,
path_or_buf: FilePath | ReadBuffer[bytes],
index=None,
convert_dates=True,
blank_missing=True,
chunksize=None,
encoding=None,
convert_text=True,
convert_header_text=True,
convert_dates: bool = True,
blank_missing: bool = True,
chunksize: int | None = None,
encoding: str | None = None,
convert_text: bool = True,
convert_header_text: bool = True,
compression: CompressionOptions = "infer",
) -> None:

Expand Down Expand Up @@ -361,9 +361,9 @@ def _get_properties(self) -> None:
self.encoding or self.default_encoding
)

def __next__(self):
def __next__(self) -> DataFrame:
da = self.read(nrows=self.chunksize or 1)
if da is None:
if da.empty:
self.close()
raise StopIteration
return da
Expand Down Expand Up @@ -732,7 +732,7 @@ def _process_format_subheader(self, offset: int, length: int) -> None:
self.column_formats.append(column_format)
self.columns.append(col)

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

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

if nrows > 0 and self._current_row_in_file_index >= self.row_count:
return None
return DataFrame()

m = self.row_count - self._current_row_in_file_index
if nrows > m:
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/sas/sas_xport.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def __init__(
self.close()
raise

def close(self):
def close(self) -> None:
self.handles.close()

def _get_row(self):
Expand Down Expand Up @@ -463,7 +463,7 @@ def _missing_double(self, vec):
return miss

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

if nrows is None:
nrows = self.nobs
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/sas/sasreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ class ReaderBase(metaclass=ABCMeta):
"""

@abstractmethod
def read(self, nrows=None):
def read(self, nrows: int | None = None) -> DataFrame:
pass

@abstractmethod
def close(self):
def close(self) -> None:
pass

def __enter__(self):
def __enter__(self) -> ReaderBase:
return self

def __exit__(self, exc_type, exc_value, traceback):
def __exit__(self, exc_type, exc_value, traceback) -> None:
self.close()


Expand Down
3 changes: 1 addition & 2 deletions pyright_reportGeneralTypeIssues.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
"pandas/io/parsers/base_parser.py",
"pandas/io/parsers/c_parser_wrapper.py",
"pandas/io/pytables.py",
"pandas/io/sas/sas7bdat.py",
"pandas/io/sas/sasreader.py",
"pandas/io/sas/sas_xport.py",
"pandas/io/sql.py",
"pandas/io/stata.py",
"pandas/io/xml.py",
Expand Down