diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 7fddb36185789..e4dad8800d78f 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -235,6 +235,7 @@ Removal of prior version deprecations/changes - Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`) - Removed 'fastpath' keyword in :class:`Categorical` constructor (:issue:`20110`) - Removed 'kind' keyword in :meth:`Series.resample` and :meth:`DataFrame.resample` (:issue:`58125`) +- Removed ``Block``, ``DatetimeTZBlock``, ``ExtensionBlock``, ``create_block_manager_from_blocks`` from ``pandas.core.internals`` and ``pandas.core.internals.api`` (:issue:`55139`) - Removed alias :class:`arrays.PandasArray` for :class:`arrays.NumpyExtensionArray` (:issue:`53694`) - Removed deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`) - Removed extension test classes ``BaseNoReduceTests``, ``BaseNumericReduceTests``, ``BaseBooleanReduceTests`` (:issue:`54663`) diff --git a/pandas/core/internals/api.py b/pandas/core/internals/api.py index ef25d7ed5ae9e..24bfad4791b29 100644 --- a/pandas/core/internals/api.py +++ b/pandas/core/internals/api.py @@ -92,10 +92,7 @@ def make_block( values, dtype = extract_pandas_array(values, dtype, ndim) - from pandas.core.internals.blocks import ( - DatetimeTZBlock, - ExtensionBlock, - ) + from pandas.core.internals.blocks import ExtensionBlock if klass is ExtensionBlock and isinstance(values.dtype, PeriodDtype): # GH-44681 changed PeriodArray to be stored in the 2D @@ -107,16 +104,6 @@ def make_block( dtype = dtype or values.dtype klass = get_block_type(dtype) - elif klass is DatetimeTZBlock and not isinstance(values.dtype, DatetimeTZDtype): - # pyarrow calls get here - values = DatetimeArray._simple_new( - # error: Argument "dtype" to "_simple_new" of "DatetimeArray" has - # incompatible type "Union[ExtensionDtype, dtype[Any], None]"; - # expected "Union[dtype[datetime64], DatetimeTZDtype]" - values, - dtype=dtype, # type: ignore[arg-type] - ) - if not isinstance(placement, BlockPlacement): placement = BlockPlacement(placement) @@ -146,48 +133,3 @@ def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int else: ndim = values.ndim return ndim - - -def __getattr__(name: str): - # GH#55139 - import warnings - - if name in [ - "Block", - "ExtensionBlock", - "DatetimeTZBlock", - "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, - # https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758 - # on hard-coding stacklevel - stacklevel=2, - ) - - if name == "create_block_manager_from_blocks": - from pandas.core.internals.managers import create_block_manager_from_blocks - - return create_block_manager_from_blocks - - elif name == "Block": - from pandas.core.internals.blocks import Block - - return Block - - elif name == "DatetimeTZBlock": - from pandas.core.internals.blocks import DatetimeTZBlock - - return DatetimeTZBlock - - elif name == "ExtensionBlock": - from pandas.core.internals.blocks import ExtensionBlock - - return ExtensionBlock - - raise AttributeError( - f"module 'pandas.core.internals.api' has no attribute '{name}'" - ) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 6107c009b5bf1..cffb1f658a640 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2153,14 +2153,6 @@ class DatetimeLikeBlock(NDArrayBackedExtensionBlock): values: DatetimeArray | TimedeltaArray -class DatetimeTZBlock(DatetimeLikeBlock): - """implement a datetime64 block with a tz attribute""" - - values: DatetimeArray - - __slots__ = () - - # ----------------------------------------------------------------- # Constructor Helpers @@ -2207,7 +2199,7 @@ def get_block_type(dtype: DtypeObj) -> type[Block]: cls : class, subclass of Block """ if isinstance(dtype, DatetimeTZDtype): - return DatetimeTZBlock + return DatetimeLikeBlock elif isinstance(dtype, PeriodDtype): return NDArrayBackedExtensionBlock elif isinstance(dtype, ExtensionDtype):