-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Changes from 2 commits
66a00fe
a8e79a9
3fcc6e5
0f9f370
2c3ae92
acf58ad
4c96eba
e30dc86
67ca8f5
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -925,26 +925,28 @@ def putmask( | |||||||
inplace: bool = False, | ||||||||
axis: int = 0, | ||||||||
transpose: bool = False, | ||||||||
): | ||||||||
) -> List["Block"]: | ||||||||
""" | ||||||||
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. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
mask : the condition to respect | ||||||||
mask : the condition to respect | ||||||||
simonjayhawkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
new : a ndarray/object | ||||||||
align : boolean, perform alignment on other/cond, default is True | ||||||||
inplace : perform inplace modification, default is False | ||||||||
align : bool, default True | ||||||||
Perform alignment on other/cond. | ||||||||
inplace : bool, default False | ||||||||
Perform inplace modification. | ||||||||
axis : int | ||||||||
transpose : boolean | ||||||||
Set to True if self is stored with axes reversed | ||||||||
transpose : bool, default False. | ||||||||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
Set to True if self is stored with axes reversed. | ||||||||
|
||||||||
Returns | ||||||||
------- | ||||||||
a list of new blocks, the result of the putmask | ||||||||
List[Block] | ||||||||
simonjayhawkins marked this conversation as resolved.
Show resolved
Hide resolved
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. 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
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. 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. we don't use google style anywhere, this is quite descriptive. |
||||||||
""" | ||||||||
new_values = self.values if inplace else self.values.copy() | ||||||||
|
||||||||
|
@@ -1670,8 +1672,14 @@ def set(self, locs, values, check=False): | |||||||
self.values = values | ||||||||
|
||||||||
def putmask( | ||||||||
self, mask, new, align=True, inplace=False, axis=0, transpose=False, | ||||||||
): | ||||||||
self, | ||||||||
mask, | ||||||||
new, | ||||||||
align: bool = True, | ||||||||
inplace: bool = False, | ||||||||
axis: int = 0, | ||||||||
transpose: bool = False, | ||||||||
) -> List["Block"]: | ||||||||
""" | ||||||||
putmask the data to the block; we must be a single block and not | ||||||||
generate other blocks | ||||||||
|
@@ -1680,14 +1688,16 @@ def putmask( | |||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
mask : the condition to respect | ||||||||
mask : the condition to respect | ||||||||
new : a ndarray/object | ||||||||
align : boolean, perform alignment on other/cond, default is True | ||||||||
inplace : perform inplace modification, default is False | ||||||||
align : bool, default True. | ||||||||
Perform alignment on other/cond. | ||||||||
inplace : bool, default False. | ||||||||
Perform inplace modification. | ||||||||
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. missing 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. 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. 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. 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.
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. 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. Totally reasonable, I rescind my request. Used the see-parent-class-docstring pattern. 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.
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. 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'm hoping that we can add validation of the internal docstrings to the CI and the CI won't be so lenient.
yes. sorry @jbrockmendel |
||||||||
|
||||||||
Returns | ||||||||
------- | ||||||||
a new block, the result of the putmask | ||||||||
List[Block] | ||||||||
""" | ||||||||
inplace = validate_bool_kwarg(inplace, "inplace") | ||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -566,8 +566,20 @@ def where(self, **kwargs) -> "BlockManager": | |
def setitem(self, indexer, value) -> "BlockManager": | ||
return self.apply("setitem", indexer=indexer, value=value) | ||
|
||
def putmask(self, **kwargs): | ||
return self.apply("putmask", **kwargs) | ||
def putmask( | ||
self, mask, new, align: bool = True, axis: int = 0, | ||
): | ||
transpose = self.ndim == 2 | ||
|
||
return self.apply( | ||
"putmask", | ||
mask=mask, | ||
new=new, | ||
align=align, | ||
inplace=True, | ||
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. How feasible is it to align the inplace arg with blocks? 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. Block.putmask is called from other Block methods with inplace=False, so non-trivial |
||
axis=axis, | ||
transpose=transpose, | ||
) | ||
|
||
def diff(self, n: int, axis: int) -> "BlockManager": | ||
return self.apply("diff", n=n, axis=axis) | ||
|
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.
can return a list with a single block? if so, i think
block(s)
is more appropriate