-
-
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
Add type hints for (BlockManager|SingleBlockManager).blocks #26888
Conversation
e941ae7
to
32e07d0
Compare
pandas/core/internals/managers.py
Outdated
@@ -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]) # type: Tuple[Block] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BlockManager.blocks
is a tuple, so this should also be a tuple, and not a list,
Codecov Report
@@ Coverage Diff @@
## master #26888 +/- ##
===========================================
- Coverage 91.87% 41.12% -50.75%
===========================================
Files 180 180
Lines 50710 50710
===========================================
- Hits 46588 20854 -25734
- Misses 4122 29856 +25734
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26888 +/- ##
==========================================
- Coverage 91.87% 91.86% -0.01%
==========================================
Files 180 180
Lines 50710 50710
==========================================
- Hits 46588 46583 -5
- Misses 4122 4127 +5
Continue to review full report at Codecov.
|
a060687
to
9c7bde2
Compare
9c7bde2
to
974b28d
Compare
|
||
def __init__(self, | ||
block: Block, | ||
axis: Union[Index, List[Index]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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 axis: Index
, given that this is named axis
(vs. axes
for BlockManager.__init__
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was for consistency with Panel and 4dPandel etc, which isnt relevant anymore. I
ll look into changing it.
thanks @topper-123 |
This PR add a type hint for
(BlockManager|SingleBlockManager).blocks
and(BlockManager|SingleBlockManager).__init__
.This follows up to the type hints added in #26871 and makes it easier to work with the
BlockManager
and blocks in Pandas.