8000 DOC: Add examples to Series operators (#24589) by sullivanbt · Pull Request #32704 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DOC: Add examples to Series operators (#24589) #32704

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move variable creation to common variable
  • Loading branch information
sullivanbt committed Mar 22, 2020
commit 926a3cfac146bcfa25d020f25595cae45abd5fb8
264 changes: 40 additions & 224 deletions pandas/core/ops/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _make_flex_doc(op_name, typ):
return doc


_add_example_SERIES = """
_common_examples_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
Expand All @@ -69,33 +69,39 @@ def _make_flex_doc(op_name, typ):
b NaN
d 1.0
e NaN
dtype: float64
>>> a.add(b, fill_value=0)
a 2.0
b 1.0
c 1.0
d 1.0
e NaN
dtype: float64
"""
dtype: float64"""

_sub_example_SERIES = """
_common_examples_comparison_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
e 1.0
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
>>> b
a 1.0
b NaN
a 0.0
b 1.0
c 2.0
d NaN
f 1.0
dtype: float64"""

_add_example_SERIES = _common_examples_SERIES + """
>>> a.add(b, fill_value=0)
a 2.0
b 1.0
c 1.0
d 1.0
e NaN
dtype: float64
"""

_sub_example_SERIES = _common_examples_SERIES + """
>>> a.subtract(b, fill_value=0)
a 0.0
b 1.0
Expand All @@ -105,23 +111,7 @@ def _make_flex_doc(op_name, typ):
dtype: float64
"""

_mul_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b
a 1.0
b NaN
d 1.0
e NaN
dtype: float64
_mul_example_SERIES = _common_examples_SERIES + """
>>> a.multiply(b, fill_value=0)
a 1.0
b 0.0
Expand All @@ -131,23 +121,7 @@ def _make_flex_doc(op_name, typ):
dtype: float64
"""

_div_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b
a 1.0
b NaN
d 1.0
e NaN
dtype: float64
_div_example_SERIES = _common_examples_SERIES + """
>>> a.divide(b, fill_value=0)
a 1.0
b inf
Expand All @@ -157,23 +131,7 @@ def _make_flex_doc(op_name, typ):
dtype: float64
"""

_floordiv_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b
a 1.0
b NaN
d 1.0
e NaN
dtype: float64
_floordiv_example_SERIES = _common_examples_SERIES + """
>>> a.floordiv(b, fill_value=0)
a 1.0
b NaN
Expand All @@ -183,23 +141,7 @@ def _make_flex_doc(op_name, typ):
dtype: float64
"""

_mod_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b
a 1.0
b NaN
d 1.0
e NaN
dtype: float64
_mod_example_SERIES = _common_examples_SERIES + """
>>> a.mod(b, fill_value=0)
a 0.0
b NaN
Expand All @@ -208,23 +150,7 @@ def _make_flex_doc(op_name, typ):
e NaN
dtype: float64
"""
_pow_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b
a 1.0
b NaN
d 1.0
e NaN
dtype: float64
_pow_example_SERIES = _common_examples_SERIES + """
>>> a.pow(b, fill_value=0)
a 1.0
b 1.0
Expand All @@ -234,83 +160,27 @@ def _make_flex_doc(op_name, typ):
dtype: float64
"""

_ne_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, np.nan, np.nan, 0], index=['a', 'b', 'c', 'd', 'e'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
e 1.0
dtype: float64
>>> b = pd.Series([0, 1, np.nan, 0, 1], index=['a', 'b', 'c', 'd', 'f'])
>>> b
a 0.0
b 1.0
c 2.0
d NaN
f 1.0
dtype: float64
_ne_example_SERIES = _common_examples_SERIES + """
>>> a.ne(b, fill_value=0)
a True
b False
a False
b True
c True
d False
e False
f True
d True
e True
dtype: bool
"""

_eq_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, np.nan, np.nan, 0], index=['a', 'b', 'c', 'd', 'e'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
e 1.0
dtype: float64
>>> b = pd.Series([0, 1, np.nan, 0, 1], index=['a', 'b', 'c', 'd', 'f'])
>>> b
a 0.0
b 1.0
c 2.0
d NaN
f 1.0
dtype: float64
_eq_example_SERIES = _common_examples_SERIES + """
>>> a.eq(b, fill_value=0)
a False
b True
a True
b False
c False
d True
e True
f False
d False
e False
dtype: bool
"""

_lt_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
e 1.0
dtype: float64
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
>>> b
a 0.0
b 1.0
c 2.0
d NaN
f 1.0
dtype: float64
_lt_example_SERIES = _common_examples_comparison_SERIES + """
>>> a.lt(b, fill_value=0)
a False
b False
Expand All @@ -321,25 +191,7 @@ def _make_flex_doc(op_name, typ):
dtype: bool
"""

_le_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
e 1.0
dtype: float64
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
>>> b
a 0.0
b 1.0
c 2.0
d NaN
f 1.0
dtype: float64
_le_example_SERIES = _common_examples_comparison_SERIES + """
>>> a.le(b, fill_value=0)
a False
b True
Expand All @@ -350,25 +202,7 @@ def _make_flex_doc(op_name, typ):
dtype: bool
"""

_gt_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
e 1.0
dtype: float64
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
>>> b
a 0.0
b 1.0
c 2.0
d NaN
f 1.0
dtype: float64
_gt_example_SERIES = _common_examples_comparison_SERIES + """
>>> a.gt(b, fill_value=0)
a True
b False
Expand All @@ -379,25 +213,7 @@ def _make_flex_doc(op_name, typ):
dtype: bool
"""

_ge_example_SERIES = """
Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
>>> a
a 1.0
b 1.0
c 1.0
d NaN
e 1.0
dtype: float64
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
>>> b
a 0.0
b 1.0
c 2.0
d NaN
f 1.0
dtype: float64
_ge_example_SERIES = _common_examples_comparison_SERIES + """
>>> a.ge(b, fill_value=0)
a True
b True
Expand Down
0