From af43a60308711b00e40f58255396cb54fca16bd6 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 2 Oct 2023 08:11:41 -0700 Subject: [PATCH 1/2] DEPR: create_block_manager_from_blocks --- pandas/core/internals/__init__.py | 13 ++++++++++++- pandas/tests/internals/test_api.py | 14 +++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/__init__.py b/pandas/core/internals/__init__.py index 284f8ef135d99..cabe2b0611041 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__ = [ @@ -41,6 +40,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 From 561354d29f4f98f7da1a0a657553ef6d840f7212 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 2 Oct 2023 12:39:15 -0700 Subject: [PATCH 2/2] lint fixup --- pandas/core/internals/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/internals/__init__.py b/pandas/core/internals/__init__.py index cabe2b0611041..0f8cb9f053174 100644 --- a/pandas/core/internals/__init__.py +++ b/pandas/core/internals/__init__.py @@ -30,8 +30,6 @@ "SingleBlockManager", "SingleArrayManager", "concatenate_managers", - # this is preserved here for downstream compatibility (GH-33892) - "create_block_manager_from_blocks", ]