@@ -243,6 +243,8 @@ def make_block(self, values, placement=None) -> "Block":
243243 """
244244 if placement is None :
245245 placement = self .mgr_locs
246+ if self .is_extension :
247+ values = _block_shape (values , ndim = self .ndim )
246248
247249 return make_block (values , placement = placement , ndim = self .ndim )
248250
@@ -354,13 +356,12 @@ def _split_op_result(self, result) -> List["Block"]:
354356 nbs = []
355357 for i , loc in enumerate (self .mgr_locs ):
356358 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 ])
359360 nbs .append (block )
360361 return nbs
361362
362363 if not isinstance (result , Block ):
363- result = self .make_block (values = _block_shape ( result , ndim = self . ndim ) )
364+ result = self .make_block (result )
364365
365366 return [result ]
366367
@@ -1264,9 +1265,6 @@ def take_nd(self, indexer, axis: int, new_mgr_locs=None, fill_value=lib.no_defau
12641265 def diff (self , n : int , axis : int = 1 ) -> List ["Block" ]:
12651266 """ return block for the diff of the values """
12661267 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 )
12701268 return [self .make_block (values = new_values )]
12711269
12721270 def shift (self , periods : int , axis : int = 0 , fill_value = None ):
@@ -2254,7 +2252,7 @@ def concat_same_type(self, to_concat):
22542252 values = values .astype (object , copy = False )
22552253 placement = self .mgr_locs if self .ndim == 2 else slice (len (values ))
22562254
2257- return self .make_block (_block_shape ( values , self . ndim ) , placement = placement )
2255+ return self .make_block (values , placement = placement )
22582256 return super ().concat_same_type (to_concat )
22592257
22602258 def fillna (self , value , limit = None , inplace = False , downcast = None ):
@@ -2420,7 +2418,6 @@ def f(mask, val, idx):
24202418 # TODO: allow EA once reshape is supported
24212419 values = values .reshape (shape )
24222420
2423- values = _block_shape (values , ndim = self .ndim )
24242421 return values
24252422
24262423 if self .ndim == 2 :
@@ -2660,9 +2657,7 @@ def concat_same_type(self, to_concat):
26602657 )
26612658 placement = self .mgr_locs if self .ndim == 2 else slice (len (values ))
26622659 # 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 )
26662661
26672662 def replace (
26682663 self ,
@@ -2771,16 +2766,15 @@ def _extend_blocks(result, blocks=None):
27712766 return blocks
27722767
27732768
2774- def _block_shape (values , ndim = 1 , shape = None ) :
2769+ def _block_shape (values : ArrayLike , ndim : int = 1 ) -> ArrayLike :
27752770 """ guarantee the shape of the values to be at least 1 d """
27762771 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
27812775 # block.shape is incorrect for "2D" ExtensionArrays
27822776 # 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
27842778 return values
27852779
27862780
0 commit comments