Skip to content

Commit ad21509

Browse files
natmokvalpmhatre1
authored andcommitted
CLN: enforce the deprecation of exposing blocks in core.internals (pandas-dev#58467)
* CLN: enforce the deprecation of exposing blocks in core.internals * remove the function __getattr__, and entries from __all__ * fix mypy error * add a note to v3.0.0 * skip parquet tests for minimum Pyarrow version * fixup test_basic * fix pre-commit error * skip pyarrow=10.0.1 in test_parquet.py * fix mypy error * fix pre-commit error * fixup test_parquet.py * fix pre-commit error * fixup test_parquet.py * replacee pytest.skip with pytest.importorskip * skip pyarrow '10.0.1'
1 parent 442be89 commit ad21509

File tree

5 files changed

+7
-78
lines changed

5 files changed

+7
-78
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Removal of prior version deprecations/changes
253253
- Enforced deprecation of :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`57820`)
254254
- Enforced deprecation of :meth:`offsets.Tick.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`)
255255
- 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`)
256+
- Enforced deprecation of ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock`` (:issue:`58467`)
256257
- Enforced deprecation of non-standard (``np.ndarray``, :class:`ExtensionArray`, :class:`Index`, or :class:`Series`) argument to :func:`api.extensions.take` (:issue:`52981`)
257258
- Enforced deprecation of parsing system timezone strings to ``tzlocal``, which depended on system timezone, pass the 'tz' keyword instead (:issue:`50791`)
258259
- Enforced deprecation of passing a dictionary to :meth:`SeriesGroupBy.agg` (:issue:`52268`)

pandas/core/internals/__init__.py

-50
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,8 @@
66
)
77

88
__all__ = [
9-
"Block",
10-
"DatetimeTZBlock",
11-
"ExtensionBlock",
129
"make_block",
1310
"BlockManager",
1411
"SingleBlockManager",
1512
"concatenate_managers",
1613
]
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-
DeprecationWarning,
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-
DeprecationWarning,
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

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

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

130131
# versioning attribute
131132
_version = "0.15.2"

pandas/tests/internals/test_api.py

-27
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ 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(DeprecationWarning, match=msg):
56-
getattr(internals, name)
57-
58-
5944
def test_make_block_2d_with_dti():
6045
# GH#41168
6146
dti = pd.date_range("2012", periods=3, tz="UTC")
@@ -65,18 +50,6 @@ def test_make_block_2d_with_dti():
6550
assert blk.values.shape == (1, 3)
6651

6752

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(DeprecationWarning, match=msg):
77-
internals.create_block_manager_from_blocks
78-
79-
8053
def test_create_dataframe_from_blocks(float_frame):
8154
block = float_frame._mgr.blocks[0]
8255
index = float_frame.index.copy()

pandas/tests/io/test_parquet.py

+4
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ def test_read_empty_array(self, pa, dtype):
655655
"value": pd.array([], dtype=dtype),
656656
}
657657
)
658+
pytest.importorskip("pyarrow", "11.0.0")
658659
# GH 45694
659660
expected = None
660661
if dtype == "float":
@@ -671,6 +672,7 @@ def test_read_empty_array(self, pa, dtype):
671672
class TestParquetPyArrow(Base):
672673
def test_basic(self, pa, df_full):
673674
df = df_full
675+
pytest.importorskip("pyarrow", "11.0.0")
674676

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

940942
def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
943+
pytest.importorskip("pyarrow", "11.0.0")
944+
941945
if timezone_aware_date_list.tzinfo != datetime.timezone.utc:
942946
request.applymarker(
943947
pytest.mark.xfail(

0 commit comments

Comments
 (0)