-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the pandas.Series.map docstring #20450
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20450 +/- ##
==========================================
- Coverage 92.05% 91.77% -0.28%
==========================================
Files 169 152 -17
Lines 50713 49216 -1497
==========================================
- Hits 46683 45170 -1513
- Misses 4030 4046 +16
Continue to review full report at Codecov.
|
pandas/core/series.py
Outdated
@@ -2850,7 +2853,7 @@ def map(self, arg, na_action=None): | |||
Examples | |||
-------- | |||
|
|||
Map inputs to outputs (both of type `Series`): | |||
Map inputs to outputs (both of type :class:`pandas.Series`): | |||
|
|||
>>> x = pd.Series([1,2,3], index=['one', 'two', 'three']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces after comma for PEP-8.
pandas/core/series.py
Outdated
one 1 | ||
two 4 | ||
three 9 | ||
dtype: int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would start by the example using a function as a parameter, which I think it's a more common use than with a series.
pandas/core/series.py
Outdated
dtype: int64 | ||
|
||
If ``arg`` is a dictionary, return a new :class:`pandas.Series` with | ||
values converted according to the dictionary's mapping: | ||
|
||
>>> z = {1: 'A', 2: 'B', 3: 'C'} | ||
|
||
>>> x.map(z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As z
is not very descriptive, I'd use the dictionary directly as a parameter, and avoid saving it to a variable.
pandas/core/series.py
Outdated
@@ -2850,7 +2853,7 @@ def map(self, arg, na_action=None): | |||
Examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a See Also
section? I think at least apply
and applymap
are related. May be the Python map
built-in could be linked too?
pandas/core/series.py
Outdated
@@ -2864,35 +2867,46 @@ def map(self, arg, na_action=None): | |||
1 foo | |||
2 bar | |||
3 baz | |||
dtype: object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these examples would be clearer if instead of foo
, bar
, one
, two
... we could find a more real-world example.
Also, I think it should be useful to show the behaviour of map
with a dict
or Series
that doesn't have all the values in the Series
.
@kaoboyandy will you have time to update based on @datapythonista's comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WillAyd do you mind taking a quick look (I made some last changes), and if you're happy merge it?
Thanks @kaoboyandy and @datapythonista ! |
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.
Checklist for other PRs (remove this part if you are doing a PR for the pandas documentation sprint):
git diff upstream/master -u -- "*.py" | flake8 --diff