3232 Dtype ,
3333 DtypeObj ,
3434 Shape ,
35+ final ,
3536)
3637from pandas .util ._validators import validate_bool_kwarg
3738
@@ -231,6 +232,7 @@ def _holder(self):
231232 """
232233 return None
233234
235+ @final
234236 @property
235237 def _consolidate_key (self ):
236238 return self ._can_consolidate , self .dtype .name
@@ -242,6 +244,7 @@ def is_view(self) -> bool:
242244 values = cast (np .ndarray , values )
243245 return values .base is not None
244246
247+ @final
245248 @property
246249 def is_categorical (self ) -> bool :
247250 return self ._holder is Categorical
@@ -278,6 +281,7 @@ def get_values(self, dtype: Optional[DtypeObj] = None) -> np.ndarray:
278281 return self .values .astype (object )
279282 return self .values
280283
284+ @final
281285 def get_block_values_for_json (self ) -> np .ndarray :
282286 """
283287 This is used in the JSON C code.
@@ -300,6 +304,7 @@ def mgr_locs(self, new_mgr_locs):
300304
301305 self ._mgr_locs = new_mgr_locs
302306
307+ @final
303308 def make_block (self , values , placement = None ) -> Block :
304309 """
305310 Create a new block, with type inference propagate any values that are
@@ -312,14 +317,14 @@ def make_block(self, values, placement=None) -> Block:
312317
313318 return make_block (values , placement = placement , ndim = self .ndim )
314319
315- def make_block_same_class (self , values , placement = None , ndim = None ) -> Block :
320+ @final
321+ def make_block_same_class (self , values , placement = None ) -> Block :
316322 """ Wrap given values in a block of same type as self. """
317323 if placement is None :
318324 placement = self .mgr_locs
319- if ndim is None :
320- ndim = self .ndim
321- return type (self )(values , placement = placement , ndim = ndim )
325+ return type (self )(values , placement = placement , ndim = self .ndim )
322326
327+ @final
323328 def __repr__ (self ) -> str :
324329 # don't want to print out all of the items here
325330 name = type (self ).__name__
@@ -332,12 +337,15 @@ def __repr__(self) -> str:
332337
333338 return result
334339
340+ @final
335341 def __len__ (self ) -> int :
336342 return len (self .values )
337343
344+ @final
338345 def __getstate__ (self ):
339346 return self .mgr_locs .indexer , self .values
340347
348+ @final
341349 def __setstate__ (self , state ):
342350 self .mgr_locs = libinternals .BlockPlacement (state [0 ])
343351 self .values = state [1 ]
@@ -348,6 +356,7 @@ def _slice(self, slicer):
348356
349357 return self .values [slicer ]
350358
359+ @final
351360 def getitem_block (self , slicer , new_mgr_locs = None ) -> Block :
352361 """
353362 Perform __getitem__-like, return result as block.
@@ -371,6 +380,7 @@ def getitem_block(self, slicer, new_mgr_locs=None) -> Block:
371380 def shape (self ) -> Shape :
372381 return self .values .shape
373382
383+ @final
374384 @property
375385 def dtype (self ) -> DtypeObj :
376386 return self .values .dtype
@@ -389,13 +399,15 @@ def set_inplace(self, locs, values):
389399 """
390400 self .values [locs ] = values
391401
402+ @final
392403 def delete (self , loc ) -> None :
393404 """
394405 Delete given loc(-s) from block in-place.
395406 """
396407 self .values = np .delete (self .values , loc , 0 )
397408 self .mgr_locs = self .mgr_locs .delete (loc )
398409
410+ @final
399411 def apply (self , func , ** kwargs ) -> List [Block ]:
400412 """
401413 apply the function to my values; return a block if we are not
@@ -427,6 +439,7 @@ def reduce(self, func, ignore_failures: bool = False) -> List[Block]:
427439 nb = self .make_block (res_values )
428440 return [nb ]
429441
442+ @final
430443 def _split_op_result (self , result ) -> List [Block ]:
431444 # See also: split_and_operate
432445 if is_extension_array_dtype (result ) and result .ndim > 1 :
@@ -487,6 +500,7 @@ def f(mask, val, idx):
487500
488501 return self .split_and_operate (None , f , inplace )
489502
503+ @final
490504 def _split (self ) -> List [Block ]:
491505 """
492506 Split a block into a list of single-column blocks.
@@ -501,6 +515,7 @@ def _split(self) -> List[Block]:
501515 new_blocks .append (nb )
502516 return new_blocks
503517
518+ @final
504519 def split_and_operate (
505520 self , mask , f , inplace : bool , ignore_failures : bool = False
506521 ) -> List [Block ]:
@@ -617,6 +632,7 @@ def f(mask, val, idx):
617632
618633 return self .split_and_operate (None , f , False )
619634
635+ @final
620636 def astype (self , dtype , copy : bool = False , errors : str = "raise" ):
621637 """
622638 Coerce to the new dtype.
@@ -720,6 +736,7 @@ def _can_hold_element(self, element: Any) -> bool:
720736 """ require the same dtype as ourselves """
721737 raise NotImplementedError ("Implemented on subclasses" )
722738
739+ @final
723740 def should_store (self , value : ArrayLike ) -> bool :
724741 """
725742 Should we set self.values[indexer] = value inplace or do we need to cast?
@@ -753,12 +770,13 @@ def to_native_types(self, na_rep="nan", quoting=None, **kwargs):
753770 return self .make_block (values )
754771
755772 # block actions #
773+ @final
756774 def copy (self , deep : bool = True ):
757775 """ copy constructor """
758776 values = self .values
759777 if deep :
760778 values = values .copy ()
761- return self .make_block_same_class (values , ndim = self . ndim )
779+ return self .make_block_same_class (values )
762780
763781 # ---------------------------------------------------------------------
764782 # Replace
@@ -807,6 +825,7 @@ def replace(
807825 blocks = blk .convert (numeric = False , copy = not inplace )
808826 return blocks
809827
828+ @final
810829 def _replace_regex (
811830 self ,
812831 to_replace ,
@@ -852,6 +871,7 @@ def _replace_regex(
852871 nbs = [block ]
853872 return nbs
854873
874+ @final
855875 def _replace_list (
856876 self ,
857877 src_list : List [Any ],
@@ -913,6 +933,7 @@ def _replace_list(
913933 rb = new_rb
914934 return rb
915935
936+ @final
916937 def _replace_coerce (
917938 self ,
918939 to_replace ,
@@ -1147,6 +1168,7 @@ def f(mask, val, idx):
11471168 new_blocks = self .split_and_operate (mask , f , True )
11481169 return new_blocks
11491170
1171+ @final
11501172 def coerce_to_target_dtype (self , other ) -> Block :
11511173 """
11521174 coerce the current block to a dtype compat for other
@@ -1162,6 +1184,7 @@ def coerce_to_target_dtype(self, other) -> Block:
11621184
11631185 return self .astype (new_dtype , copy = False )
11641186
1187+ @final
11651188 def interpolate (
11661189 self ,
11671190 method : str = "pad" ,
@@ -1220,6 +1243,7 @@ def interpolate(
12201243 ** kwargs ,
12211244 )
12221245
1246+ @final
12231247 def _interpolate_with_fill (
12241248 self ,
12251249 method : str = "pad" ,
@@ -1244,9 +1268,10 @@ def _interpolate_with_fill(
12441268 limit_area = limit_area ,
12451269 )
12461270
1247- blocks = [self .make_block_same_class (values , ndim = self . ndim )]
1271+ blocks = [self .make_block_same_class (values )]
12481272 return self ._maybe_downcast (blocks , downcast )
12491273
1274+ @final
12501275 def _interpolate (
12511276 self ,
12521277 method : str ,
@@ -1459,7 +1484,7 @@ def _unstack(self, unstacker, fill_value, new_placement):
14591484 new_values = new_values .T [mask ]
14601485 new_placement = new_placement [mask ]
14611486
1462- blocks = [make_block (new_values , placement = new_placement )]
1487+ blocks = [make_block (new_values , placement = new_placement , ndim = 2 )]
14631488 return blocks , mask
14641489
14651490 def quantile (
@@ -1761,21 +1786,15 @@ def fillna(
17611786 ) -> List [Block ]:
17621787 values = self .values if inplace else self .values .copy ()
17631788 values = values .fillna (value = value , limit = limit )
1764- return [
1765- self .make_block_same_class (
1766- values = values , placement = self .mgr_locs , ndim = self .ndim
1767- )
1768- ]
1789+ return [self .make_block_same_class (values = values )]
17691790
17701791 def interpolate (
17711792 self , method = "pad" , axis = 0 , inplace = False , limit = None , fill_value = None , ** kwargs
17721793 ):
17731794
17741795 values = self .values if inplace else self .values .copy ()
1775- return self .make_block_same_class (
1776- values = values .fillna (value = fill_value , method = method , limit = limit ),
1777- placement = self .mgr_locs ,
1778- )
1796+ new_values = values .fillna (value = fill_value , method = method , limit = limit )
1797+ return self .make_block_same_class (new_values )
17791798
17801799 def diff (self , n : int , axis : int = 1 ) -> List [Block ]:
17811800 if axis == 0 and n != 0 :
@@ -1797,13 +1816,8 @@ def shift(self, periods: int, axis: int = 0, fill_value: Any = None) -> List[Blo
17971816 Dispatches to underlying ExtensionArray and re-boxes in an
17981817 ExtensionBlock.
17991818 """
1800- return [
1801- self .make_block_same_class (
1802- self .values .shift (periods = periods , fill_value = fill_value ),
1803- placement = self .mgr_locs ,
1804- ndim = self .ndim ,
1805- )
1806- ]
1819+ new_values = self .values .shift (periods = periods , fill_value = fill_value )
1820+ return [self .make_block_same_class (new_values )]
18071821
18081822 def where (self , other , cond , errors = "raise" , axis : int = 0 ) -> List [Block ]:
18091823
@@ -1850,7 +1864,7 @@ def where(self, other, cond, errors="raise", axis: int = 0) -> List[Block]:
18501864 np .where (cond , self .values , other ), dtype = dtype
18511865 )
18521866
1853- return [self .make_block_same_class (result , placement = self . mgr_locs )]
1867+ return [self .make_block_same_class (result )]
18541868
18551869 def _unstack (self , unstacker , fill_value , new_placement ):
18561870 # ExtensionArray-safe unstack.
0 commit comments