diff --git a/pandas/_libs/index_class_helper.pxi.in b/pandas/_libs/index_class_helper.pxi.in index f1dbc3780011f..dfce411c09e66 100644 --- a/pandas/_libs/index_class_helper.pxi.in +++ b/pandas/_libs/index_class_helper.pxi.in @@ -49,9 +49,7 @@ cdef class {{name}}Engine(IndexEngine): # Returns ndarray[bool] or int cdef: ndarray[uint8_t, ndim=1, cast=True] indexer - ndarray[intp_t, ndim=1] found ndarray[{{dtype}}_t, ndim=1] values - int count = 0 self._check_type(val) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 7d2eb3acf2ed2..181cb46325708 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -422,7 +422,7 @@ def unique(values): """ values = _ensure_arraylike(values) - if is_extension_array_dtype(values): + if is_extension_array_dtype(values.dtype): # Dispatch to extension dtype's unique. return values.unique() diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 70a88595a4b16..6afb071f76f10 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -26,6 +26,7 @@ type_t, ) from pandas.errors import PerformanceWarning +from pandas.util._decorators import cache_readonly from pandas.util._validators import validate_bool_kwarg from pandas.core.dtypes.cast import infer_dtype_from_scalar @@ -1706,7 +1707,7 @@ def unpickle_block(values, mgr_locs, ndim: int) -> Block: def _post_setstate(self): pass - @property + @cache_readonly def _block(self) -> Block: return self.blocks[0] @@ -1729,7 +1730,7 @@ def getitem_mgr(self, indexer) -> SingleBlockManager: raise ValueError("dimension-expanding indexing not allowed") bp = BlockPlacement(slice(0, len(array))) - block = blk.make_block_same_class(array, placement=bp) + block = type(blk)(array, placement=bp, ndim=1) new_idx = self.index[indexer] return type(self)(block, new_idx) @@ -1926,7 +1927,7 @@ def _form_blocks(arrays: list[ArrayLike], consolidate: bool) -> list[Block]: tuples = list(enumerate(arrays)) if not consolidate: - nbs = _tuples_to_blocks_no_consolidate(tuples, dtype=None) + nbs = _tuples_to_blocks_no_consolidate(tuples) return nbs # group by dtype @@ -1966,17 +1967,8 @@ def _form_blocks(arrays: list[ArrayLike], consolidate: bool) -> list[Block]: return nbs -def _tuples_to_blocks_no_consolidate(tuples, dtype: DtypeObj | None) -> list[Block]: +def _tuples_to_blocks_no_consolidate(tuples) -> list[Block]: # tuples produced within _form_blocks are of the form (placement, array) - if dtype is not None: - return [ - new_block( - ensure_block_shape(x[1].astype(dtype, copy=False), ndim=2), - placement=x[0], - ndim=2, - ) - for x in tuples - ] return [ new_block(ensure_block_shape(x[1], ndim=2), placement=x[0], ndim=2) for x in tuples