From 32e07d0ba430d6632e1b9aa9137131c9fcb88a84 Mon Sep 17 00:00:00 2001 From: tp Date: Sun, 16 Jun 2019 20:02:45 +0200 Subject: [PATCH 1/2] Add type hints for (BlockManager|SingleBlockManager).blocks --- pandas/core/internals/managers.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index a1e5468e2f871..5f88116670543 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -3,7 +3,7 @@ import itertools import operator import re -from typing import List, Optional, Union +from typing import List, Optional, Union, Sequence, Tuple import numpy as np @@ -95,9 +95,12 @@ class BlockManager(PandasObject): __slots__ = ['axes', 'blocks', '_ndim', '_shape', '_known_consolidated', '_is_consolidated', '_blknos', '_blklocs'] - def __init__(self, blocks, axes, do_integrity_check=True): + def __init__(self, + blocks: Sequence[Block], + axes: Sequence[Index], + do_integrity_check: bool = True): self.axes = [ensure_index(ax) for ax in axes] - self.blocks = tuple(blocks) + self.blocks = tuple(blocks) # type: Tuple[Block, ...] for block in blocks: if block.is_sparse: @@ -1415,8 +1418,11 @@ class SingleBlockManager(BlockManager): _known_consolidated = True __slots__ = () - def __init__(self, block, axis, do_integrity_check=False, fastpath=False): - + def __init__(self, + block: Block, + axis: Union[Index, List[Index]], + do_integrity_check: bool = False, + fastpath: bool = False): if isinstance(axis, list): if len(axis) != 1: raise ValueError("cannot create SingleBlockManager with more " @@ -1455,7 +1461,7 @@ def __init__(self, block, axis, do_integrity_check=False, fastpath=False): if not isinstance(block, Block): block = make_block(block, placement=slice(0, len(axis)), ndim=1) - self.blocks = [block] + self.blocks = [block] # type: List[Block] def _post_setstate(self): pass From 974b28db59db7c43c810bcd29114c60129b88744 Mon Sep 17 00:00:00 2001 From: tp Date: Sun, 16 Jun 2019 20:50:57 +0200 Subject: [PATCH 2/2] SingleBlockManager.blocks should be a tuple --- pandas/core/internals/managers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 5f88116670543..907498c7ff350 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -3,7 +3,7 @@ import itertools import operator import re -from typing import List, Optional, Union, Sequence, Tuple +from typing import List, Optional, Sequence, Tuple, Union import numpy as np @@ -1461,7 +1461,7 @@ def __init__(self, if not isinstance(block, Block): block = make_block(block, placement=slice(0, len(axis)), ndim=1) - self.blocks = [block] # type: List[Block] + self.blocks = tuple([block]) def _post_setstate(self): pass