-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the Series.reset_index DocString #20107
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
Hello @ludusrusso! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on March 15, 2018 at 20:46 Hours UTC |
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.
Thanks for the PR! Added some comments
Can you add an examples with drop=True
as well?
pandas/core/series.py
Outdated
@@ -1002,24 +1002,33 @@ def _set_value(self, label, value, takeable=False): | |||
|
|||
def reset_index(self, level=None, drop=False, name=None, inplace=False): | |||
""" | |||
Analogous to the :meth:`pandas.DataFrame.reset_index` function, see | |||
docstring there. | |||
Reset the index of the Serie. |
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.
General comment: Serie -> Series (the singular of Series is still Series :))
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.
Solved tnx!
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.
Did you already push? Because this one is not yet fixed
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.
Sorry, I missed it!
pandas/core/series.py
Outdated
|
||
Parameters | ||
---------- | ||
level : int, str, tuple, or list, default None | ||
level : `int`, `str`, `tuple`, or `list`, default `None` |
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.
Those quotes in the type description is not needed
pandas/core/series.py
Outdated
docstring there. | ||
Reset the index of the Serie. | ||
|
||
For a Serie with multi-level index, return a new Serie with labeling |
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 the explanation with the standard case of normal index
pandas/core/series.py
Outdated
|
||
See Also | ||
-------- | ||
:meth:`pandas.DataFrame.reset_index`: Analogous funciton for DataFrame |
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.
funciton -> function
:meth:`pandas.DataFrame.reset_index`
-> DataFrame.reset_index (without any mark-up)
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.
DataFrame.reset_index
I've removed the mark-up, but are you sure about that? It should be nice tu have a link the the related method.
pandas/core/series.py
Outdated
docstring there. | ||
Reset the index of the Serie. | ||
|
||
For a standard index, the index name will be used (if set), |
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.
just say Index
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.
ok
pandas/core/series.py
Outdated
For a standard index, the index name will be used (if set), | ||
otherwise a default index or `level_0` (if `index` is already taken) | ||
will be used. | ||
For a Series with multi-level index, return a new Series with labeling |
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.
say MultiIndex
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.
done
pandas/core/series.py
Outdated
inplace : boolean, default False | ||
Modify the Series in place (do not create a new object) | ||
default. | ||
drop : `boolean`, default `False` |
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.
boolean -> bool
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.
tnx
pandas/core/series.py
Outdated
>>> s.reset_index(drop=True) | ||
0 1 | ||
1 2 | ||
2 3 |
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 an example with name
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.
Done, for name and for inplace
pandas/core/series.py
Outdated
|
||
Returns | ||
---------- | ||
resetted : DataFrame, or Series if drop == True | ||
resetted : `DataFrame`, or Series if `drop == True` |
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.
Resetted should probably just "reset"
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.
ok!
Update pull request after review! Tnx! |
pandas/core/series.py
Outdated
Reset the index of the Serie. | ||
|
||
For an Index, the index name will be used (if set), | ||
otherwise a default index or `level_0` (if `index` is already taken) |
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.
the default IS 'index', can you make this a bit more clear
pandas/core/series.py
Outdated
|
||
Returns | ||
---------- | ||
resetted : DataFrame, or Series if drop == True | ||
reset : `DataFrame`, or Series if `drop == True` |
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 don't recall whether we are single ticking Series, DataFrame in doc-strings. @datapythonista @jorisvandenbossche
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.
decision was to not use ticks in this case
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.
ok @ludusrusso can you update
pandas/core/series.py
Outdated
|
||
>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'], | ||
... name = 'idx')) | ||
>>> s.reset_index(name = 'new_idx') |
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.
no spaces around the equals
pandas/core/series.py
Outdated
Do not try to insert index into dataframe columns. | ||
name : `object`, default `None` | ||
The name of the column corresponding to the Series values. | ||
inplace : `bool`, default `False` |
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 also remove the backticks here? In general: no backticks in the type descriptions
pandas/core/series.py
Outdated
2 c 3 | ||
3 d 4 | ||
|
||
>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'], |
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.
you don't need to re-define the series, you can reuse from the previous code block
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 also put some explanation sentence between the examples?
Thanks you all! I've updated the examples with comments! |
pandas/core/series.py
Outdated
@@ -1002,36 +1002,86 @@ def _set_value(self, label, value, takeable=False): | |||
|
|||
def reset_index(self, level=None, drop=False, name=None, inplace=False): | |||
""" | |||
Analogous to the :meth:`pandas.DataFrame.reset_index` function, see | |||
docstring there. | |||
Reset the index of the Series. |
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.
so this is not correct, .reset_index(drop=False)
(the default) on a Series will return a DataFrame. The columns will be the name of the Series and a new column of the index, with its name being the name of the column or 'index' if its not named.
pandas/core/series.py
Outdated
For an Index, the index name will be used (if set), | ||
otherwise a default index or level_0 (if index is already taken) | ||
will be used. | ||
For a MultiIndex, return a new Series with labeling |
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.
you will get a multi-column DataFrame, with each level being turned into a column, here the levels will be named level_n if the name is None.
pandas/core/series.py
Outdated
|
||
Returns | ||
---------- | ||
resetted : DataFrame, or Series if drop == True | ||
reset : DataFrame, or Series if `drop == True` |
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.
no back ticks
pandas/core/series.py
Outdated
|
||
Examples | ||
-------- | ||
|
||
Generate a pandas.Series with a given Index. |
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.
this comment is a bit odd here
pandas/core/series.py
Outdated
>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'], | ||
... name = 'idx')) | ||
|
||
To generate a pandas.DataFrame with resetted index, |
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.
resetted -> default index
pandas/core/series.py
Outdated
2 c 3 | ||
3 d 4 | ||
|
||
To generate a new pandas.Series with the resetted |
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.
resetted -> default index
@ludusrusso did you run the validation script again after updating? |
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.
Looks good in general, but still needs some work.
pandas/core/series.py
Outdated
docstring there. | ||
Generate a new DataFrame with columns containing the data and | ||
the index of the original Series, or, if drop is True, | ||
a Series with numeric index. |
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.
Short summary must fit in one line.
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.
It's hard to summarize it! I'll try!
pandas/core/series.py
Outdated
|
||
Returns | ||
---------- | ||
resetted : DataFrame, or Series if drop == True | ||
reset : DataFrame, or Series if drop == True |
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.
Check the first example here to see how the output of Returns is: https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-4-returns-or-yields
Also, not your change, but the hyphens under return are too long.
pandas/core/series.py
Outdated
>>> s.reset_index() | ||
idx 0 | ||
0 a 1 | ||
1 b 2 | ||
2 c 3 | ||
3 d 4 | ||
|
||
To specify the name of the column corrisponding |
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.
corrIsponding.
pandas/core/series.py
Outdated
|
||
Examples | ||
-------- | ||
|
||
Generate a pandas.Series. | ||
|
||
>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'], | ||
... name = 'idx')) |
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.
spaces around =
don't follow PEP-8.
pandas/core/series.py
Outdated
dtype: int64 | ||
|
||
Generate a MultiIndex Series. | ||
|
||
>>> arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', | ||
... 'foo', 'qux', 'qux']), | ||
... np.array(['one', 'two', 'one', 'two', 'one', 'two', |
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.
If I'm not wrong, just 4 rows should be enough to illustrate the example. That would make it more compact, and easier to understand for the user.
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.
You're right, that was an existing example!
pandas/core/series.py
Outdated
@@ -1002,36 +1002,88 @@ def _set_value(self, label, value, takeable=False): | |||
|
|||
def reset_index(self, level=None, drop=False, name=None, inplace=False): | |||
""" | |||
Analogous to the :meth:`pandas.DataFrame.reset_index` function, see | |||
docstring there. | |||
Generate a new DataFrame with columns containing the data and |
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.
this needs to be a single line.
pandas/core/series.py
Outdated
the index of the original Series, or, if drop is True, | ||
a Series with numeric index. | ||
|
||
For an Index Series, the results is a two-column DataFrame with |
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.
Index Series doesn't make sense, more like: For a Series with a single level index (Index)
pandas/core/series.py
Outdated
|
||
For an Index Series, the results is a two-column DataFrame with | ||
index tourned in column. | ||
For a MultiIndex Series, the results is a multi-column |
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.
for a Series with a multi-level index (MultiIndex)
pandas/core/series.py
Outdated
|
||
See Also | ||
-------- | ||
pandas.DataFrame.reset_index: Analogous function for DataFrame |
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.
link to pandas.Series.set_index as well
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.
Series does not have a method set_index(), did you mean DataFrame.set_index()?
s.set_index()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ludus/develop/pandas-meetup/pandas/pandas/core/generic.py", line 4046, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'set_index'
pandas/core/series.py
Outdated
>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'], | ||
... name = 'idx')) | ||
|
||
To generate a pandas.DataFrame with default index, | ||
call the reset_index() method. |
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.
you don't need to say 'call the reset_index() method'
pandas/core/series.py
Outdated
>>> s.reset_index() | ||
idx 0 | ||
0 a 1 | ||
1 b 2 | ||
2 c 3 | ||
3 d 4 | ||
|
||
To specify the name of the column corrisponding |
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.
sp
pandas/core/series.py
Outdated
2 c 3 | ||
3 d 4 | ||
|
||
To generate a new pandas.Series with the default |
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 just say Series
Codecov Report
@@ Coverage Diff @@
## master #20107 +/- ##
==========================================
+ Coverage 91.72% 91.72% +<.01%
==========================================
Files 150 150
Lines 49149 49159 +10
==========================================
+ Hits 45083 45093 +10
Misses 4066 4066
Continue to review full report at Codecov.
|
@jorisvandenbossche you're right.. I've checked it this time! |
[ci skip]
[ci skip]
Very nice docstring, thanks @ludusrusso ! |
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: