diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index c4e5ad773ca09..c33d4ab92d4c6 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -5314,6 +5314,7 @@ Read from a parquet file. Read only certain columns of a parquet file. .. ipython:: python + :okwarning: result = pd.read_parquet( "example_fp.parquet", diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 239ecad18d4bc..f670059192094 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -98,6 +98,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ - Deprecated silently dropping unrecognized timezones when parsing strings to datetimes (:issue:`18702`) +- Deprecated :meth:`DataFrame._data` and :meth:`Series._data`, use public APIs instead (:issue:`33333`) - Deprecating pinning ``group.name`` to each group in :meth:`SeriesGroupBy.aggregate` aggregations; if your operation requires utilizing the groupby keys, iterate over the groupby object instead (:issue:`41090`) - Deprecated ``axis=1`` in :meth:`DataFrame.groupby` and in :class:`Grouper` constructor, do ``frame.T.groupby(...)`` instead (:issue:`51203`) - Deprecated passing a :class:`DataFrame` to :meth:`DataFrame.from_records`, use :meth:`DataFrame.set_index` or :meth:`DataFrame.drop` instead (:issue:`51353`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c3818a0a425b9..1c2c0734d2bd3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -486,6 +486,13 @@ def _constructor(self) -> Callable[..., Self]: def _data(self): # GH#33054 retained because some downstream packages uses this, # e.g. fastparquet + # GH#33333 + warnings.warn( + f"{type(self).__name__}._data is deprecated and will be removed in " + "a future version. Use public APIs instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) return self._mgr # ---------------------------------------------------------------------- diff --git a/pandas/tests/extension/base/casting.py b/pandas/tests/extension/base/casting.py index 89ea1670d9e7b..59b8679881bce 100644 --- a/pandas/tests/extension/base/casting.py +++ b/pandas/tests/extension/base/casting.py @@ -26,7 +26,7 @@ def test_astype_object_frame(self, all_data): result = df.astype(object) if hasattr(result._mgr, "blocks"): - blk = result._data.blocks[0] + blk = result._mgr.blocks[0] assert isinstance(blk, ObjectBlock), type(blk) assert isinstance(result._mgr.arrays[0], np.ndarray) assert result._mgr.arrays[0].dtype == np.dtype(object) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index e5787a7f16a35..e0d9d6c281fd5 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -377,5 +377,8 @@ def test_constructor_expanddim(self): def test_inspect_getmembers(self): # GH38740 df = DataFrame() - with tm.assert_produces_warning(None): + msg = "DataFrame._data is deprecated" + with tm.assert_produces_warning( + FutureWarning, match=msg, check_stacklevel=False + ): inspect.getmembers(df) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 54d08b577a47a..74d8277c975e4 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -301,6 +301,13 @@ def test_copy_and_deepcopy(self, frame_or_series, shape, func): assert obj_copy is not obj tm.assert_equal(obj_copy, obj) + def test_data_deprecated(self, frame_or_series): + obj = frame_or_series() + msg = "(Series|DataFrame)._data is deprecated" + with tm.assert_produces_warning(FutureWarning, match=msg): + mgr = obj._data + assert mgr is obj._mgr + class TestNDFrame: # tests that don't fit elsewhere diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index dcb28001777d2..e4e276af121f9 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -170,7 +170,10 @@ def test_attrs(self): def test_inspect_getmembers(self): # GH38782 ser = Series(dtype=object) - with tm.assert_produces_warning(None, check_stacklevel=False): + msg = "Series._data is deprecated" + with tm.assert_produces_warning( + FutureWarning, match=msg, check_stacklevel=False + ): inspect.getmembers(ser) def test_unknown_attribute(self):