Skip to content
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

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

Closed
wants to merge 1 commit into from

Conversation

@kawochen
Copy link
Contributor

kawochen commented Jan 17, 2016

xref #12034

@kawochen

This comment has been minimized.

Copy link
Contributor Author

kawochen commented Jan 17, 2016

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

@jreback

This comment has been minimized.

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 this to the 0.18.0 milestone Jan 17, 2016
@jreback

This comment has been minimized.

Copy link
Contributor

jreback commented Jan 17, 2016

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

@kawochen kawochen force-pushed the kawochen:ENH-12034-floordiv branch 2 times, most recently Jan 19, 2016
@jreback
jreback reviewed Jan 19, 2016
View changes
pandas/tests/test_index.py Outdated
(RangeIndex(-100, -200, 3), 2, RangeIndex())]
for idx, div, expected in cases_equiv:
result = idx // div
tm.assert_index_equal(result, expected, exact=False)

This comment has been minimized.

Copy link
@jreback

jreback Jan 19, 2016

Contributor

shouldn't you just have exact=True here?

This comment has been minimized.

Copy link
@kawochen

kawochen Jan 19, 2016

Author Contributor

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.

This comment has been minimized.

Copy link
@kawochen

kawochen Jan 19, 2016

Author Contributor

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

This comment has been minimized.

Copy link
@jreback

jreback Jan 19, 2016

Contributor

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

@jreback
jreback reviewed Jan 19, 2016
View changes
pandas/core/index.py Outdated
if len(self) == 1:
start = self._start // other
return RangeIndex(start, start + 1, 1, name = self.name,
faspath=True)

This comment has been minimized.

Copy link
@jreback

jreback Jan 19, 2016

Contributor

type here fastpath

and pep name=self.name

@jreback

This comment has been minimized.

Copy link
Contributor

jreback commented Jan 19, 2016

ping when green

@kawochen kawochen force-pushed the kawochen:ENH-12034-floordiv branch Jan 19, 2016
@kawochen kawochen force-pushed the kawochen:ENH-12034-floordiv branch to 7106263 Jan 19, 2016
@kawochen

This comment has been minimized.

Copy link
Contributor Author

kawochen commented Jan 20, 2016

updated

@jreback

This comment has been minimized.

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
Projects
None yet
2 participants
You can’t perform that action at this time.