Skip to content

Commit 234f678

Browse files
committed
revert removing exposing blocks core.internals and replace DeprecationWarning with FutureWarning
1 parent 283a2dc commit 234f678

File tree

5 files changed

+78
-7
lines changed

5 files changed

+78
-7
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ Removal of prior version deprecations/changes
259259
- Enforced deprecation of :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`57820`)
260260
- Enforced deprecation of :meth:`offsets.Tick.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`)
261261
- 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`)
262-
- Enforced deprecation of ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock`` (:issue:`58467`)
263262
- 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`)
264263
- Enforced deprecation of ``keep_date_col`` keyword in :func:`read_csv` (:issue:`55569`)
265264
- Enforced deprecation of ``quantile`` keyword in :meth:`.Rolling.quantile` and :meth:`.Expanding.quantile`, renamed to ``q`` instead. (:issue:`52550`)

pandas/core/internals/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,58 @@
66
)
77

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

pandas/io/pytables.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@
125125
npt,
126126
)
127127

128-
from pandas.core.internals.blocks import Block
129-
128+
from pandas.core.internals import Block
130129

131130
# versioning attribute
132131
_version = "0.15.2"

pandas/tests/internals/test_api.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ def test_namespace():
4141
assert set(result) == set(expected + modules)
4242

4343

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

5267

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

pandas/tests/io/test_parquet.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,6 @@ def test_read_empty_array(self, pa, dtype):
655655
"value": pd.array([], dtype=dtype),
656656
}
657657
)
658-
pytest.importorskip("pyarrow", "11.0.0")
659658
# GH 45694
660659
expected = None
661660
if dtype == "float":
@@ -672,7 +671,6 @@ def test_read_empty_array(self, pa, dtype):
672671
class TestParquetPyArrow(Base):
673672
def test_basic(self, pa, df_full):
674673
df = df_full
675-
pytest.importorskip("pyarrow", "11.0.0")
676674

677675
# additional supported types for pyarrow
678676
dti = pd.date_range("20130101", periods=3, tz="Europe/Brussels")
@@ -940,8 +938,6 @@ def test_timestamp_nanoseconds(self, pa):
940938
check_round_trip(df, pa, write_kwargs={"version": ver})
941939

942940
def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
943-
pytest.importorskip("pyarrow", "11.0.0")
944-
945941
if timezone_aware_date_list.tzinfo != datetime.timezone.utc:
946942
request.applymarker(
947943
pytest.mark.xfail(

0 commit comments

Comments
 (0)