@@ -243,6 +243,8 @@ def make_block(self, values, placement=None) -> "Block":
243
243
"""
244
244
if placement is None :
245
245
placement = self .mgr_locs
246
+ if self .is_extension :
247
+ values = _block_shape (values , ndim = self .ndim )
246
248
247
249
return make_block (values , placement = placement , ndim = self .ndim )
248
250
@@ -354,13 +356,12 @@ def _split_op_result(self, result) -> List["Block"]:
354
356
nbs = []
355
357
for i , loc in enumerate (self .mgr_locs ):
356
358
vals = result [i ]
357
- nv = _block_shape (vals , ndim = self .ndim )
358
- block = self .make_block (values = nv , placement = [loc ])
359
+ block = self .make_block (values = vals , placement = [loc ])
359
360
nbs .append (block )
360
361
return nbs
361
362
362
363
if not isinstance (result , Block ):
363
- result = self .make_block (values = _block_shape ( result , ndim = self . ndim ) )
364
+ result = self .make_block (result )
364
365
365
366
return [result ]
366
367
@@ -1264,9 +1265,6 @@ def take_nd(self, indexer, axis: int, new_mgr_locs=None, fill_value=lib.no_defau
1264
1265
def diff (self , n : int , axis : int = 1 ) -> List ["Block" ]:
1265
1266
""" return block for the diff of the values """
1266
1267
new_values = algos .diff (self .values , n , axis = axis , stacklevel = 7 )
1267
- # We use block_shape for ExtensionBlock subclasses, which may call here
1268
- # via a super.
1269
- new_values = _block_shape (new_values , ndim = self .ndim )
1270
1268
return [self .make_block (values = new_values )]
1271
1269
1272
1270
def shift (self , periods : int , axis : int = 0 , fill_value = None ):
@@ -2254,7 +2252,7 @@ def concat_same_type(self, to_concat):
2254
2252
values = values .astype (object , copy = False )
2255
2253
placement = self .mgr_locs if self .ndim == 2 else slice (len (values ))
2256
2254
2257
- return self .make_block (_block_shape ( values , self . ndim ) , placement = placement )
2255
+ return self .make_block (values , placement = placement )
2258
2256
return super ().concat_same_type (to_concat )
2259
2257
2260
2258
def fillna (self , value , limit = None , inplace = False , downcast = None ):
@@ -2420,7 +2418,6 @@ def f(mask, val, idx):
2420
2418
# TODO: allow EA once reshape is supported
2421
2419
values = values .reshape (shape )
2422
2420
2423
- values = _block_shape (values , ndim = self .ndim )
2424
2421
return values
2425
2422
2426
2423
if self .ndim == 2 :
@@ -2660,9 +2657,7 @@ def concat_same_type(self, to_concat):
2660
2657
)
2661
2658
placement = self .mgr_locs if self .ndim == 2 else slice (len (values ))
2662
2659
# not using self.make_block_same_class as values can be object dtype
2663
- return self .make_block (
2664
- _block_shape (values , ndim = self .ndim ), placement = placement
2665
- )
2660
+ return self .make_block (values , placement = placement )
2666
2661
2667
2662
def replace (
2668
2663
self ,
@@ -2771,16 +2766,15 @@ def _extend_blocks(result, blocks=None):
2771
2766
return blocks
2772
2767
2773
2768
2774
- def _block_shape (values , ndim = 1 , shape = None ) :
2769
+ def _block_shape (values : ArrayLike , ndim : int = 1 ) -> ArrayLike :
2775
2770
""" guarantee the shape of the values to be at least 1 d """
2776
2771
if values .ndim < ndim :
2777
- if shape is None :
2778
- shape = values .shape
2779
- if not is_extension_array_dtype (values ):
2780
- # TODO: https://github.com/pandas-dev/pandas/issues/23023
2772
+ shape = values .shape
2773
+ if not is_extension_array_dtype (values .dtype ):
2774
+ # TODO(EA2D): https://github.com/pandas-dev/pandas/issues/23023
2781
2775
# block.shape is incorrect for "2D" ExtensionArrays
2782
2776
# We can't, and don't need to, reshape.
2783
- values = values .reshape (tuple ((1 ,) + shape ))
2777
+ values = values .reshape (tuple ((1 ,) + shape )) # type: ignore
2784
2778
return values
2785
2779
2786
2780
0 commit comments