From 542c3c1302d48efdd293580fd2f9ef621ff87511 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sun, 11 Feb 2024 23:05:03 +0100 Subject: [PATCH] Remove close from StataReader --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/io/stata.py | 18 ------------------ pandas/tests/io/test_stata.py | 15 --------------- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index aa378faac2a00..a830fb594051f 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -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`) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index c2a3db2d44b16..37ea940b3938a 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -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 diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py index c12bcfb91a4c7..42a9e84218a81 100644 --- a/pandas/tests/io/test_stata.py +++ b/pandas/tests/io/test_stata.py @@ -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])