@@ -110,8 +110,6 @@ class BlockManager(PandasObject):
110
110
__slots__ = [
111
111
"axes" ,
112
112
"blocks" ,
113
- "_ndim" ,
114
- "_shape" ,
115
113
"_known_consolidated" ,
116
114
"_is_consolidated" ,
117
115
"_blknos" ,
@@ -759,9 +757,7 @@ def get_slice(self, slobj: slice, axis: int = 0) -> "BlockManager":
759
757
if axis == 0 :
760
758
new_blocks = self ._slice_take_blocks_ax0 (slobj )
761
759
elif axis == 1 :
762
- _slicer = [slice (None )] * (axis + 1 )
763
- _slicer [axis ] = slobj
764
- slicer = tuple (_slicer )
760
+ slicer = (slice (None ), slobj )
765
761
new_blocks = [blk .getitem_block (slicer ) for blk in self .blocks ]
766
762
else :
767
763
raise IndexError ("Requested axis not found in manager" )
@@ -1103,7 +1099,6 @@ def value_getitem(placement):
1103
1099
if len (val_locs ) == len (blk .mgr_locs ):
1104
1100
removed_blknos .append (blkno )
1105
1101
else :
1106
- self ._blklocs [blk .mgr_locs .indexer ] = - 1
1107
1102
blk .delete (blk_locs )
1108
1103
self ._blklocs [blk .mgr_locs .indexer ] = np .arange (len (blk ))
1109
1104
@@ -1115,9 +1110,7 @@ def value_getitem(placement):
1115
1110
new_blknos = np .empty (self .nblocks , dtype = np .int64 )
1116
1111
new_blknos .fill (- 1 )
1117
1112
new_blknos [~ is_deleted ] = np .arange (self .nblocks - len (removed_blknos ))
1118
- self ._blknos = algos .take_1d (
1119
- new_blknos , self ._blknos , axis = 0 , allow_fill = False
1120
- )
1113
+ self ._blknos = new_blknos [self ._blknos ]
1121
1114
self .blocks = tuple (
1122
1115
blk for i , blk in enumerate (self .blocks ) if i not in set (removed_blknos )
1123
1116
)
@@ -1128,8 +1121,9 @@ def value_getitem(placement):
1128
1121
1129
1122
new_blocks : List [Block ] = []
1130
1123
if value_is_extension_type :
1131
- # This code (ab-)uses the fact that sparse blocks contain only
1124
+ # This code (ab-)uses the fact that EA blocks contain only
1132
1125
# one item.
1126
+ # TODO(EA2D): special casing unnecessary with 2D EAs
1133
1127
new_blocks .extend (
1134
1128
make_block (
1135
1129
values = value ,
@@ -1162,7 +1156,7 @@ def value_getitem(placement):
1162
1156
# Newly created block's dtype may already be present.
1163
1157
self ._known_consolidated = False
1164
1158
1165
- def insert (self , loc : int , item , value , allow_duplicates : bool = False ):
1159
+ def insert (self , loc : int , item : Label , value , allow_duplicates : bool = False ):
1166
1160
"""
1167
1161
Insert item at selected position.
1168
1162
@@ -1185,7 +1179,7 @@ def insert(self, loc: int, item, value, allow_duplicates: bool = False):
1185
1179
# insert to the axis; this could possibly raise a TypeError
1186
1180
new_axis = self .items .insert (loc , item )
1187
1181
1188
- if value .ndim == self .ndim - 1 and not is_extension_array_dtype (value ):
1182
+ if value .ndim == self .ndim - 1 and not is_extension_array_dtype (value . dtype ):
1189
1183
value = _safe_reshape (value , (1 ,) + value .shape )
1190
1184
1191
1185
block = make_block (values = value , ndim = self .ndim , placement = slice (loc , loc + 1 ))
@@ -1959,14 +1953,14 @@ def _compare_or_regex_search(a, b, regex=False):
1959
1953
return result
1960
1954
1961
1955
1962
- def _fast_count_smallints (arr ) :
1956
+ def _fast_count_smallints (arr : np . ndarray ) -> np . ndarray :
1963
1957
"""Faster version of set(arr) for sequences of small numbers."""
1964
1958
counts = np .bincount (arr .astype (np .int_ ))
1965
1959
nz = counts .nonzero ()[0 ]
1966
1960
return np .c_ [nz , counts [nz ]]
1967
1961
1968
1962
1969
- def _preprocess_slice_or_indexer (slice_or_indexer , length , allow_fill ):
1963
+ def _preprocess_slice_or_indexer (slice_or_indexer , length : int , allow_fill : bool ):
1970
1964
if isinstance (slice_or_indexer , slice ):
1971
1965
return (
1972
1966
"slice" ,
0 commit comments