Skip to content

Commit 6b27de3

Browse files
authored
DEPR: NDFrame._data (#52003)
1 parent ebfcad1 commit 6b27de3

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

doc/source/user_guide/io.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5314,6 +5314,7 @@ Read from a parquet file.
53145314
Read only certain columns of a parquet file.
53155315

53165316
.. ipython:: python
5317+
:okwarning:
53175318
53185319
result = pd.read_parquet(
53195320
"example_fp.parquet",

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Other API changes
9797
Deprecations
9898
~~~~~~~~~~~~
9999
- Deprecated silently dropping unrecognized timezones when parsing strings to datetimes (:issue:`18702`)
100+
- Deprecated :meth:`DataFrame._data` and :meth:`Series._data`, use public APIs instead (:issue:`33333`)
100101
- 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`)
101102
- Deprecated ``axis=1`` in :meth:`DataFrame.groupby` and in :class:`Grouper` constructor, do ``frame.T.groupby(...)`` instead (:issue:`51203`)
102103
- Deprecated passing a :class:`DataFrame` to :meth:`DataFrame.from_records`, use :meth:`DataFrame.set_index` or :meth:`DataFrame.drop` instead (:issue:`51353`)

pandas/core/generic.py

+7
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ def _constructor(self) -> Callable[..., Self]:
486486
def _data(self):
487487
# GH#33054 retained because some downstream packages uses this,
488488
# e.g. fastparquet
489+
# GH#33333
490+
warnings.warn(
491+
f"{type(self).__name__}._data is deprecated and will be removed in "
492+
"a future version. Use public APIs instead.",
493+
FutureWarning,
494+
stacklevel=find_stack_level(),
495+
)
489496
return self._mgr
490497

491498
# ----------------------------------------------------------------------

pandas/tests/extension/base/casting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_astype_object_frame(self, all_data):
2626

2727
result = df.astype(object)
2828
if hasattr(result._mgr, "blocks"):
29-
blk = result._data.blocks[0]
29+
blk = result._mgr.blocks[0]
3030
assert isinstance(blk, ObjectBlock), type(blk)
3131
assert isinstance(result._mgr.arrays[0], np.ndarray)
3232
assert result._mgr.arrays[0].dtype == np.dtype(object)

pandas/tests/frame/test_api.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -377,5 +377,8 @@ def test_constructor_expanddim(self):
377377
def test_inspect_getmembers(self):
378378
# GH38740
379379
df = DataFrame()
380-
with tm.assert_produces_warning(None):
380+
msg = "DataFrame._data is deprecated"
381+
with tm.assert_produces_warning(
382+
FutureWarning, match=msg, check_stacklevel=False
383+
):
381384
inspect.getmembers(df)

pandas/tests/generic/test_generic.py

+7
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ def test_copy_and_deepcopy(self, frame_or_series, shape, func):
301301
assert obj_copy is not obj
302302
tm.assert_equal(obj_copy, obj)
303303

304+
def test_data_deprecated(self, frame_or_series):
305+
obj = frame_or_series()
306+
msg = "(Series|DataFrame)._data is deprecated"
307+
with tm.assert_produces_warning(FutureWarning, match=msg):
308+
mgr = obj._data
309+
assert mgr is obj._mgr
310+
304311

305312
class TestNDFrame:
306313
# tests that don't fit elsewhere

pandas/tests/series/test_api.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ def test_attrs(self):
170170
def test_inspect_getmembers(self):
171171
# GH38782
172172
ser = Series(dtype=object)
173-
with tm.assert_produces_warning(None, check_stacklevel=False):
173+
msg = "Series._data is deprecated"
174+
with tm.assert_produces_warning(
175+
FutureWarning, match=msg, check_stacklevel=False
176+
):
174177
inspect.getmembers(ser)
175178

176179
def test_unknown_attribute(self):

0 commit comments

Comments
 (0)