Skip to content

Commit adce628

Browse files
DOC:Add examples for SERIES ops -- mod,pow,truediv,floordiv (pandas-dev#24589)
1 parent 658ea82 commit adce628

File tree

1 file changed

+80
-3
lines changed

1 file changed

+80
-3
lines changed

pandas/core/ops.py

+80-3
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,83 @@ def _get_op_name(op, special):
488488
dtype: float64
489489
"""
490490

491+
_floordiv_example_SERIES = """
492+
Examples
493+
--------
494+
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
495+
>>> a
496+
a 1.0
497+
b 1.0
498+
c 1.0
499+
d NaN
500+
dtype: float64
501+
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
502+
>>> b
503+
a 1.0
504+
b NaN
505+
d 1.0
506+
e NaN
507+
dtype: float64
508+
>>> a.floordiv(b, fill_value=0)
509+
a 1.0
510+
b NaN
511+
c NaN
512+
d 0.0
513+
e NaN
514+
dtype: float64
515+
"""
516+
517+
_mod_example_SERIES = """
518+
Examples
519+
--------
520+
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
521+
>>> a
522+
a 1.0
523+
b 1.0
524+
c 1.0
525+
d NaN
526+
dtype: float64
527+
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
528+
>>> b
529+
a 1.0
530+
b NaN
531+
d 1.0
532+
e NaN
533+
dtype: float64
534+
>>> a.mod(b, fill_value=0)
535+
a 0.0
536+
b NaN
537+
c NaN
538+
d 0.0
539+
e NaN
540+
dtype: float64
541+
"""
542+
_pow_example_SERIES = """
543+
Examples
544+
--------
545+
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
546+
>>> a
547+
a 1.0
548+
b 1.0
549+
c 1.0
550+
d NaN
551+
dtype: float64
552+
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
553+
>>> b
554+
a 1.0
555+
b NaN
556+
d 1.0
557+
e NaN
558+
dtype: float64
559+
>>> a.pow(b, fill_value=0)
560+
a 1.0
561+
b 1.0
562+
c 1.0
563+
d 0.0
564+
e NaN
565+
dtype: float64
566+
"""
567+
491568
_op_descriptions = {
492569
# Arithmetic Operators
493570
'add': {'op': '+',
@@ -506,11 +583,11 @@ def _get_op_name(op, special):
506583
'mod': {'op': '%',
507584
'desc': 'Modulo',
508585
'reverse': 'rmod',
509-
'series_examples': None},
586+
'series_examples': _mod_example_SERIES},
510587
'pow': {'op': '**',
511588
'desc': 'Exponential power',
512589
'reverse': 'rpow',
513-
'series_examples': None,
590+
'series_examples': _pow_example_SERIES,
514591
'df_examples': None},
515592
'truediv': {'op': '/',
516593
'desc': 'Floating division',
@@ -520,7 +597,7 @@ def _get_op_name(op, special):
520597
'floordiv': {'op': '//',
521598
'desc': 'Integer division',
522599
'reverse': 'rfloordiv',
523-
'series_examples': None,
600+
'series_examples': _floordiv_example_SERIES,
524601
'df_examples': None},
525602
'divmod': {'op': 'divmod',
526603
'desc': 'Integer division and modulo',

0 commit comments

Comments
 (0)