8
8
import numpy as np
9
9
10
10
from pandas ._libs import Timedelta , Timestamp , internals as libinternals , lib
11
+ from pandas ._typing import DtypeObj
11
12
from pandas .util ._validators import validate_bool_kwarg
12
13
13
14
from pandas .core .dtypes .cast import (
@@ -847,7 +848,7 @@ def to_dict(self, copy: bool = True):
847
848
848
849
return {dtype : self .combine (blocks , copy = copy ) for dtype , blocks in bd .items ()}
849
850
850
- def fast_xs (self , loc ):
851
+ def fast_xs (self , loc : int ):
851
852
"""
852
853
get a cross sectional for a given location in the
853
854
items ; handle dups
@@ -883,12 +884,12 @@ def fast_xs(self, loc):
883
884
for i , rl in enumerate (blk .mgr_locs ):
884
885
result [rl ] = blk .iget ((i , loc ))
885
886
886
- if is_extension_array_dtype (dtype ):
887
+ if isinstance (dtype , ExtensionDtype ):
887
888
result = dtype .construct_array_type ()._from_sequence (result , dtype = dtype )
888
889
889
890
return result
890
891
891
- def consolidate (self ):
892
+ def consolidate (self ) -> "BlockManager" :
892
893
"""
893
894
Join together blocks having same dtype
894
895
@@ -940,7 +941,7 @@ def get(self, item):
940
941
new_axis = self .items [indexer ], indexer = indexer , axis = 0 , allow_dups = True
941
942
)
942
943
943
- def iget (self , i ) :
944
+ def iget (self , i : int ) -> "SingleBlockManager" :
944
945
"""
945
946
Return the data as a SingleBlockManager.
946
947
"""
@@ -1377,7 +1378,7 @@ def canonicalize(block):
1377
1378
block .equals (oblock ) for block , oblock in zip (self_blocks , other_blocks )
1378
1379
)
1379
1380
1380
- def unstack (self , unstacker_func , fill_value ):
1381
+ def unstack (self , unstacker_func , fill_value ) -> "BlockManager" :
1381
1382
"""
1382
1383
Return a BlockManager with all blocks unstacked..
1383
1384
@@ -1396,8 +1397,8 @@ def unstack(self, unstacker_func, fill_value):
1396
1397
dummy = unstacker_func (np .empty ((0 , 0 )), value_columns = self .items )
1397
1398
new_columns = dummy .get_new_columns ()
1398
1399
new_index = dummy .get_new_index ()
1399
- new_blocks = []
1400
- columns_mask = []
1400
+ new_blocks : List [ Block ] = []
1401
+ columns_mask : List [ np . ndarray ] = []
1401
1402
1402
1403
for blk in self .blocks :
1403
1404
blocks , mask = blk ._unstack (
@@ -1478,7 +1479,7 @@ def _post_setstate(self):
1478
1479
pass
1479
1480
1480
1481
@property
1481
- def _block (self ):
1482
+ def _block (self ) -> Block :
1482
1483
return self .blocks [0 ]
1483
1484
1484
1485
@property
@@ -1495,14 +1496,14 @@ def _blklocs(self):
1495
1496
""" compat with BlockManager """
1496
1497
return None
1497
1498
1498
- def get_slice (self , slobj , axis = 0 ) :
1499
+ def get_slice (self , slobj : slice , axis : int = 0 ) -> "SingleBlockManager" :
1499
1500
if axis >= self .ndim :
1500
1501
raise IndexError ("Requested axis not found in manager" )
1501
1502
1502
- return type (self )(self ._block ._slice (slobj ), self .index [slobj ], fastpath = True , )
1503
+ return type (self )(self ._block ._slice (slobj ), self .index [slobj ], fastpath = True )
1503
1504
1504
1505
@property
1505
- def index (self ):
1506
+ def index (self ) -> Index :
1506
1507
return self .axes [0 ]
1507
1508
1508
1509
@property
@@ -1516,7 +1517,7 @@ def array_dtype(self):
1516
1517
def get_dtype_counts (self ):
1517
1518
return {self .dtype .name : 1 }
1518
1519
1519
- def get_dtypes (self ):
1520
+ def get_dtypes (self ) -> np . ndarray :
1520
1521
return np .array ([self ._block .dtype ])
1521
1522
1522
1523
def external_values (self ):
@@ -1527,15 +1528,15 @@ def internal_values(self):
1527
1528
"""The array that Series._values returns"""
1528
1529
return self ._block .internal_values ()
1529
1530
1530
- def get_values (self ):
1531
+ def get_values (self ) -> np . ndarray :
1531
1532
""" return a dense type view """
1532
1533
return np .array (self ._block .to_dense (), copy = False )
1533
1534
1534
1535
@property
1535
1536
def _can_hold_na (self ) -> bool :
1536
1537
return self ._block ._can_hold_na
1537
1538
1538
- def is_consolidated (self ):
1539
+ def is_consolidated (self ) -> bool :
1539
1540
return True
1540
1541
1541
1542
def _consolidate_check (self ):
@@ -1813,9 +1814,7 @@ def _shape_compat(x):
1813
1814
return stacked , placement
1814
1815
1815
1816
1816
- def _interleaved_dtype (
1817
- blocks : List [Block ],
1818
- ) -> Optional [Union [np .dtype , ExtensionDtype ]]:
1817
+ def _interleaved_dtype (blocks : Sequence [Block ]) -> Optional [DtypeObj ]:
1819
1818
"""
1820
1819
Find the common dtype for `blocks`.
1821
1820
@@ -1825,7 +1824,7 @@ def _interleaved_dtype(
1825
1824
1826
1825
Returns
1827
1826
-------
1828
- dtype : Optional[Union[ np.dtype, ExtensionDtype]]
1827
+ dtype : np.dtype, ExtensionDtype, or None
1829
1828
None is returned when `blocks` is empty.
1830
1829
"""
1831
1830
if not len (blocks ):
0 commit comments