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: revert enforcing the deprecation of exposing blocks in core.internals and deprecate with FutureWarning #58715

2 changes: 1 addition & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ Other Removals
- Enforced deprecation of :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`57820`)
- Enforced deprecation of :meth:`offsets.Tick.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`)
- 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`)
- Enforced deprecation of ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock`` (:issue:`58467`)
- Enforced deprecation of ``core.internals`` member ``DatetimeTZBlock`` (:issue:`58467`)
- 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`)
- Enforced deprecation of ``keep_date_col`` keyword in :func:`read_csv` (:issue:`55569`)
- Enforced deprecation of ``quantile`` keyword in :meth:`.Rolling.quantile` and :meth:`.Expanding.quantile`, renamed to ``q`` instead. (:issue:`52550`)
Expand Down
44 changes: 44 additions & 0 deletions pandas/core/internals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,52 @@
)

__all__ = [
"Block",
"ExtensionBlock",
"make_block",
"BlockManager",
"SingleBlockManager",
"concatenate_managers",
]


def __getattr__(name: str):
# GH#55139
import warnings

if name == "create_block_manager_from_blocks":
# GH#33892
warnings.warn(
f"{name} is deprecated and will be removed in a future version. "
"Use public APIs instead.",
FutureWarning,
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
# on hard-coding stacklevel
stacklevel=2,
)
from pandas.core.internals.managers import create_block_manager_from_blocks

return create_block_manager_from_blocks

if name in [
"Block",
"ExtensionBlock",
]:
warnings.warn(
f"{name} is deprecated and will be removed in a future version. "
"Use public APIs instead.",
FutureWarning,
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
# on hard-coding stacklevel
stacklevel=2,
)
if name == "ExtensionBlock":
from pandas.core.internals.blocks import ExtensionBlock

return ExtensionBlock
else:
from pandas.core.internals.blocks import Block

return Block

raise AttributeError(f"module 'pandas.core.internals' has no attribute '{name}'")
3 changes: 1 addition & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@
npt,
)

from pandas.core.internals.blocks import Block

from pandas.core.internals import Block

# versioning attribute
_version = "0.15.2"
Expand Down
26 changes: 26 additions & 0 deletions pandas/tests/internals/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ def test_namespace():
assert set(result) == set(expected + modules)


@pytest.mark.parametrize(
"name",
[
"Block",
"ExtensionBlock",
],
)
def test_deprecations(name):
# GH#55139
msg = f"{name} is deprecated.* Use public APIs instead"
with tm.assert_produces_warning(FutureWarning, match=msg):
getattr(internals, name)


def test_make_block_2d_with_dti():
# GH#41168
dti = pd.date_range("2012", periods=3, tz="UTC")
Expand All @@ -53,6 +67,18 @@ def test_make_block_2d_with_dti():
assert blk.values.shape == (1, 3)


def test_create_block_manager_from_blocks_deprecated():
# GH#33892
# If they must, downstream packages should get this from internals.api,
# not internals.
msg = (
"create_block_manager_from_blocks is deprecated and will be "
"removed in a future version. Use public APIs instead"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
internals.create_block_manager_from_blocks


def test_create_dataframe_from_blocks(float_frame):
block = float_frame._mgr.blocks[0]
index = float_frame.index.copy()
Expand Down