-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: rename fails when using level #43667
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
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7db707a
bug: reproduce #43659 in test_rename_with_multiindex at Series test.
wojtek2kdev 712c7aa
test: correct series equality for assertion.
wojtek2kdev 5534697
bug: Add get_indexer_for on MultiIndex on given level.
wojtek2kdev 3aa23ed
lint: correction lint errors.
wojtek2kdev cdf3013
bug(NDFrame): indexer for MultiIndex only if level is provided.
wojtek2kdev 0c74b1f
test(test_series): Simplify test_rename_with_multiindex.
wojtek2kdev 2c9f511
test(test_series): Move reference to issue into test.
wojtek2kdev 288344c
doc: Resolve bug #43659
wojtek2kdev 80a556d
lint: Add newline in test file.
wojtek2kdev 191f646
test(rename): Move test related to #43659 into proper file.
wojtek2kdev eeb2c86
Mistake: test moved to frame instead of series. Now its correct.
wojtek2kdev aa1fc34
test(series/rename): Change assertion method.
wojtek2kdev 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,3 +151,28 @@ def finalize(self, other, method=None, **kwargs): | |
# reset | ||
Series._metadata = _metadata | ||
Series.__finalize__ = _finalize # FIXME: use monkeypatch | ||
|
||
# issue #43659 | ||
def test_rename_with_multiindex(self): | ||
arrays = [ | ||
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. Please add reference in test not above The test is to complicated. Please reduce number of rows and don't use something like list(zip(*arrays)). You can use MultiIndex.from_arrays |
||
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"], | ||
["one", "two", "one", "two", "one", "two", "one", "two"], | ||
] | ||
|
||
tuples = list(zip(*arrays)) | ||
index = MultiIndex.from_tuples(tuples, names=["first", "second"]) | ||
s = Series(np.ones(8), index=index) | ||
result = s.rename(index={"one": "yes"}, level="second", errors="raise") | ||
|
||
arrays_expected = [ | ||
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"], | ||
["yes", "two", "yes", "two", "yes", "two", "yes", "two"], | ||
] | ||
|
||
tuples_expected = list(zip(*arrays_expected)) | ||
index_expected = MultiIndex.from_tuples( | ||
tuples_expected, names=["first", "second"] | ||
) | ||
series_expected = Series(np.ones(8), index=index_expected) | ||
|
||
assert result.equals(series_expected) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move here: pandas/tests/series/methods/test_rename.py