Skip to content

BUG: GH12071 .reset_index() should create a RangeIndex #12080

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

boombard
Copy link
Contributor

closes #12071

@boombard
Copy link
Contributor Author

Fixes #12071

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Jan 19, 2016
@@ -2891,7 +2891,10 @@ def _maybe_casted_values(index, labels=None):
np.nan)
return values

new_index = np.arange(len(new_obj), dtype='int64')
Copy link
Contributor

Choose a reason for hiding this comment

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

just use core.common._default_index instead here

Copy link
Contributor

Choose a reason for hiding this comment

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

this can always be _default_index

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it and squashed it into the same commit

Copy link
Contributor

Choose a reason for hiding this comment

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

new_index = _default_index(len(new_obj))
is the entire answer here, you don't need a separate check whether its a RangeIndex or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@jreback
Copy link
Contributor

jreback commented Jan 19, 2016

add this issue number to right after #939 in whatsnew/v0.18.0

@jreback jreback added the Bug label Jan 19, 2016
@jreback jreback added this to the 0.18.0 milestone Jan 19, 2016
@boombard
Copy link
Contributor Author

Thanks. Updated the pull request. Not sure if I put the reference to the issue in the right place in "whatsnew" (this is my first PR to pandas).

@jreback
Copy link
Contributor

jreback commented Jan 19, 2016

add a test for Series as well

index=RangeIndex(stop=2))
assert_frame_equal(result, expected)

s = pd.Series(range(2), name='A', index=RangeIndex(stop=2))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test for Series Added

@jreback
Copy link
Contributor

jreback commented Jan 20, 2016

merged via 16a7799

thanks!

@jreback jreback closed this Jan 20, 2016
@boombard
Copy link
Contributor Author

Thanks for the help @jreback

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

Successfully merging this pull request may close these issues.

BUG: .reset_index() should create a RangeIndex
2 participants