26
26
type_t ,
27
27
)
28
28
from pandas .errors import PerformanceWarning
29
+ from pandas .util ._decorators import cache_readonly
29
30
from pandas .util ._validators import validate_bool_kwarg
30
31
31
32
from pandas .core .dtypes .cast import infer_dtype_from_scalar
@@ -1706,7 +1707,7 @@ def unpickle_block(values, mgr_locs, ndim: int) -> Block:
1706
1707
def _post_setstate (self ):
1707
1708
pass
1708
1709
1709
- @property
1710
+ @cache_readonly
1710
1711
def _block (self ) -> Block :
1711
1712
return self .blocks [0 ]
1712
1713
@@ -1729,7 +1730,7 @@ def getitem_mgr(self, indexer) -> SingleBlockManager:
1729
1730
raise ValueError ("dimension-expanding indexing not allowed" )
1730
1731
1731
1732
bp = BlockPlacement (slice (0 , len (array )))
1732
- block = blk . make_block_same_class (array , placement = bp )
1733
+ block = type ( blk ) (array , placement = bp , ndim = 1 )
1733
1734
1734
1735
new_idx = self .index [indexer ]
1735
1736
return type (self )(block , new_idx )
@@ -1926,7 +1927,7 @@ def _form_blocks(arrays: list[ArrayLike], consolidate: bool) -> list[Block]:
1926
1927
tuples = list (enumerate (arrays ))
1927
1928
1928
1929
if not consolidate :
1929
- nbs = _tuples_to_blocks_no_consolidate (tuples , dtype = None )
1930
+ nbs = _tuples_to_blocks_no_consolidate (tuples )
1930
1931
return nbs
1931
1932
1932
1933
# group by dtype
@@ -1966,17 +1967,8 @@ def _form_blocks(arrays: list[ArrayLike], consolidate: bool) -> list[Block]:
1966
1967
return nbs
1967
1968
1968
1969
1969
- def _tuples_to_blocks_no_consolidate (tuples , dtype : DtypeObj | None ) -> list [Block ]:
1970
+ def _tuples_to_blocks_no_consolidate (tuples ) -> list [Block ]:
1970
1971
# tuples produced within _form_blocks are of the form (placement, array)
1971
- if dtype is not None :
1972
- return [
1973
- new_block (
1974
- ensure_block_shape (x [1 ].astype (dtype , copy = False ), ndim = 2 ),
1975
- placement = x [0 ],
1976
- ndim = 2 ,
1977
- )
1978
- for x in tuples
1979
- ]
1980
1972
return [
1981
1973
new_block (ensure_block_shape (x [1 ], ndim = 2 ), placement = x [0 ], ndim = 2 )
1982
1974
for x in tuples
0 commit comments