3
3
import itertools
4
4
import operator
5
5
import re
6
- from typing import List , Optional , Sequence , Tuple , Union
6
+ from typing import Dict , List , Optional , Sequence , Tuple , Union
7
7
8
8
import numpy as np
9
9
@@ -181,23 +181,23 @@ def set_axis(self, axis, new_labels):
181
181
182
182
self .axes [axis ] = new_labels
183
183
184
- def rename_axis (self , mapper , axis , copy = True , level = None ):
184
+ def rename_axis (self , mapper , axis , copy : bool = True , level = None ):
185
185
"""
186
186
Rename one of axes.
187
187
188
188
Parameters
189
189
----------
190
190
mapper : unary callable
191
191
axis : int
192
- copy : boolean , default True
192
+ copy : bool , default True
193
193
level : int, default None
194
194
"""
195
195
obj = self .copy (deep = copy )
196
196
obj .set_axis (axis , _transform_index (self .axes [axis ], mapper , level ))
197
197
return obj
198
198
199
199
@property
200
- def _is_single_block (self ):
200
+ def _is_single_block (self ) -> bool :
201
201
if self .ndim == 1 :
202
202
return True
203
203
@@ -441,9 +441,9 @@ def quantile(
441
441
Parameters
442
442
----------
443
443
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
445
445
dtype
446
- transposed: boolean , default False
446
+ transposed: bool , default False
447
447
we are holding transposed data
448
448
interpolation : type of interpolation, default 'linear'
449
449
qs : a scalar or list of the quantiles to be computed
@@ -525,7 +525,9 @@ def get_axe(block, qs, axes):
525
525
values = values .take (indexer )
526
526
527
527
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 ,
529
531
)
530
532
531
533
def isna (self , func ):
@@ -635,24 +637,24 @@ def _consolidate_check(self):
635
637
self ._known_consolidated = True
636
638
637
639
@property
638
- def is_mixed_type (self ):
640
+ def is_mixed_type (self ) -> bool :
639
641
# Warning, consolidation needs to get checked upstairs
640
642
self ._consolidate_inplace ()
641
643
return len (self .blocks ) > 1
642
644
643
645
@property
644
- def is_numeric_mixed_type (self ):
646
+ def is_numeric_mixed_type (self ) -> bool :
645
647
# Warning, consolidation needs to get checked upstairs
646
648
self ._consolidate_inplace ()
647
649
return all (block .is_numeric for block in self .blocks )
648
650
649
651
@property
650
- def any_extension_types (self ):
652
+ def any_extension_types (self ) -> bool :
651
653
"""Whether any of the blocks in this manager are extension blocks"""
652
654
return any (block .is_extension for block in self .blocks )
653
655
654
656
@property
655
- def is_view (self ):
657
+ def is_view (self ) -> bool :
656
658
""" return a boolean if we are a single block and are a view """
657
659
if len (self .blocks ) == 1 :
658
660
return self .blocks [0 ].is_view
@@ -666,21 +668,21 @@ def is_view(self):
666
668
667
669
return False
668
670
669
- def get_bool_data (self , copy = False ):
671
+ def get_bool_data (self , copy : bool = False ):
670
672
"""
671
673
Parameters
672
674
----------
673
- copy : boolean , default False
675
+ copy : bool , default False
674
676
Whether to copy the blocks
675
677
"""
676
678
self ._consolidate_inplace ()
677
679
return self .combine ([b for b in self .blocks if b .is_bool ], copy )
678
680
679
- def get_numeric_data (self , copy = False ):
681
+ def get_numeric_data (self , copy : bool = False ):
680
682
"""
681
683
Parameters
682
684
----------
683
- copy : boolean , default False
685
+ copy : bool , default False
684
686
Whether to copy the blocks
685
687
"""
686
688
self ._consolidate_inplace ()
@@ -772,8 +774,8 @@ def as_array(self, transpose: bool = False) -> np.ndarray:
772
774
773
775
Parameters
774
776
----------
775
- transpose : boolean , default False
776
- If True, transpose the return array
777
+ transpose : bool , default False
778
+ If True, transpose the return array,
777
779
778
780
Returns
779
781
-------
@@ -825,13 +827,13 @@ def _interleave(self):
825
827
826
828
return result
827
829
828
- def to_dict (self , copy = True ):
830
+ def to_dict (self , copy : bool = True ):
829
831
"""
830
832
Return a dict of str(dtype) -> BlockManager
831
833
832
834
Parameters
833
835
----------
834
- copy : boolean , default True
836
+ copy : bool , default True
835
837
836
838
Returns
837
839
-------
@@ -843,7 +845,7 @@ def to_dict(self, copy=True):
843
845
"""
844
846
self ._consolidate_inplace ()
845
847
846
- bd = {}
848
+ bd : Dict [ str , List [ Block ]] = {}
847
849
for b in self .blocks :
848
850
bd .setdefault (str (b .dtype ), []).append (b )
849
851
@@ -944,21 +946,18 @@ def get(self, item):
944
946
945
947
def iget (self , i ):
946
948
"""
947
- Return the data as a SingleBlockManager if possible
948
-
949
- Otherwise return as a ndarray
949
+ Return the data as a SingleBlockManager.
950
950
"""
951
951
block = self .blocks [self ._blknos [i ]]
952
952
values = block .iget (self ._blklocs [i ])
953
953
954
954
# shortcut for select a single-dim from a 2-dim BM
955
955
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
+ ),
961
959
self .axes [1 ],
960
+ fastpath = True ,
962
961
)
963
962
964
963
def delete (self , item ):
@@ -1360,7 +1359,7 @@ def take(self, indexer, axis=1, verify=True, convert=True):
1360
1359
new_axis = new_labels , indexer = indexer , axis = axis , allow_dups = True
1361
1360
)
1362
1361
1363
- def equals (self , other ):
1362
+ def equals (self , other ) -> bool :
1364
1363
self_axes , other_axes = self .axes , other .axes
1365
1364
if len (self_axes ) != len (other_axes ):
1366
1365
return False
@@ -1385,7 +1384,8 @@ def canonicalize(block):
1385
1384
)
1386
1385
1387
1386
def unstack (self , unstacker_func , fill_value ):
1388
- """Return a blockmanager with all blocks unstacked.
1387
+ """
1388
+ Return a BlockManager with all blocks unstacked..
1389
1389
1390
1390
Parameters
1391
1391
----------
@@ -1538,7 +1538,7 @@ def get_values(self):
1538
1538
return np .array (self ._block .to_dense (), copy = False )
1539
1539
1540
1540
@property
1541
- def _can_hold_na (self ):
1541
+ def _can_hold_na (self ) -> bool :
1542
1542
return self ._block ._can_hold_na
1543
1543
1544
1544
def is_consolidated (self ):
@@ -1567,7 +1567,7 @@ def fast_xs(self, loc):
1567
1567
"""
1568
1568
return self ._block .values [loc ]
1569
1569
1570
- def concat (self , to_concat , new_axis ):
1570
+ def concat (self , to_concat , new_axis ) -> "SingleBlockManager" :
1571
1571
"""
1572
1572
Concatenate a list of SingleBlockManagers into a single
1573
1573
SingleBlockManager.
@@ -1582,7 +1582,6 @@ def concat(self, to_concat, new_axis):
1582
1582
Returns
1583
1583
-------
1584
1584
SingleBlockManager
1585
-
1586
1585
"""
1587
1586
non_empties = [x for x in to_concat if len (x ) > 0 ]
1588
1587
0 commit comments