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

DEPR: NDFrame._data #52003

Merged
merged 2 commits into from
Mar 16, 2023
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/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/base/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down