diff --git a/pandas/core/internals/__init__.py b/pandas/core/internals/__init__.py index 284f8ef135d99..0f8cb9f053174 100644 --- a/pandas/core/internals/__init__.py +++ b/pandas/core/internals/__init__.py @@ -16,7 +16,6 @@ from pandas.core.internals.managers import ( BlockManager, SingleBlockManager, - create_block_manager_from_blocks, ) __all__ = [ @@ -31,8 +30,6 @@ "SingleBlockManager", "SingleArrayManager", "concatenate_managers", - # this is preserved here for downstream compatibility (GH-33892) - "create_block_manager_from_blocks", ] @@ -41,6 +38,18 @@ def __getattr__(name: str): from pandas.util._exceptions import find_stack_level + 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.", + DeprecationWarning, + stacklevel=find_stack_level(), + ) + from pandas.core.internals.managers import create_block_manager_from_blocks + + return create_block_manager_from_blocks + if name in ["NumericBlock", "ObjectBlock"]: warnings.warn( f"{name} is deprecated and will be removed in a future version. " diff --git a/pandas/tests/internals/test_api.py b/pandas/tests/internals/test_api.py index 5cd6c718260ea..ffc672cc748be 100644 --- a/pandas/tests/internals/test_api.py +++ b/pandas/tests/internals/test_api.py @@ -4,6 +4,7 @@ """ import pandas as pd +import pandas._testing as tm from pandas.core import internals from pandas.core.internals import api @@ -37,7 +38,6 @@ def test_namespace(): "SingleBlockManager", "SingleArrayManager", "concatenate_managers", - "create_block_manager_from_blocks", ] result = [x for x in dir(internals) if not x.startswith("__")] @@ -51,3 +51,15 @@ def test_make_block_2d_with_dti(): assert blk.shape == (1, 3) 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(DeprecationWarning, match=msg): + internals.create_block_manager_from_blocks