Skip to content

Remove close from StataReader #57371

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 1 commit into from
Feb 12, 2024
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Removal of prior version deprecations/changes
- Removed ``Series.__int__`` and ``Series.__float__``. Call ``int(Series.iloc[0])`` or ``float(Series.iloc[0])`` instead. (:issue:`51131`)
- Removed ``Series.ravel`` (:issue:`56053`)
- Removed ``Series.view`` (:issue:`56054`)
- Removed ``StataReader.close`` (:issue:`49228`)
- Removed ``axis`` argument from :meth:`DataFrame.groupby`, :meth:`Series.groupby`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.resample`, and :meth:`Series.resample` (:issue:`51203`)
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
- Removed ``pandas.api.types.is_interval`` and ``pandas.api.types.is_period``, use ``isinstance(obj, pd.Interval)`` and ``isinstance(obj, pd.Period)`` instead (:issue:`55264`)
Expand Down
18 changes: 0 additions & 18 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,24 +1181,6 @@ def __exit__(
if self._close_file:
self._close_file()

def close(self) -> None:
"""Close the handle if its open.

.. deprecated: 2.0.0

The close method is not part of the public API.
The only supported way to use StataReader is to use it as a context manager.
"""
warnings.warn(
"The StataReader.close() method is not part of the public API and "
"will be removed in a future version without notice. "
"Using StataReader as a context manager is the only supported method.",
FutureWarning,
stacklevel=find_stack_level(),
)
if self._close_file:
self._close_file()

def _set_encoding(self) -> None:
"""
Set string encoding which depends on file version
Expand Down
15 changes: 0 additions & 15 deletions pandas/tests/io/test_stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2001,21 +2001,6 @@ def test_direct_read(datapath, monkeypatch):
assert reader._path_or_buf is bio


def test_statareader_warns_when_used_without_context(datapath):
file_path = datapath("io", "data", "stata", "stata-compat-118.dta")
with tm.assert_produces_warning(
ResourceWarning,
match="without using a context manager",
):
sr = StataReader(file_path)
sr.read()
with tm.assert_produces_warning(
FutureWarning,
match="is not part of the public API",
):
sr.close()


@pytest.mark.parametrize("version", [114, 117, 118, 119, None])
@pytest.mark.parametrize("use_dict", [True, False])
@pytest.mark.parametrize("infer", [True, False])
Expand Down