Skip to content

Commit 3f39226

Browse files
committed
DOC: improve binary operator docs (fixes pandas-dev#10093)
1 parent 0517eac commit 3f39226

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

pandas/core/ops.py

+29-5
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,31 @@ def _radd_compat(left, right):
703703

704704
return output
705705

706+
_op_descriptions = {'add': 'addition',
707+
'radd': 'addition in the reverse order of operands compared to add',
708+
'sub': 'subtraction',
709+
'rsub': 'subtraction in the reverse order of operands compared to sub',
710+
'mul': 'multiplication',
711+
'rmul': 'multiplication in the reverse order of operands compared to mul',
712+
'mod': 'modulo',
713+
'rmod': 'modulo in the reverse order of operands compared to mod',
714+
'pow': 'exponential power',
715+
'rpow': 'exponential power in the reverse order of operands compared to pow',
716+
'truediv': 'floating division',
717+
'rtruediv': 'floating division in the reverse order of operands compared to truediv',
718+
'floordiv': 'integer division',
719+
'rfloordiv': 'integer division in the reverse order of operands compared to floordiv'}
706720

707721
def _flex_method_SERIES(op, name, str_rep, default_axis=None,
708722
fill_zeros=None, **eval_kwargs):
723+
desc = name
724+
if _op_descriptions.get(name):
725+
desc = desc + ' (' + _op_descriptions.get(name) + ')'
726+
709727
doc = """
710-
Binary operator %s with support to substitute a fill_value for missing data
711-
in one of the inputs
728+
Binary operator %s.
729+
This supports substituting a fill_value for missing data
730+
in one of the inputs.
712731
713732
Parameters
714733
----------
@@ -723,7 +742,7 @@ def _flex_method_SERIES(op, name, str_rep, default_axis=None,
723742
Returns
724743
-------
725744
result : Series
726-
""" % name
745+
""" % desc
727746

728747
@Appender(doc)
729748
def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
@@ -754,7 +773,8 @@ def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
754773

755774

756775
_arith_doc_FRAME = """
757-
Binary operator %s with support to substitute a fill_value for missing data in
776+
Binary operator %s.
777+
This supports substituting a fill_value for missing data in
758778
one of the inputs
759779
760780
Parameters
@@ -813,7 +833,11 @@ def na_op(x, y):
813833

814834
return result
815835

816-
@Appender(_arith_doc_FRAME % name)
836+
desc = name
837+
if _op_descriptions.get(name):
838+
desc = desc + ' (' + _op_descriptions.get(name) + ')'
839+
840+
@Appender(_arith_doc_FRAME % desc)
817841
def f(self, other, axis=default_axis, level=None, fill_value=None):
818842
if isinstance(other, pd.DataFrame): # Another DataFrame
819843
return self._combine_frame(other, na_op, fill_value, level)

pandas/core/panel.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import pandas.core.nanops as nanops
3131
import pandas.computation.expressions as expressions
3232
from pandas import lib
33+
from pandas.core.ops import _op_descriptions
34+
3335

3436
_shared_doc_kwargs = dict(
3537
axes='items, major_axis, minor_axis',
@@ -1437,7 +1439,7 @@ def _add_aggregate_operations(cls, use_numexpr=True):
14371439
----------
14381440
other : %s or %s""" % (cls._constructor_sliced.__name__, cls.__name__) + """
14391441
axis : {""" + ', '.join(cls._AXIS_ORDERS) + "}" + """
1440-
Axis to broadcast over
1442+
Axis to broadcast over
14411443
14421444
Returns
14431445
-------
@@ -1459,7 +1461,10 @@ def na_op(x, y):
14591461
result = com._fill_zeros(result, x, y, name, fill_zeros)
14601462
return result
14611463

1462-
@Substitution(name)
1464+
desc = name
1465+
if _op_descriptions.get(name):
1466+
desc = desc + ' (' + _op_descriptions.get(name) + ')'
1467+
@Substitution(desc)
14631468
@Appender(_agg_doc)
14641469
def f(self, other, axis=0):
14651470
return self._combine(other, na_op, axis=axis)

0 commit comments

Comments
 (0)