Skip to content

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

Merged

Conversation

topper-123
Copy link
Contributor

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.

@topper-123 topper-123 force-pushed the add_types_for_BlockManager.blocks branch from e941ae7 to 32e07d0 Compare June 16, 2019 18:43
@@ -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]
Copy link
Contributor Author

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
Copy link

codecov bot commented Jun 16, 2019

Codecov Report

Merging #26888 into master will decrease coverage by 50.74%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Flag Coverage Δ
#multiple ?
#single 41.12% <100%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/core/internals/managers.py 66.18% <100%> (-29.04%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/plotting/_matplotlib/__init__.py 0% <0%> (-100%) ⬇️
pandas/io/gcs.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/io/s3.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-99.37%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.16%) ⬇️
... and 133 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9326c1e...a060687. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 16, 2019

Codecov Report

Merging #26888 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.45% <100%> (ø) ⬆️
#single 41.1% <100%> (-0.11%) ⬇️
Impacted Files Coverage Δ
pandas/core/internals/managers.py 95.21% <100%> (ø) ⬆️
pandas/io/gbq.py 88.88% <0%> (-11.12%) ⬇️
pandas/core/frame.py 96.88% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.84% <0%> (-0.11%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9326c1e...974b28d. Read the comment docs.

@topper-123 topper-123 force-pushed the add_types_for_BlockManager.blocks branch from a060687 to 9c7bde2 Compare June 16, 2019 19:49
@topper-123 topper-123 force-pushed the add_types_for_BlockManager.blocks branch from 9c7bde2 to 974b28d Compare June 16, 2019 20:44

def __init__(self,
block: Block,
axis: Union[Index, List[Index]],
Copy link
Contributor

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?

Copy link
Contributor Author

@topper-123 topper-123 Jun 17, 2019

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.

Copy link
Contributor Author

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__).

Copy link
Contributor

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.

Copy link
Contributor Author

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. Ill look into changing it.

@jreback jreback added the Typing type annotations, mypy/pyright type checking label Jun 17, 2019
@jreback jreback added this to the 0.25.0 milestone Jun 19, 2019
@jreback jreback merged commit 9ceb029 into pandas-dev:master Jun 19, 2019
@jreback
Copy link
Contributor

jreback commented Jun 19, 2019

thanks @topper-123

@topper-123 topper-123 deleted the add_types_for_BlockManager.blocks branch June 19, 2019 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants