-
-
Notifications
You must be signed in to change notification settings - Fork 141
Dataframe loc #575
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
Closed
Dataframe loc #575
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,8 +160,8 @@ class _LocIndexerFrame(_LocIndexer): | |
| Callable[[DataFrame], IndexType | MaskType | list[HashableT]] | ||
| list[HashableT] | ||
| tuple[ | ||
IndexType | MaskType | list[HashableT] | Hashable, | ||
list[HashableT] | slice | Series[bool] | Callable, | ||
Iterable[HashableT] | slice | Hashable, | ||
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. I don't think you need |
||
list[HashableT] | Series[bool] | slice | Callable, | ||
], | ||
) -> DataFrame: ... | ||
@overload | ||
|
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
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.
Iterable[HashableT]
is too wide, as it will match a plain string, which, if supplied, would return aSeries
.So please put back
IndexType | MaskType | list[HashableT]
and replaceHashable
with_IndexSliceTuple | Callable
Including
slice
is fine.If you make the suggested change, that will cause the test
test_frame.py:test_loc_slice()
to fail, but I now realize that the expression used there is ambiguous:So the first argument as an integer could return a
DataFrame
orSeries
, dependent on whether the underlying index is a regularIndex
orMultiIndex
The solution is then to add another overload in
_LocIndexerFrame.__getitem__()
:Then modify the test in
test_index_slice()
to check that the type isUnion[pd.Series, pd.DataFrame]
, and add another test corresponding todf2
above.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.
Matching
str
is fine here, because the second component of the tuple ensures multiple columns are selected.Both
df.loc["row", ["col1", "col2", "col3"]]
anddf.loc[["r", "o", "w"], ["col1", "col2", "col3"]]
return DataFrame which is the only thing this overload ensures.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.
No, you are incorrect. The first example could create a
Series
: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.
Oh, right.