-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Centralize ops kwarg specification #19396
Conversation
""" | ||
Adds the full suite of flex arithmetic methods (``pow``, ``mul``, ``add``) | ||
to the class. | ||
|
||
Parameters | ||
---------- | ||
flex_arith_method : function | ||
factory for special arithmetic methods, with op string: | ||
f(op, name, str_rep, default_axis=None) | ||
factory for flex arithmetic methods, with op string: |
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.
Pretty sure "special" here was a copy/paste mistake. Please correct me if I'm wrong.
@@ -637,15 +632,9 @@ def safe_na_op(lvalues, rvalues): | |||
with np.errstate(all='ignore'): | |||
return na_op(lvalues, rvalues) | |||
except Exception: | |||
if isinstance(rvalues, ABCSeries): |
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.
isinstance(rvalues, ABCSeries)
is always False
because before calling safe_na_op
we do this same check and if True
set rvalues = rvalues.values
. If reviewers want to call this out-of-scope I'll remove it and make a separate PR.
@@ -1228,6 +1217,40 @@ def f(self, other, axis=None): | |||
return f | |||
|
|||
|
|||
def _flex_method_PANEL(op, name, str_rep=None): |
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.
Cut/pasted from Panel, with small re-workings to _agg_doc_PANEL.
@@ -1575,7 +1528,8 @@ def f(self, other, axis=0): | |||
'minor_axis': 'columns'}) | |||
|
|||
ops.add_special_arithmetic_methods(Panel, **ops.panel_special_funcs) | |||
Panel._add_aggregate_operations() | |||
ops.add_flex_arithmetic_methods(Panel, ops._flex_method_PANEL, |
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.
Making this match the usage everywhere else.
pandas/core/sparse/series.py
Outdated
@@ -41,13 +41,12 @@ | |||
# Wrapper function for Series arithmetic methods | |||
|
|||
|
|||
def _arith_method_SPARSE_SERIES(op, name, str_rep=None, default_axis=None): |
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.
Considering moving this and _arith_method_SPARSE_ARRAY to ops, so that all of the funcs called by ops.add_special* are in ops. (Also there is some duplication that may be removable). Thoughts?
Codecov Report
@@ Coverage Diff @@
## master #19396 +/- ##
==========================================
+ Coverage 91.65% 91.65% +<.01%
==========================================
Files 150 150
Lines 48726 48733 +7
==========================================
+ Hits 44658 44667 +9
+ Misses 4068 4066 -2
Continue to review full report at Codecov.
|
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.
looks fine, couple of comments.
pandas/core/ops.py
Outdated
# have default axis None, whereas flex methods have default axis 'columns' | ||
subtyp = getattr(cls, '_subtyp', '') | ||
use_numexpr = 'sparse' not in subtyp | ||
# numexpr is available for non-sparse classes |
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.
comments above the statement
|
||
Parameters | ||
---------- | ||
other : {construct} or {cls_name} | ||
axis : {{{axis_order}}} | ||
other : DataFrame or Panel |
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.
is this other correct?
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 matches the existing docstring
thanks! |
Follow-up to #19346, making **kwargs more explicit, documenting how they are chosen, moving one method from
Panel
that belongs incore.ops
.git diff upstream/master -u -- "*.py" | flake8 --diff