Skip to content

Bug22373: Enhance documentation for RangeIndex #22421

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

Closed
wants to merge 8 commits into from
Closed

Bug22373: Enhance documentation for RangeIndex #22421

wants to merge 8 commits into from

Conversation

mikapfl
Copy link

@mikapfl mikapfl commented Aug 19, 2018

Corrects documentation for RangeIndex and enhances documentation for RangeIndex and RangeIndex.from_range
closes #22373
passes git diff upstream/master -u -- "*.py" | flake8 --diff

@pep8speaks
Copy link

pep8speaks commented Aug 19, 2018

Hello @mikapfl! Thanks for updating the PR.

Line 42:80: E501 line too long (82 > 79 characters)

Comment last updated on September 06, 2018 at 21:17 Hours UTC

@gfyoung gfyoung added the Docs label Aug 19, 2018
@gfyoung gfyoung added this to the 0.23.5 milestone Aug 19, 2018
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, looking good. If you want to add examples as part of this PR, that would be great (we can do it in a separate PR too).

Also, if you can add periods at the end of the See Also items description, that would be great.

If of type `int` and `stop` is not given, interpreted as `stop`
instead.
stop : int, default 0
step : int, default 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'f be good to have these documented. Also, start, which would be good to have a description, besides the behavior described.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re documenting start, stop and step: I also thought that it would be nice to document them, and figured we could just recycle the python documentation for range. However, the documentation for the arguments is very basic in python as well: "stop: The value of the stop parameter". Maybe there is not much else to say?

But I'll try to adapt the rest of the python range docs (i.e. the long description) and try to come up with some useful examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be useful to say whether the stop value is included or not. It's not obvious to me that range(0, 10) doesn't include the 10.

Also, for beginner users, something as simple as start : The first value of the generated range. can be useful. step can be tricky, do we support negative values, as range?

I do think there is a lot to say. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think it can be useful to say whether the stop value is included or not. It's not obvious to me that range(0, 10) doesn't include the 10.

this is standard python behavior to NOT include the rhs on ranges.

If of type `int` and `stop` is not given, interpreted as `stop`
instead.
stop : int, default 0
step : int, default 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think it can be useful to say whether the stop value is included or not. It's not obvious to me that range(0, 10) doesn't include the 10.

this is standard python behavior to NOT include the rhs on ranges.

copy : bool, default False
Unused, accepted for homogeneity with other index types.
name : object, optional
Name to be stored in the index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this constructor should be discouraged for using integers on ranges, this is the reason we have .from_range. Actually folks should generally NOT use specific constructors anyhow. pd.Index dispatches in most cases. Only if you have very very specific requreiments do you need to use this constructor.

@datapythonista
Copy link
Member

Agree that not including the stop of the range is standard, my point is that it's not obvious unless you know about this standard. So, I think it's worth mentioning it in the documentation.

If using the constructor is discouraged, we should also say it in the description I guess.

…ges.

Explanation is based on the python documentation for ranges.
…ge to Index.

Index docstring: add example of passing a range to construct a RangeIndex.
@codecov
Copy link

codecov bot commented Sep 6, 2018

Codecov Report

Merging #22421 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22421   +/-   ##
=======================================
  Coverage   92.05%   92.05%           
=======================================
  Files         169      169           
  Lines       50714    50714           
=======================================
  Hits        46684    46684           
  Misses       4030     4030
Flag Coverage Δ
#multiple 90.46% <ø> (ø) ⬆️
#single 42.25% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/range.py 95.7% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 140c7bb...219f5ee. Read the comment docs.

@mikapfl
Copy link
Author

mikapfl commented Sep 6, 2018

@datapythonista I have added documentation and examples showing the half-inclusive behaviour of RangeIndex. The documentation is based on the python range documentation.

@jreback I have added langeuage and examples to Index and RangeIndex to guide users towards using Index(range(…)) instead of RangeIndex(…).

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the default of tupleize_cols from (default: True) to `default True

And finish the comment in Notes with a period.

@@ -177,7 +177,7 @@ class Index(IndexOpsMixin, PandasObject):

Parameters
----------
data : array-like (1-dimensional)
data : array-like (1-dimensional) or python `range`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think iterable would be the best in this case. If you can add a description, and also comment there about range.

@@ -177,7 +177,7 @@ class Index(IndexOpsMixin, PandasObject):

Parameters
----------
data : array-like (1-dimensional)
data : array-like (1-dimensional) or python `range`
dtype : NumPy dtype (default: object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change it to `dtype : dtype, default None

@@ -201,6 +201,9 @@ class Index(IndexOpsMixin, PandasObject):
>>> pd.Index(list('abc'))
Index(['a', 'b', 'c'], dtype='object')

>>> pd.Index(range(4))
RangeIndex(start=0, stop=4, step=1)

See Also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the See Also section before Notes. Also, if you can end all the description with period.

@jreback jreback modified the milestones: 0.23.5, 0.24.0 Oct 23, 2018
@jreback jreback removed this from the 0.24.0 milestone Nov 6, 2018
@alimcmaster1
Copy link
Member

@mikapfl could you rebase and merge master if you are still looking to take this on? If not I can potentially take a look

@datapythonista
Copy link
Member

@alimcmaster1, if you want to open a new PR with this. Closing as this seems abandoned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

version 0.23: RangeIndex argument order changed, docs stale
6 participants