Skip to content

DOC: Cleaned docstrings in core/indexers.py #30131

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 2 commits into from
Dec 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions pandas/core/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ def is_list_like_indexer(key) -> bool:


def is_scalar_indexer(indexer, arr_value) -> bool:
# return True if we are all scalar indexers
"""
Return True if we are all scalar indexers.

Returns
-------
bool
"""
if arr_value.ndim == 1:
if not isinstance(indexer, tuple):
indexer = tuple([indexer])
Expand Down Expand Up @@ -73,11 +78,11 @@ def check_setitem_lengths(indexer, value, values) -> None:
Parameters
----------
indexer : sequence
The key for the setitem
Key for the setitem.
value : array-like
The value for the setitem
Value for the setitem.
values : array-like
The values being set into
Values being set into.

Returns
-------
Expand All @@ -86,8 +91,7 @@ def check_setitem_lengths(indexer, value, values) -> None:
Raises
------
ValueError
When the indexer is an ndarray or list and the lengths don't
match.
When the indexer is an ndarray or list and the lengths don't match.
"""
# boolean with truth values == len of the value is ok too
if isinstance(indexer, (np.ndarray, list)):
Expand Down Expand Up @@ -122,7 +126,7 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
----------
indices : ndarray
n : int
length of the array being indexed
Length of the array being indexed.

Raises
------
Expand All @@ -144,9 +148,8 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
if len(indices):
min_idx = indices.min()
if min_idx < -1:
raise ValueError(
f"'indices' contains values less than allowed ({min_idx} < -1)"
)
msg = f"'indices' contains values less than allowed ({min_idx} < -1)"
raise ValueError(msg)

max_idx = indices.max()
if max_idx >= n:
Expand All @@ -167,27 +170,27 @@ def maybe_convert_indices(indices, n: int):
Parameters
----------
indices : array-like
The array of indices that we are to convert.
Array of indices that we are to convert.
n : int
The number of elements in the array that we are indexing.
Number of elements in the array that we are indexing.

Returns
-------
valid_indices : array-like
array-like
An array-like of positive indices that correspond to the ones
that were passed in initially to this function.

Raises
------
IndexError : one of the converted indices either exceeded the number
of elements (specified by `n`) OR was still negative.
IndexError
One of the converted indices either exceeded the number of,
elements (specified by `n`), or was still negative.
"""

if isinstance(indices, list):
indices = np.array(indices)
if len(indices) == 0:
# If list is empty, np.array will return float and cause indexing
# errors.
# If `indices` is empty, np.array will return a float,
# and will cause indexing errors.
return np.empty(0, dtype=np.intp)

mask = indices < 0
Expand All @@ -207,7 +210,11 @@ def maybe_convert_indices(indices, n: int):

def length_of_indexer(indexer, target=None) -> int:
"""
return the length of a single non-tuple indexer which could be a slice
Return the length of a single non-tuple indexer which could be a slice.

Returns
-------
int
"""
if target is not None and isinstance(indexer, slice):
target_len = len(target)
Expand Down