Skip to content

Commit 93e8cf5

Browse files
DOC: Added series operation name/example to flex_doc
1 parent 12a0dc4 commit 93e8cf5

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

pandas/core/ops.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,30 @@ def _get_op_name(op, special):
486486
e NaN -4.0 NaN
487487
"""
488488

489+
_mul_example_FRAME = """
490+
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
491+
>>> a
492+
a 1.0
493+
b 1.0
494+
c 1.0
495+
d NaN
496+
dtype: float64
497+
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
498+
>>> b
499+
a 1.0
500+
b NaN
501+
d 1.0
502+
e NaN
503+
dtype: float64
504+
>>> a.multiply(b, fill_value=0)
505+
a 1.0
506+
b 0.0
507+
c 0.0
508+
d 0.0
509+
e NaN
510+
dtype: float64
511+
"""
512+
489513
_op_descriptions = {
490514
# Arithmetic Operators
491515
'add': {'op': '+',
@@ -499,7 +523,7 @@ def _get_op_name(op, special):
499523
'mul': {'op': '*',
500524
'desc': 'Multiplication',
501525
'reverse': 'rmul',
502-
'df_examples': None},
526+
'df_examples': _mul_example_FRAME},
503527
'mod': {'op': '%',
504528
'desc': 'Modulo',
505529
'reverse': 'rmod',
@@ -580,31 +604,12 @@ def _get_op_name(op, special):
580604
581605
Examples
582606
--------
583-
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
584-
>>> a
585-
a 1.0
586-
b 1.0
587-
c 1.0
588-
d NaN
589-
dtype: float64
590-
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
591-
>>> b
592-
a 1.0
593-
b NaN
594-
d 1.0
595-
e NaN
596-
dtype: float64
597-
>>> a.add(b, fill_value=0)
598-
a 2.0
599-
b 1.0
600-
c 1.0
601-
d 1.0
602-
e NaN
603-
dtype: float64
607+
{df_examples}
604608
605609
See also
606610
--------
607611
Series.{reverse}
612+
608613
"""
609614

610615
_arith_doc_FRAME = """
@@ -690,7 +695,6 @@ def _get_op_name(op, special):
690695
Panel.{reverse}
691696
"""
692697

693-
694698
_agg_doc_PANEL = """
695699
Wrapper method for {op_name}
696700
@@ -732,7 +736,8 @@ def _make_flex_doc(op_name, typ):
732736
if typ == 'series':
733737
base_doc = _flex_doc_SERIES
734738
doc = base_doc.format(desc=op_desc['desc'], op_name=op_name,
735-
equiv=equiv, reverse=op_desc['reverse'])
739+
equiv=equiv, reverse=op_desc['reverse'],
740+
df_examples=op_desc['df_examples'])
736741
elif typ == 'dataframe':
737742
base_doc = _flex_doc_FRAME
738743
doc = base_doc.format(desc=op_desc['desc'], op_name=op_name,
@@ -1296,7 +1301,7 @@ def wrapper(left, right):
12961301
"{op}".format(typ=type(left).__name__, op=str_rep))
12971302

12981303
elif (is_extension_array_dtype(left) or
1299-
(is_extension_array_dtype(right) and not is_scalar(right))):
1304+
(is_extension_array_dtype(right) and not is_scalar(right))):
13001305
# GH#22378 disallow scalar to exclude e.g. "category", "Int64"
13011306
return dispatch_to_extension_op(op, left, right)
13021307

0 commit comments

Comments
 (0)