-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: fixed doc-string for combine & combine_first in pandas/core/series.py #22971
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
Changes from 14 commits
06e5af0
6d1dae6
63c6b4b
52955a3
bf123bd
de2a6e2
2ee7f4a
52c1911
c921539
c9a2490
0a00632
8c928f5
f6099da
edc1524
7390f46
8804436
ddd3e12
7902672
e35a038
02521e7
efd42ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
""" | ||
from __future__ import division | ||
|
||
# pylint: disable=E1101,E1103 | ||
# pylint: disable=W0703,W0622,W0613,W0201 | ||
|
||
import warnings | ||
from textwrap import dedent | ||
import warnings | ||
|
||
|
@@ -2281,36 +2285,62 @@ def _binop(self, other, func, level=None, fill_value=None): | |
|
||
def combine(self, other, func, fill_value=None): | ||
""" | ||
Perform elementwise binary operation on two Series using given function | ||
with optional fill value when an index is missing from one Series or | ||
the other | ||
Combine the Series with a Series or scalar according to `func`. | ||
|
||
Combine the Series and `other` using `func` to perform elementwise | ||
selection for combined Series. | ||
`fill_value` is assumed when value is missing at some index | ||
from one of the two objects being combined. | ||
|
||
Parameters | ||
---------- | ||
other : Series or scalar value | ||
other : Series or scalar | ||
The value(s) to be combined with the `Series`. | ||
func : function | ||
Function that takes two scalars as inputs and return a scalar | ||
fill_value : scalar value | ||
The default specifies to use the appropriate NaN value for | ||
the underlying dtype of the Series | ||
Function that takes two scalars as inputs and returns an element. | ||
fill_value : scalar, optional | ||
The value to assume when an index is missing from | ||
one Series or the other. The default specifies to use the | ||
appropriate NaN value for the underlying dtype of the Series. | ||
|
||
Returns | ||
------- | ||
result : Series | ||
Series | ||
The result of combining the Series with the other object. | ||
|
||
See Also | ||
-------- | ||
Series.combine_first : Combine Series values, choosing the calling | ||
Series' values first. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation is wrong, should be indented 4 spaces respect to the previous line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you fix this please? |
||
|
||
Examples | ||
-------- | ||
>>> s1 = pd.Series([1, 2]) | ||
>>> s2 = pd.Series([0, 3]) | ||
>>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2) | ||
0 0 | ||
1 2 | ||
>>> s2 = pd.Series([0, 3, 4]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep this first example as it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, @mroeschke |
||
>>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2) | ||
0 1 | ||
1 3 | ||
2 4 | ||
dtype: int64 | ||
|
||
>>> arms = pd.Series({'dog':2,'cat': 2,'mouse': 2}) | ||
>>> legs = pd.Series({'dog':2,'cat': 2}) | ||
>>> arms | ||
dog 2 | ||
cat 2 | ||
mouse 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say all those animals have 4 legs and 0 arms. Use correct data, and different values (spider, monkey...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this example look fine?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not find any alternative to defining a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides the example not following pep8 again, you may not be able to use a sum without a In the first example, remove completely the Also, add a short description before each case, explaining what is the goal of what you're showing. pandas does not contain functions or methods that are not useful for real-world examples. And in the documentation examples we should show those. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of combine() is to merge two Series into one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks much better, yes. I'd name the Series And I don't quite understand the
I would expect that in the first example Can you do a bit of research and move the examples to the PR, so I can add new comments in a review. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @datapythonista look! something funny!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @datapythonista So in the example above, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This answer on StackOverflow clears this doubt for me! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @datapythonista please read this ! |
||
dtype: int64 | ||
>>> legs | ||
dog 2 | ||
cat 2 | ||
dtype: int64 | ||
>>> limbs = arms.combine(legs, lambda x1,x2: x1+x2, fill_value=0) | ||
tm9k1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
>>> limbs | ||
cat 4 | ||
dog 4 | ||
mouse 2 | ||
dtype: int64 | ||
|
||
See Also | ||
-------- | ||
Series.combine_first : Combine Series values, choosing the calling | ||
Series's values first. | ||
""" | ||
if fill_value is None: | ||
fill_value = na_value_for_dtype(self.dtype, compat=False) | ||
|
@@ -2352,16 +2382,26 @@ def combine(self, other, func, fill_value=None): | |
|
||
def combine_first(self, other): | ||
""" | ||
Combine Series values, choosing the calling Series's values | ||
first. Result index will be the union of the two indexes | ||
Combine Series values, choosing the calling Series's values first. | ||
|
||
Parameters | ||
---------- | ||
other : Series | ||
The value(s) to be combined with the `Series`. | ||
|
||
Returns | ||
------- | ||
combined : Series | ||
Series | ||
The result of combining the Series with the other object. | ||
|
||
See Also | ||
-------- | ||
Series.combine : Perform elementwise operation on two Series | ||
using a given function | ||
tm9k1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Notes | ||
----- | ||
Result index will be the union of the two indexes. | ||
|
||
Examples | ||
-------- | ||
|
@@ -2371,11 +2411,7 @@ def combine_first(self, other): | |
0 1.0 | ||
1 4.0 | ||
dtype: float64 | ||
|
||
See Also | ||
-------- | ||
Series.combine : Perform elementwise operation on two Series | ||
using a given function. | ||
|
||
tm9k1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
new_index = self.index.union(other.index) | ||
this = self.reindex(new_index, copy=False) | ||
|
Uh oh!
There was an error while loading. Please reload this page.