Skip to content

ENH: GH12034 RangeIndex.__floordiv__ returns RangeIndex if possible #12070

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 1 commit into from

Conversation

kawochen
Copy link
Contributor

xref #12034

@kawochen
Copy link
Contributor Author

Not sure if I should always return RangeIndex when length < 2.

@jreback
Copy link
Contributor

jreback commented Jan 17, 2016

@kawochen I had the same thoughts for n=0/1 for the default constructor for a NDFrame, but thought its more consistent to always get a RangeIndex. Ideally would do the same if at all possible.

@jreback jreback added Enhancement Indexing Related to indexing on series/frames, not to indexes themselves labels Jan 17, 2016
@jreback jreback added this to the 0.18.0 milestone Jan 17, 2016
@jreback
Copy link
Contributor

jreback commented Jan 17, 2016

pls add this issue number to the whatsnew note as well.

@kawochen kawochen force-pushed the ENH-12034-floordiv branch 2 times, most recently from 0224746 to 3e0f331 Compare January 19, 2016 05:21
(RangeIndex(-100, -200, 3), 2, RangeIndex())]
for idx, div, expected in cases_equiv:
result = idx // div
tm.assert_index_equal(result, expected, exact=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't you just have exact=True here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For len(self) == 1 and len(self) == 0 the equivalent classes are particularly large, and it doesn't matter which representatives to return. e.g. you could always return RangeIndex() for len(self) == 0 or leave _start unchanged. And since when len(self) == 1, step // div could be 0, I couldn't treat all cases the same. The choice of step and stop is arbitrary so I had exact=False.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh I just looked at assert_index_equal, so it defers to Index.equals -- I will change it to exact=True

Copy link
Contributor

Choose a reason for hiding this comment

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

the exact defaults to equiv which means Int64Index/RangeIndex can be equivalent. exact=True mean they must be exactly the same

@jreback
Copy link
Contributor

jreback commented Jan 19, 2016

ping when green

@kawochen
Copy link
Contributor Author

updated

@jreback
Copy link
Contributor

jreback commented Jan 20, 2016

merged via 8e29361

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants