-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Bug fix - rename dataframe reset index #46167
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
jreback
merged 88 commits into
pandas-dev:main
from
weikhor:bug_fix_rename_dataframe_reset_index
Mar 29, 2022
Merged
Changes from all commits
Commits
Show all changes
88 commits
Select commit
Hold shift + click to select a range
f75fd19
Update frame.py
bf9b3de
Update base.py
e4665ab
Update test_reset_index.py
bdb010f
Update v1.5.0.rst
7871c05
add
0166c9d
Update frame.py
cb460d7
Update frame.py
5fe7c1b
pre-commit
0fde54b
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
638182a
add
e19d807
reset index
bccb825
Docstring and typing validation
a328d9b
Update frame.py
4392233
Update base.py
18e36c8
Update test_reset_index.py
6229168
remove is_array_like
42bdfda
docstring
dffa501
docstring
b210e93
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
8856572
docstring
b4aa34b
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
647b526
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
6b5a76b
add none to default
c79cb09
remove return type of string
776dea8
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
1ccb5ab
Update frame.py
bdf7691
pre commit
dbe2ec3
add return type
7002639
type
aad0759
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
29fe527
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
98865a7
doc
9cbe1ed
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
4d473d8
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
fac0e7f
Merge branch 'bug_fix_rename_dataframe_reset_index' of https://github…
27cbb62
doc
5efd2eb
doc
1148e46
frame
e924d06
doc
db2626a
doc
2e136ac
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
5d2dda2
pre commit
540e4f9
doc
14564e8
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
jreback 4c00430
Update frame.py
106beb8
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
e30dd14
pre commit
8b61ced
Update frame.py
d3b2444
Update frame.py
775bfea
Update frame.py
f5a59cd
pre commit
d77868f
df doc
9e4bfd1
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
a4d5a76
df doc
89a0ad7
rst
d80107d
Update v1.5.0.rst
247d490
Update v1.5.0.rst
ad19646
Update frame.py
3efafaf
pre commit
2e16d96
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
4967381
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
d614da0
remove doc
8af651a
add
b47adb5
test remove first
ce44104
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
175ab70
remove
aa583ee
test
0111d4d
doc
bfc48f9
Merge branch 'main' of https://github.com/weikhor/pandas into bug_fix…
0c61012
Merge branch 'bug_fix_rename_dataframe_reset_index' of https://github…
11085c7
add
abfb95d
doc
0086bd5
add
7778d4b
Update base.py
1428894
doc
d1bc3eb
Merge branch 'bug_fix_rename_dataframe_reset_index' of https://github…
d2939c5
doc
ca641f6
add methods
51b0724
add
2dd795b
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
d081072
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
2de3426
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
83e81a6
doc
774a509
doc
2e99a82
doc
6e95d09
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
9b2deb5
add test
ad2d8eb
Merge branch 'main' into bug_fix_rename_dataframe_reset_index
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -754,3 +754,42 @@ def test_reset_index_interval_columns_object_cast(): | |
columns=Index(["Year", Interval(0, 1), Interval(1, 2)]), | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_reset_index_rename(float_frame): | ||
# GH 6878 | ||
result = float_frame.reset_index(names="new_name") | ||
expected = Series(float_frame.index.values, name="new_name") | ||
tm.assert_series_equal(result["new_name"], expected) | ||
|
||
result = float_frame.reset_index(names=123) | ||
expected = Series(float_frame.index.values, name=123) | ||
tm.assert_series_equal(result[123], expected) | ||
|
||
|
||
def test_reset_index_rename_multiindex(float_frame): | ||
# GH 6878 | ||
stacked_df = float_frame.stack()[::2] | ||
stacked_df = DataFrame({"foo": stacked_df, "bar": stacked_df}) | ||
|
||
names = ["first", "second"] | ||
stacked_df.index.names = names | ||
|
||
result = stacked_df.reset_index() | ||
expected = stacked_df.reset_index(names=["new_first", "new_second"]) | ||
tm.assert_series_equal(result["first"], expected["new_first"], check_names=False) | ||
tm.assert_series_equal(result["second"], expected["new_second"], check_names=False) | ||
|
||
|
||
def test_errorreset_index_rename(float_frame): | ||
# GH 6878 | ||
stacked_df = float_frame.stack()[::2] | ||
stacked_df = DataFrame({"first": stacked_df, "second": stacked_df}) | ||
|
||
with pytest.raises( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make a new test for the errors tests. add one that tests an Index with names = list-like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have add test. |
||
ValueError, match="Index names must be str or 1-dimensional list" | ||
): | ||
stacked_df.reset_index(names={"first": "new_first", "second": "new_second"}) | ||
|
||
with pytest.raises(IndexError, match="list index out of range"): | ||
stacked_df.reset_index(names=["new_first"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.