33import itertools
44import operator
55import re
6- from typing import List , Optional , Sequence , Tuple , Union
6+ from typing import Dict , List , Optional , Sequence , Tuple , Union
77
88import numpy as np
99
@@ -181,23 +181,23 @@ def set_axis(self, axis, new_labels):
181181
182182 self .axes [axis ] = new_labels
183183
184- def rename_axis (self , mapper , axis , copy = True , level = None ):
184+ def rename_axis (self , mapper , axis , copy : bool = True , level = None ):
185185 """
186186 Rename one of axes.
187187
188188 Parameters
189189 ----------
190190 mapper : unary callable
191191 axis : int
192- copy : boolean , default True
192+ copy : bool , default True
193193 level : int, default None
194194 """
195195 obj = self .copy (deep = copy )
196196 obj .set_axis (axis , _transform_index (self .axes [axis ], mapper , level ))
197197 return obj
198198
199199 @property
200- def _is_single_block (self ):
200+ def _is_single_block (self ) -> bool :
201201 if self .ndim == 1 :
202202 return True
203203
@@ -441,9 +441,9 @@ def quantile(
441441 Parameters
442442 ----------
443443 axis: reduction axis, default 0
444- consolidate: boolean , default True. Join together blocks having same
444+ consolidate: bool , default True. Join together blocks having same
445445 dtype
446- transposed: boolean , default False
446+ transposed: bool , default False
447447 we are holding transposed data
448448 interpolation : type of interpolation, default 'linear'
449449 qs : a scalar or list of the quantiles to be computed
@@ -525,7 +525,9 @@ def get_axe(block, qs, axes):
525525 values = values .take (indexer )
526526
527527 return SingleBlockManager (
528- [make_block (values , ndim = 1 , placement = np .arange (len (values )))], axes [0 ]
528+ make_block (values , ndim = 1 , placement = np .arange (len (values ))),
529+ axes [0 ],
530+ fastpath = True ,
529531 )
530532
531533 def isna (self , func ):
@@ -635,24 +637,24 @@ def _consolidate_check(self):
635637 self ._known_consolidated = True
636638
637639 @property
638- def is_mixed_type (self ):
640+ def is_mixed_type (self ) -> bool :
639641 # Warning, consolidation needs to get checked upstairs
640642 self ._consolidate_inplace ()
641643 return len (self .blocks ) > 1
642644
643645 @property
644- def is_numeric_mixed_type (self ):
646+ def is_numeric_mixed_type (self ) -> bool :
645647 # Warning, consolidation needs to get checked upstairs
646648 self ._consolidate_inplace ()
647649 return all (block .is_numeric for block in self .blocks )
648650
649651 @property
650- def any_extension_types (self ):
652+ def any_extension_types (self ) -> bool :
651653 """Whether any of the blocks in this manager are extension blocks"""
652654 return any (block .is_extension for block in self .blocks )
653655
654656 @property
655- def is_view (self ):
657+ def is_view (self ) -> bool :
656658 """ return a boolean if we are a single block and are a view """
657659 if len (self .blocks ) == 1 :
658660 return self .blocks [0 ].is_view
@@ -666,21 +668,21 @@ def is_view(self):
666668
667669 return False
668670
669- def get_bool_data (self , copy = False ):
671+ def get_bool_data (self , copy : bool = False ):
670672 """
671673 Parameters
672674 ----------
673- copy : boolean , default False
675+ copy : bool , default False
674676 Whether to copy the blocks
675677 """
676678 self ._consolidate_inplace ()
677679 return self .combine ([b for b in self .blocks if b .is_bool ], copy )
678680
679- def get_numeric_data (self , copy = False ):
681+ def get_numeric_data (self , copy : bool = False ):
680682 """
681683 Parameters
682684 ----------
683- copy : boolean , default False
685+ copy : bool , default False
684686 Whether to copy the blocks
685687 """
686688 self ._consolidate_inplace ()
@@ -772,8 +774,8 @@ def as_array(self, transpose: bool = False) -> np.ndarray:
772774
773775 Parameters
774776 ----------
775- transpose : boolean , default False
776- If True, transpose the return array
777+ transpose : bool , default False
778+ If True, transpose the return array,
777779
778780 Returns
779781 -------
@@ -825,13 +827,13 @@ def _interleave(self):
825827
826828 return result
827829
828- def to_dict (self , copy = True ):
830+ def to_dict (self , copy : bool = True ):
829831 """
830832 Return a dict of str(dtype) -> BlockManager
831833
832834 Parameters
833835 ----------
834- copy : boolean , default True
836+ copy : bool , default True
835837
836838 Returns
837839 -------
@@ -843,7 +845,7 @@ def to_dict(self, copy=True):
843845 """
844846 self ._consolidate_inplace ()
845847
846- bd = {}
848+ bd : Dict [ str , List [ Block ]] = {}
847849 for b in self .blocks :
848850 bd .setdefault (str (b .dtype ), []).append (b )
849851
@@ -944,21 +946,18 @@ def get(self, item):
944946
945947 def iget (self , i ):
946948 """
947- Return the data as a SingleBlockManager if possible
948-
949- Otherwise return as a ndarray
949+ Return the data as a SingleBlockManager.
950950 """
951951 block = self .blocks [self ._blknos [i ]]
952952 values = block .iget (self ._blklocs [i ])
953953
954954 # shortcut for select a single-dim from a 2-dim BM
955955 return SingleBlockManager (
956- [
957- block .make_block_same_class (
958- values , placement = slice (0 , len (values )), ndim = 1
959- )
960- ],
956+ block .make_block_same_class (
957+ values , placement = slice (0 , len (values )), ndim = 1
958+ ),
961959 self .axes [1 ],
960+ fastpath = True ,
962961 )
963962
964963 def delete (self , item ):
@@ -1360,7 +1359,7 @@ def take(self, indexer, axis=1, verify=True, convert=True):
13601359 new_axis = new_labels , indexer = indexer , axis = axis , allow_dups = True
13611360 )
13621361
1363- def equals (self , other ):
1362+ def equals (self , other ) -> bool :
13641363 self_axes , other_axes = self .axes , other .axes
13651364 if len (self_axes ) != len (other_axes ):
13661365 return False
@@ -1385,7 +1384,8 @@ def canonicalize(block):
13851384 )
13861385
13871386 def unstack (self , unstacker_func , fill_value ):
1388- """Return a blockmanager with all blocks unstacked.
1387+ """
1388+ Return a BlockManager with all blocks unstacked..
13891389
13901390 Parameters
13911391 ----------
@@ -1538,7 +1538,7 @@ def get_values(self):
15381538 return np .array (self ._block .to_dense (), copy = False )
15391539
15401540 @property
1541- def _can_hold_na (self ):
1541+ def _can_hold_na (self ) -> bool :
15421542 return self ._block ._can_hold_na
15431543
15441544 def is_consolidated (self ):
@@ -1567,7 +1567,7 @@ def fast_xs(self, loc):
15671567 """
15681568 return self ._block .values [loc ]
15691569
1570- def concat (self , to_concat , new_axis ):
1570+ def concat (self , to_concat , new_axis ) -> "SingleBlockManager" :
15711571 """
15721572 Concatenate a list of SingleBlockManagers into a single
15731573 SingleBlockManager.
@@ -1582,7 +1582,6 @@ def concat(self, to_concat, new_axis):
15821582 Returns
15831583 -------
15841584 SingleBlockManager
1585-
15861585 """
15871586 non_empties = [x for x in to_concat if len (x ) > 0 ]
15881587
0 commit comments