Skip to content

TST: add test cases for reset_index method #23116

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

Merged
merged 4 commits into from
Oct 24, 2018

Conversation

minggli
Copy link
Contributor

@minggli minggli commented Oct 12, 2018

the fix appears to work but it breaks previous assert_frame_equal that assumes index.name == None after reset_index() call.

The question remains that is the issue #17067 actually a bug and does it require a fix at all? user can pretty much do series.index.name = 'new name' to handle this problem.

@pep8speaks
Copy link

Hello @minggli! Thanks for submitting the PR.

@jreback
Copy link
Contributor

jreback commented Oct 14, 2018

there are 2 issues pointed out in the OP

the first should already be fixed (and was a bug)

to answer your question, yes we want to be consistent in this

@minggli
Copy link
Contributor Author

minggli commented Oct 14, 2018

@jreback thanks for commenting! it seems it has indeed been fixed already. closing this PR.

@minggli minggli closed this Oct 14, 2018
@jreback
Copy link
Contributor

jreback commented Oct 14, 2018

would take tests for this though!

@minggli minggli changed the title BUG: reset index does not inherit index.name TST: add test cases that reset_index method inherits index.name Oct 14, 2018
@minggli minggli reopened this Oct 14, 2018
@minggli minggli force-pushed the bugfix/reset_index branch from 81f64df to ddd4b6a Compare October 15, 2018 21:39
@minggli
Copy link
Contributor Author

minggli commented Oct 15, 2018

strangely, it appears that below would fail on master:

s = pd.Series([1, 2, 3], index=pd.Index(range(3), name='x'))
assert s.reset_index().index.name == 'x'
assert s.reset_index(drop=True).index.name == 'x'

i hope I understood the issue correctly, is it expected for the reset index to carry over the index name?

@jreback
Copy link
Contributor

jreback commented Oct 17, 2018

In [11]: s.reset_index(drop=True).index.name == 'x'
Out[11]: False

In [12]: s.reset_index().index.name == 'x'
Out[12]: False

these both look correct to me, the index name should not be carried over.

@codecov
Copy link

codecov bot commented Oct 18, 2018

Codecov Report

Merging #23116 into master will increase coverage by 0.62%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23116      +/-   ##
==========================================
+ Coverage   92.19%   92.82%   +0.62%     
==========================================
  Files         169      169              
  Lines       50950    55686    +4736     
==========================================
+ Hits        46975    51689    +4714     
- Misses       3975     3997      +22
Flag Coverage Δ
#multiple 91.37% <ø> (+0.75%) ⬆️
#single 43.7% <ø> (+1.43%) ⬆️
Impacted Files Coverage Δ
pandas/io/common.py 68.62% <0%> (-2.42%) ⬇️
pandas/core/arrays/period.py 95.47% <0%> (-0.1%) ⬇️
pandas/util/testing.py 86.5% <0%> (+0.05%) ⬆️
pandas/core/indexes/datetimelike.py 98.37% <0%> (+0.12%) ⬆️
pandas/io/formats/csvs.py 98.39% <0%> (+0.17%) ⬆️
pandas/core/arrays/categorical.py 95.74% <0%> (+0.2%) ⬆️
pandas/core/arrays/sparse.py 92.76% <0%> (+0.24%) ⬆️
pandas/core/arrays/datetimelike.py 95.57% <0%> (+0.67%) ⬆️
pandas/core/arrays/datetimes.py 98.05% <0%> (+0.67%) ⬆️
pandas/core/frame.py 97.84% <0%> (+0.72%) ⬆️
... and 12 more

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 ecc5cbc...2cfd37f. Read the comment docs.

@minggli
Copy link
Contributor Author

minggli commented Oct 18, 2018

@jreback reflected your comment in added tests.

@minggli minggli changed the title TST: add test cases that reset_index method inherits index.name TST: add test cases for reset_index method Oct 18, 2018
@minggli minggli force-pushed the bugfix/reset_index branch from 9ce663b to 2cfd37f Compare October 19, 2018 10:46
@minggli minggli closed this Oct 21, 2018
@minggli minggli reopened this Oct 21, 2018
@minggli minggli closed this Oct 24, 2018
@minggli minggli reopened this Oct 24, 2018
@jreback jreback added the Testing pandas testing functions or related to the test suite label Oct 24, 2018
@jreback jreback added this to the 0.24.0 milestone Oct 24, 2018
@jreback jreback merged commit 2b9dfe6 into pandas-dev:master Oct 24, 2018
@jreback
Copy link
Contributor

jreback commented Oct 24, 2018

thanks @minggli

@minggli minggli deleted the bugfix/reset_index branch October 24, 2018 12:30
@minggli
Copy link
Contributor Author

minggli commented Oct 24, 2018

welcome! @jreback @gfyoung 😃

tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: reset_index can reset index name
3 participants