-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Bug in loc raised Error when non-integer slice was given for MultiIndex #37707
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 2 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c8df1c8
Bug in loc raised Error when non integer interval was given for Multi…
phofl 9e62c50
Adjust tests
phofl 8377a79
Comment it back in
phofl e6acaac
Run black
phofl 37fe677
Rename test
phofl 550ac88
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl d38c9e7
Change new implementation
phofl 72345a4
Do slicing outside
phofl 04056ae
Add test
phofl 41dbbcc
Change issue number
phofl 07f13f3
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl adaa27b
Delete None
phofl 061468c
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl d59e7f7
Change whatsnew
phofl d9562c4
Add comment
phofl c382af0
Improve test
phofl 694e469
Change test description
phofl d78d8ce
Change issue number in test
phofl d9a4054
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl c13da44
Fix comments
phofl 0a6cab7
Add testcases
phofl 4ffe46e
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl 3e9baa6
Fix bugs
phofl c579c88
Adress review comments
phofl 0be97cd
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl 923610e
Fix whatsnew
phofl fdd170e
Fix blank line and if else
phofl 3f3c133
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl 4c17aeb
Parametrize test
phofl a766f98
Run black
phofl 48424fb
Merge branch 'master' of https://github.com/pandas-dev/pandas into 25165
phofl 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -598,3 +598,28 @@ def test_getitem_loc_commutability(multiindex_year_month_day_dataframe_random_da | |
result = ser[2000, 5] | ||
expected = df.loc[2000, 5]["A"] | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
def test_getitem_loc_datetime(): | ||
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. put partial in the name of the test, move to pandas/tests/indexing/test_partial.py 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. Done |
||
# GH: 25165 | ||
date_idx = pd.date_range("2019", periods=2, freq="MS") | ||
df = DataFrame( | ||
list(range(4)), | ||
index=MultiIndex.from_product([date_idx, [0, 1]], names=["x", "y"]), | ||
) | ||
expected = DataFrame( | ||
[2, 3], | ||
index=MultiIndex.from_product( | ||
[[pd.to_datetime("2019-02-01")], [0, 1]], names=["x", "y"] | ||
), | ||
) | ||
result = df["2019-2":] | ||
tm.assert_frame_equal(result, expected) | ||
result = df.loc["2019-2":] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.loc(axis=0)["2019-2":] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.loc["2019-2":, :] | ||
tm.assert_frame_equal(result, 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.
this is commented?
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.
Shit, no I tried something out. This has to get back in. Will add it back momentarily
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.
Commented it back in. At least my test failed previously :)