-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Avoid accessing private loc methods #27383
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 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9ddb071
Avoid using private loc methods
jbrockmendel ba70015
avoid private usage
jbrockmendel 21fb397
abstractmethod
jbrockmendel f6cfe85
Merge branch 'master' of https://github.com/pandas-dev/pandas into loc_
jbrockmendel 0de71aa
add types in indexing; make internal calls with less overhead
jbrockmendel aa3b6c3
blackify
jbrockmendel deb6193
remove unnecessary
jbrockmendel 944fb36
silence mypy complaint
jbrockmendel 0f44a3c
blackify
jbrockmendel 525a02d
lint/mypy
jbrockmendel 99ca950
Merge branch 'master' of https://github.com/pandas-dev/pandas into loc_
jbrockmendel f9c7fc9
tuple->Tuple
jbrockmendel dbbae14
Merge branch 'master' of https://github.com/pandas-dev/pandas into loc_
jbrockmendel 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 |
---|---|---|
|
@@ -222,7 +222,7 @@ def _validate_key(self, key, axis: int): | |
""" | ||
raise AbstractMethodError(self) | ||
|
||
def _has_valid_tuple(self, key): | ||
def _has_valid_tuple(self, key: tuple): | ||
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 use the generic |
||
""" check the key for valid keys across my indexer """ | ||
for i, k in enumerate(key): | ||
if i >= self.obj.ndim: | ||
|
@@ -235,7 +235,7 @@ def _has_valid_tuple(self, key): | |
"[{types}] types".format(types=self._valid_types) | ||
) | ||
|
||
def _is_nested_tuple_indexer(self, tup): | ||
def _is_nested_tuple_indexer(self, tup: tuple): | ||
if any(isinstance(ax, MultiIndex) for ax in self.obj.axes): | ||
return any(is_nested_tuple(tup, ax) for ax in self.obj.axes) | ||
return False | ||
|
@@ -259,7 +259,7 @@ def _convert_tuple(self, key, is_setter: bool = False): | |
keyidx.append(idx) | ||
return tuple(keyidx) | ||
|
||
def _convert_range(self, key, is_setter: bool = False): | ||
def _convert_range(self, key: range, is_setter: bool = False): | ||
""" convert a range argument """ | ||
return list(key) | ||
|
||
|
@@ -269,7 +269,7 @@ def _convert_scalar_indexer(self, key, axis: int): | |
# a scalar | ||
return ax._convert_scalar_indexer(key, kind=self.name) | ||
|
||
def _convert_slice_indexer(self, key, axis: int): | ||
def _convert_slice_indexer(self, key: slice, axis: int): | ||
# if we are accessing via lowered dim, use the last dim | ||
ax = self.obj._get_axis(min(axis, self.ndim - 1)) | ||
return ax._convert_slice_indexer(key, kind=self.name) | ||
|
@@ -483,7 +483,7 @@ def setter(item, v): | |
if is_list_like_indexer(value) and getattr(value, "ndim", 1) > 0: | ||
|
||
# we have an equal len Frame | ||
if isinstance(value, ABCDataFrame) and value.ndim > 1: | ||
if isinstance(value, ABCDataFrame): | ||
sub_indexer = list(indexer) | ||
multiindex_indexer = isinstance(labels, MultiIndex) | ||
|
||
|
@@ -637,27 +637,23 @@ def _setitem_with_indexer_missing(self, indexer, value): | |
self.obj._maybe_update_cacher(clear=True) | ||
return self.obj | ||
|
||
def _align_series(self, indexer, ser, multiindex_indexer=False): | ||
def _align_series(self, indexer, ser: ABCSeries, multiindex_indexer: bool = False): | ||
""" | ||
Parameters | ||
---------- | ||
indexer : tuple, slice, scalar | ||
The indexer used to get the locations that will be set to | ||
`ser` | ||
|
||
ser : pd.Series | ||
The values to assign to the locations specified by `indexer` | ||
|
||
multiindex_indexer : boolean, optional | ||
Defaults to False. Should be set to True if `indexer` was from | ||
a `pd.MultiIndex`, to avoid unnecessary broadcasting. | ||
|
||
|
||
Returns | ||
------- | ||
`np.array` of `ser` broadcast to the appropriate shape for assignment | ||
to the locations selected by `indexer` | ||
|
||
""" | ||
if isinstance(indexer, (slice, np.ndarray, list, Index)): | ||
indexer = tuple([indexer]) | ||
|
@@ -733,7 +729,7 @@ def ravel(i): | |
|
||
raise ValueError("Incompatible indexer with Series") | ||
|
||
def _align_frame(self, indexer, df): | ||
def _align_frame(self, indexer, df: ABCDataFrame): | ||
is_frame = self.obj.ndim == 2 | ||
|
||
if isinstance(indexer, tuple): | ||
|
@@ -785,7 +781,7 @@ def _align_frame(self, indexer, df): | |
|
||
raise ValueError("Incompatible indexer with DataFrame") | ||
|
||
def _getitem_tuple(self, tup): | ||
def _getitem_tuple(self, tup: tuple): | ||
try: | ||
return self._getitem_lowerdim(tup) | ||
except IndexingError: | ||
|
@@ -808,7 +804,7 @@ def _getitem_tuple(self, tup): | |
|
||
return retval | ||
|
||
def _multi_take_opportunity(self, tup): | ||
def _multi_take_opportunity(self, tup: tuple): | ||
""" | ||
Check whether there is the possibility to use ``_multi_take``. | ||
Currently the limit is that all axes being indexed must be indexed with | ||
|
@@ -832,7 +828,7 @@ def _multi_take_opportunity(self, tup): | |
|
||
return True | ||
|
||
def _multi_take(self, tup): | ||
def _multi_take(self, tup: tuple): | ||
""" | ||
Create the indexers for the passed tuple of keys, and execute the take | ||
operation. This allows the take operation to be executed all at once - | ||
|
@@ -858,7 +854,7 @@ def _multi_take(self, tup): | |
def _convert_for_reindex(self, key, axis: int): | ||
return key | ||
|
||
def _handle_lowerdim_multi_index_axis0(self, tup): | ||
def _handle_lowerdim_multi_index_axis0(self, tup: tuple): | ||
# we have an axis0 multi-index, handle or raise | ||
axis = self.axis or 0 | ||
try: | ||
|
@@ -883,7 +879,7 @@ def _handle_lowerdim_multi_index_axis0(self, tup): | |
|
||
return None | ||
|
||
def _getitem_lowerdim(self, tup): | ||
def _getitem_lowerdim(self, tup: tuple): | ||
|
||
# we can directly get the axis result since the axis is specified | ||
if self.axis is not None: | ||
|
@@ -947,7 +943,7 @@ def _getitem_lowerdim(self, tup): | |
|
||
raise IndexingError("not applicable") | ||
|
||
def _getitem_nested_tuple(self, tup): | ||
def _getitem_nested_tuple(self, tup: tuple): | ||
# we have a nested tuple so have at least 1 multi-index level | ||
# we should be able to match up the dimensionality here | ||
|
||
|
@@ -1421,7 +1417,7 @@ def _getbool_axis(self, key, axis: int): | |
# caller is responsible for ensuring non-None axis | ||
labels = self.obj._get_axis(axis) | ||
key = check_bool_indexer(labels, key) | ||
inds, = key.nonzero() | ||
inds = key.nonzero()[0] | ||
try: | ||
return self.obj.take(inds, axis=axis) | ||
except Exception as detail: | ||
|
@@ -2042,7 +2038,7 @@ def _getitem_scalar(self, key): | |
values = self.obj._get_value(*key, takeable=True) | ||
return values | ||
|
||
def _validate_integer(self, key, axis): | ||
def _validate_integer(self, key: int, axis: int): | ||
""" | ||
Check that 'key' is a valid position in the desired axis. | ||
|
||
|
@@ -2067,7 +2063,7 @@ def _validate_integer(self, key, axis): | |
if key >= len_axis or key < -len_axis: | ||
raise IndexError("single positional indexer is out-of-bounds") | ||
|
||
def _getitem_tuple(self, tup): | ||
def _getitem_tuple(self, tup: tuple): | ||
|
||
self._has_valid_tuple(tup) | ||
try: | ||
|
@@ -2167,7 +2163,7 @@ class _ScalarAccessIndexer(_NDFrameIndexer): | |
""" access scalars quickly """ | ||
|
||
def _convert_key(self, key, is_setter: bool = False): | ||
return list(key) | ||
raise AbstractMethodError(self) | ||
|
||
def __getitem__(self, key): | ||
if not isinstance(key, tuple): | ||
|
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.
self.columns.get_indexer(key)
?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.
Looks like this returns something different, will have to keep digging