-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: Annotated pandas/core/indexing.py #29908
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 all commits
Commits
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 |
---|---|---|
|
@@ -240,7 +240,7 @@ def _has_valid_tuple(self, key: Tuple): | |
"[{types}] types".format(types=self._valid_types) | ||
) | ||
|
||
def _is_nested_tuple_indexer(self, tup: Tuple): | ||
def _is_nested_tuple_indexer(self, tup: Tuple) -> bool: | ||
if any(isinstance(ax, ABCMultiIndex) for ax in self.obj.axes): | ||
return any(is_nested_tuple(tup, ax) for ax in self.obj.axes) | ||
return False | ||
|
@@ -273,10 +273,10 @@ def _convert_slice_indexer(self, key: slice, axis: int): | |
ax = self.obj._get_axis(min(axis, self.ndim - 1)) | ||
return ax._convert_slice_indexer(key, kind=self.name) | ||
|
||
def _has_valid_setitem_indexer(self, indexer): | ||
def _has_valid_setitem_indexer(self, indexer) -> bool: | ||
return True | ||
|
||
def _has_valid_positional_setitem_indexer(self, indexer): | ||
def _has_valid_positional_setitem_indexer(self, indexer) -> bool: | ||
""" validate that an positional indexer cannot enlarge its target | ||
will raise if needed, does not modify the indexer externally | ||
""" | ||
|
@@ -1318,7 +1318,7 @@ def __init__(self, name, obj): | |
super().__init__(name, obj) | ||
|
||
@Appender(_NDFrameIndexer._validate_key.__doc__) | ||
def _validate_key(self, key, axis: int): | ||
def _validate_key(self, key, axis: int) -> bool: | ||
if isinstance(key, slice): | ||
return True | ||
|
||
|
@@ -1689,7 +1689,7 @@ def _validate_key(self, key, axis: int): | |
if not is_list_like_indexer(key): | ||
self._convert_scalar_indexer(key, axis) | ||
|
||
def _is_scalar_access(self, key: Tuple): | ||
def _is_scalar_access(self, key: Tuple) -> bool: | ||
# this is a shortcut accessor to both .loc and .iloc | ||
# that provide the equivalent access of .at and .iat | ||
# a) avoid getting things via sections and (to minimize dtype changes) | ||
|
@@ -2002,7 +2002,7 @@ def _validate_key(self, key, axis: int): | |
def _has_valid_setitem_indexer(self, indexer): | ||
self._has_valid_positional_setitem_indexer(indexer) | ||
|
||
def _is_scalar_access(self, key: Tuple): | ||
def _is_scalar_access(self, key: Tuple) -> bool: | ||
# this is a shortcut accessor to both .loc and .iloc | ||
# that provide the equivalent access of .at and .iat | ||
# a) avoid getting things via sections and (to minimize dtype changes) | ||
|
@@ -2026,7 +2026,7 @@ def _getitem_scalar(self, key): | |
values = self.obj._get_value(*key, takeable=True) | ||
return values | ||
|
||
def _validate_integer(self, key: int, axis: int): | ||
def _validate_integer(self, key: int, axis: int) -> None: | ||
""" | ||
Check that 'key' is a valid position in the desired axis. | ||
|
||
|
@@ -2452,7 +2452,7 @@ def maybe_convert_ix(*args): | |
return args | ||
|
||
|
||
def is_nested_tuple(tup, labels): | ||
def is_nested_tuple(tup, labels) -> bool: | ||
# check for a compatible nested tuple and multiindexes among the axes | ||
if not isinstance(tup, tuple): | ||
return False | ||
|
@@ -2465,12 +2465,12 @@ def is_nested_tuple(tup, labels): | |
return False | ||
|
||
|
||
def is_label_like(key): | ||
def is_label_like(key) -> bool: | ||
# select a label or row | ||
return not isinstance(key, slice) and not is_list_like_indexer(key) | ||
|
||
|
||
def need_slice(obj): | ||
def need_slice(obj) -> bool: | ||
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. seems like obj will be a slice? |
||
return ( | ||
obj.start is not None | ||
or obj.stop is not None | ||
|
@@ -2491,7 +2491,7 @@ def _non_reducing_slice(slice_): | |
if isinstance(slice_, kinds): | ||
slice_ = IndexSlice[:, slice_] | ||
|
||
def pred(part): | ||
def pred(part) -> bool: | ||
# true when slice does *not* reduce, False when part is a tuple, | ||
# i.e. MultiIndex slice | ||
return (isinstance(part, slice) or is_list_like(part)) and not isinstance( | ||
|
@@ -2523,7 +2523,7 @@ def _maybe_numeric_slice(df, slice_, include_bool=False): | |
return slice_ | ||
|
||
|
||
def _can_do_equal_len(labels, value, plane_indexer, lplane_indexer, obj): | ||
def _can_do_equal_len(labels, value, plane_indexer, lplane_indexer, obj) -> bool: | ||
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 any of the args here be typed? |
||
""" return True if we have an equal len settable """ | ||
if not len(labels) == 1 or not np.iterable(value) or is_scalar(plane_indexer[0]): | ||
return False | ||
|
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.
it looks like this always either raises or returns True; is that accurate? if so, maybe get rid of the return value altogether (might need to update usages)
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.
I don't feel confident enough in reformatting this function, I'll leave it for someone else who will probably won't break the package.