Skip to content

TYP: annotate Block/BlockManager putmask #32769

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
merged 9 commits into from
Mar 22, 2020

Conversation

jbrockmendel
Copy link
Member

medium-term goal is to avoid passing Series/DataFrame objects to Block methods via BlockManager.apply

@jreback jreback added the Typing type annotations, mypy/pyright type checking label Mar 17, 2020
mask=mask,
new=new,
align=align,
inplace=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How feasible is it to align the inplace arg with blocks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block.putmask is called from other Block methods with inplace=False, so non-trivial

"""
putmask the data to the block; it is possible that we may create a
new dtype of block

return the resulting block(s)
Return the resulting blocks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can return a list with a single block? if so, i think block(s) is more appropriate


Returns
-------
a list of new blocks, the result of the putmask
List[Block]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from numpdoc for Returns section...

"Explanation of the returned values and their types. Similar to the Parameters section, except the name of each return value is optional. The type of each return value is always required"

the pandas docstring guide appears to say the same.

The guides do NOT say this section is optional.

so to comply something like...

Suggested change
List[Block]
list of Block
A list of new blocks, the result of the putmask.

personally, i'd be happy following the google style here.

"Describe the type and semantics of the return value. If the function only returns None, this section is not required. It may also be omitted if the docstring starts with Returns or Yields (e.g. """Returns row from Bigtable as a tuple of strings.""") and the opening sentence is sufficient to describe return value."

and make the returns section optional for internal docstings in the validation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use google style anywhere, this is quite descriptive.

align : bool, default True.
Perform alignment on other/cond.
inplace : bool, default False.
Perform inplace modification.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing axis and transpose parameters and descriptions.

personally, i'd be happy following the google style here...

"A method that overrides a method from a base class may have a simple docstring sending the reader to its overridden method’s docstring, such as """See base class.""". The rationale is that there is no need to repeat in many places documentation that is already present in the base method’s docstring. However, if the overriding method’s behavior is substantially different from the overridden method, or details need to be provided (e.g., documenting additional side effects), a docstring with at least those differences is required on the overriding method."

This docstring appears to be duplicate of Block.putmask with a minor inconsistency. i.e. Return the resulting blocks. vs return the resulting block

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the missing axis and transpose params ill do now, but for the rest (here and in other comments), can we not make this the PR where we start implementing the discussed standards? This is preliminary to more-important follow-ups.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not make this the PR where we start implementing the discussed standards

IIUC these are our standards already in existence for changes made in this PR.

As a responsible reviewer, just pointing out where the additions/changes in this PR don't meet those standards.

If you feel that this is an unnecessary distraction or disruptive to workflow, then that could be a valid argument in support for a more lightweight standard for internal docstrings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally reasonable, I rescind my request.

Used the see-parent-class-docstring pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel that this is an unnecessary distraction or disruptive to workflow, then that could be a valid argument in support for a more lightweight standard for internal docstrings.

You could also say that this more lightweight standard for internal docstrings already exist: we typically don't review those in such detail on formatting issues.
(and to be clear: I think it is good to have this discussion (but in the other issue), as it is certainly not clear or some kind of unspoken rule)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also say that this more lightweight standard for internal docstrings already exist: we typically don't review those in such detail on formatting issues.

I'm hoping that we can add validation of the internal docstrings to the CI and the CI won't be so lenient.

I think it is good to have this discussion (but in the other issue)

yes. sorry @jbrockmendel

@jbrockmendel
Copy link
Member Author

@simonjayhawkins i lost track, is there anything left actionable here?

@jbrockmendel
Copy link
Member Author

rebased+green

@jreback
Copy link
Contributor

jreback commented Mar 22, 2020

needs another rebase

@jbrockmendel
Copy link
Member Author

rebased+green

@jreback jreback added this to the 1.1 milestone Mar 22, 2020

Returns
-------
a list of new blocks, the result of the putmask
List[Block]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use google style anywhere, this is quite descriptive.

@jreback jreback merged commit 60269d9 into pandas-dev:master Mar 22, 2020
@jreback
Copy link
Contributor

jreback commented Mar 22, 2020

thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the putmask-typ branch March 22, 2020 21:01
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
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.

5 participants