-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add type hints for (BlockManager|SingleBlockManager).blocks #26888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import itertools | ||
import operator | ||
import re | ||
from typing import List, Optional, Union | ||
from typing import List, Optional, Sequence, Tuple, Union | ||
|
||
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]], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. really? when is this an actual Index? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it can be either. For example, when printing a DataFrame, it is supplied either a index or a list of a single index in various stages of the printing operation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be more consistent that it'd pick one of the two options. I'd prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, I think this was for consistency with a BlockManger where you have 2 axes; ok with changing this (followup PR); not sure how much this would take to make consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was for consistency with Panel and 4dPandel etc, which isn |
||
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 = tuple([block]) | ||
|
||
def _post_setstate(self): | ||
pass | ||
|
Uh oh!
There was an error while loading. Please reload this page.