Skip to content

Commit 66d7dc7

Browse files
natmokvalZKaoChi
authored andcommitted
DEPR: revert enforcing the deprecation of exposing blocks in core.internals and deprecate with FutureWarning (pandas-dev#58715)
1 parent 979fb2e commit 66d7dc7

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

doc/source/whatsnew/v3.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ Other Removals
481481
- Enforced deprecation of :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`57820`)
482482
- Enforced deprecation of :meth:`offsets.Tick.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`)
483483
- Enforced deprecation of ``axis=None`` acting the same as ``axis=0`` in the DataFrame reductions ``sum``, ``prod``, ``std``, ``var``, and ``sem``, passing ``axis=None`` will now reduce over both axes; this is particularly the case when doing e.g. ``numpy.sum(df)`` (:issue:`21597`)
484-
- Enforced deprecation of ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock`` (:issue:`58467`)
484+
- Enforced deprecation of ``core.internals`` member ``DatetimeTZBlock`` (:issue:`58467`)
485485
- Enforced deprecation of ``date_parser`` in :func:`read_csv`, :func:`read_table`, :func:`read_fwf`, and :func:`read_excel` in favour of ``date_format`` (:issue:`50601`)
486486
- Enforced deprecation of ``keep_date_col`` keyword in :func:`read_csv` (:issue:`55569`)
487487
- Enforced deprecation of ``quantile`` keyword in :meth:`.Rolling.quantile` and :meth:`.Expanding.quantile`, renamed to ``q`` instead. (:issue:`52550`)

pandas/core/internals/__init__.py

+44
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,52 @@
66
)
77

88
__all__ = [
9+
"Block",
10+
"ExtensionBlock",
911
"make_block",
1012
"BlockManager",
1113
"SingleBlockManager",
1214
"concatenate_managers",
1315
]
16+
17+
18+
def __getattr__(name: str):
19+
# GH#55139
20+
import warnings
21+
22+
if name == "create_block_manager_from_blocks":
23+
# GH#33892
24+
warnings.warn(
25+
f"{name} is deprecated and will be removed in a future version. "
26+
"Use public APIs instead.",
27+
FutureWarning,
28+
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
29+
# on hard-coding stacklevel
30+
stacklevel=2,
31+
)
32+
from pandas.core.internals.managers import create_block_manager_from_blocks
33+
34+
return create_block_manager_from_blocks
35+
36+
if name in [
37+
"Block",
38+
"ExtensionBlock",
39+
]:
40+
warnings.warn(
41+
f"{name} is deprecated and will be removed in a future version. "
42+
"Use public APIs instead.",
43+
FutureWarning,
44+
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
45+
# on hard-coding stacklevel
46+
stacklevel=2,
47+
)
48+
if name == "ExtensionBlock":
49+
from pandas.core.internals.blocks import ExtensionBlock
50+
51+
return ExtensionBlock
52+
else:
53+
from pandas.core.internals.blocks import Block
54+
55+
return Block
56+
57+
raise AttributeError(f"module 'pandas.core.internals' has no attribute '{name}'")

pandas/io/pytables.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@
126126
npt,
127127
)
128128

129-
from pandas.core.internals.blocks import Block
130-
129+
from pandas.core.internals import Block
131130

132131
# versioning attribute
133132
_version = "0.15.2"

pandas/tests/internals/test_api.py

+26
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ def test_namespace():
4141
assert set(result) == set(expected + modules)
4242

4343

44+
@pytest.mark.parametrize(
45+
"name",
46+
[
47+
"Block",
48+
"ExtensionBlock",
49+
],
50+
)
51+
def test_deprecations(name):
52+
# GH#55139
53+
msg = f"{name} is deprecated.* Use public APIs instead"
54+
with tm.assert_produces_warning(FutureWarning, match=msg):
55+
getattr(internals, name)
56+
57+
4458
def test_make_block_2d_with_dti():
4559
# GH#41168
4660
dti = pd.date_range("2012", periods=3, tz="UTC")
@@ -53,6 +67,18 @@ def test_make_block_2d_with_dti():
5367
assert blk.values.shape == (1, 3)
5468

5569

70+
def test_create_block_manager_from_blocks_deprecated():
71+
# GH#33892
72+
# If they must, downstream packages should get this from internals.api,
73+
# not internals.
74+
msg = (
75+
"create_block_manager_from_blocks is deprecated and will be "
76+
"removed in a future version. Use public APIs instead"
77+
)
78+
with tm.assert_produces_warning(FutureWarning, match=msg):
79+
internals.create_block_manager_from_blocks
80+
81+
5682
def test_create_dataframe_from_blocks(float_frame):
5783
block = float_frame._mgr.blocks[0]
5884
index = float_frame.index.copy()

0 commit comments

Comments
 (0)