Skip to content

Commit 9ceb029

Browse files
topper-123jreback
authored andcommitted
Add type hints for (BlockManager|SingleBlockManager).blocks (#26888)
1 parent 5828b31 commit 9ceb029

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pandas/core/internals/managers.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import itertools
44
import operator
55
import re
6-
from typing import List, Optional, Union
6+
from typing import List, Optional, Sequence, Tuple, Union
77

88
import numpy as np
99

@@ -95,9 +95,12 @@ class BlockManager(PandasObject):
9595
__slots__ = ['axes', 'blocks', '_ndim', '_shape', '_known_consolidated',
9696
'_is_consolidated', '_blknos', '_blklocs']
9797

98-
def __init__(self, blocks, axes, do_integrity_check=True):
98+
def __init__(self,
99+
blocks: Sequence[Block],
100+
axes: Sequence[Index],
101+
do_integrity_check: bool = True):
99102
self.axes = [ensure_index(ax) for ax in axes]
100-
self.blocks = tuple(blocks)
103+
self.blocks = tuple(blocks) # type: Tuple[Block, ...]
101104

102105
for block in blocks:
103106
if block.is_sparse:
@@ -1415,8 +1418,11 @@ class SingleBlockManager(BlockManager):
14151418
_known_consolidated = True
14161419
__slots__ = ()
14171420

1418-
def __init__(self, block, axis, do_integrity_check=False, fastpath=False):
1419-
1421+
def __init__(self,
1422+
block: Block,
1423+
axis: Union[Index, List[Index]],
1424+
do_integrity_check: bool = False,
1425+
fastpath: bool = False):
14201426
if isinstance(axis, list):
14211427
if len(axis) != 1:
14221428
raise ValueError("cannot create SingleBlockManager with more "
@@ -1455,7 +1461,7 @@ def __init__(self, block, axis, do_integrity_check=False, fastpath=False):
14551461
if not isinstance(block, Block):
14561462
block = make_block(block, placement=slice(0, len(axis)), ndim=1)
14571463

1458-
self.blocks = [block]
1464+
self.blocks = tuple([block])
14591465

14601466
def _post_setstate(self):
14611467
pass

0 commit comments

Comments
 (0)