Skip to content

DOC: Validator + converting array_like to array-like in docstrings #41295

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
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,13 +1544,13 @@ def searchsorted(arr, value, side="left", sorter=None) -> np.ndarray:
Input array. If `sorter` is None, then it must be sorted in
ascending order, otherwise `sorter` must be an array of indices
that sort it.
value : array_like
value : array-like
Values to insert into `arr`.
side : {'left', 'right'}, optional
If 'left', the index of the first suitable location found is given.
If 'right', return the last such index. If there is no suitable
index, return either 0 or N (where N is the length of `self`).
sorter : 1-D array_like, optional
sorter : 1-D array-like, optional
Optional array of integer indices that sort array a into ascending
order. They are typically the result of argsort.

Expand Down
6 changes: 3 additions & 3 deletions pandas/core/array_algos/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ def compare_or_regex_search(
a: ArrayLike, b: Union[Scalar, Pattern], regex: bool, mask: np.ndarray
) -> Union[ArrayLike, bool]:
"""
Compare two array_like inputs of the same shape or two scalar values
Compare two array-like inputs of the same shape or two scalar values

Calls operator.eq or re.search, depending on regex argument. If regex is
True, perform an element-wise regex matching.

Parameters
----------
a : array_like
a : array-like
b : scalar or regex pattern
regex : bool
mask : np.ndarray[bool]

Returns
-------
mask : array_like of bool
mask : array-like of bool
"""
if isna(b):
return ~mask
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,13 @@ def searchsorted(self, value, side="left", sorter=None):

Parameters
----------
value : array_like
value : array-like
Values to insert into `self`.
side : {'left', 'right'}, optional
If 'left', the index of the first suitable location found is given.
If 'right', return the last such index. If there is no suitable
index, return either 0 or N (where N is the length of `self`).
sorter : 1-D array_like, optional
sorter : 1-D array-like, optional
Optional array of integer indices that sort array a into ascending
order. They are typically the result of argsort.

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,13 +1160,13 @@ def factorize(self, sort: bool = False, na_sentinel: int | None = -1):

Parameters
----------
value : array_like
value : array-like
Values to insert into `self`.
side : {{'left', 'right'}}, optional
If 'left', the index of the first suitable location found is given.
If 'right', return the last such index. If there is no suitable
index, return either 0 or N (where N is the length of `self`).
sorter : 1-D array_like, optional
sorter : 1-D array-like, optional
Optional array of integer indices that sort `self` into ascending
order. They are typically the result of ``np.argsort``.

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7489,11 +7489,11 @@ def clip(

Parameters
----------
lower : float or array_like, default None
lower : float or array-like, default None
Minimum threshold value. All values below this
threshold will be set to it. A missing
threshold (e.g `NA`) will not clip the value.
upper : float or array_like, default None
upper : float or array-like, default None
Maximum threshold value. All values above this
threshold will be set to it. A missing
threshold (e.g `NA`) will not clip the value.
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6065,8 +6065,8 @@ def any(self, *args, **kwargs):

Returns
-------
any : bool or array_like (if axis is specified)
A single element array_like may be converted to bool.
any : bool or array-like (if axis is specified)
A single element array-like may be converted to bool.

See Also
--------
Expand Down Expand Up @@ -6109,8 +6109,8 @@ def all(self, *args, **kwargs):

Returns
-------
all : bool or array_like (if axis is specified)
A single element array_like may be converted to bool.
all : bool or array-like (if axis is specified)
A single element array-like may be converted to bool.

See Also
--------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3892,7 +3892,7 @@ def maybe_droplevels(index: Index, key) -> Index:

def _coerce_indexer_frozen(array_like, categories, copy: bool = False) -> np.ndarray:
"""
Coerce the array_like indexer to the smallest integer dtype that can encode all
Coerce the array-like indexer to the smallest integer dtype that can encode all
of the given categories.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ def _unstack(self, unstacker, fill_value, new_placement):
-------
blocks : list of Block
New blocks of unstacked values.
mask : array_like of bool
mask : array-like of bool
The mask of columns of `blocks` we should keep.
"""
new_values, mask = unstacker.get_new_values(
Expand Down
26 changes: 13 additions & 13 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ def _from_derivatives(xi, yi, x, order=None, der=0, extrapolate=False):

Parameters
----------
xi : array_like
xi : array-like
sorted 1D array of x-coordinates
yi : array_like or list of array-likes
yi : array-like or list of array-likes
yi[i][j] is the j-th derivative known at xi[i]
order: None or int or array_like of ints. Default: None.
order: None or int or array-like of ints. Default: None.
Specifies the degree of local polynomials. If not None, some
derivatives are ignored.
der : int or list
Expand All @@ -546,7 +546,7 @@ def _from_derivatives(xi, yi, x, order=None, der=0, extrapolate=False):

Returns
-------
y : scalar or array_like
y : scalar or array-like
The result, of length R or length M or M by R.
"""
from scipy import interpolate
Expand All @@ -568,13 +568,13 @@ def _akima_interpolate(xi, yi, x, der=0, axis=0):

Parameters
----------
xi : array_like
xi : array-like
A sorted list of x-coordinates, of length N.
yi : array_like
yi : array-like
A 1-D array of real values. `yi`'s length along the interpolation
axis must be equal to the length of `xi`. If N-D array, use axis
parameter to select correct axis.
x : scalar or array_like
x : scalar or array-like
Of length M.
der : int, optional
How many derivatives to extract; None for all potentially
Expand All @@ -590,7 +590,7 @@ def _akima_interpolate(xi, yi, x, der=0, axis=0):

Returns
-------
y : scalar or array_like
y : scalar or array-like
The result, of length R or length M or M by R,

"""
Expand All @@ -609,14 +609,14 @@ def _cubicspline_interpolate(xi, yi, x, axis=0, bc_type="not-a-knot", extrapolat

Parameters
----------
xi : array_like, shape (n,)
xi : array-like, shape (n,)
1-d array containing values of the independent variable.
Values must be real, finite and in strictly increasing order.
yi : array_like
yi : array-like
Array containing values of the dependent variable. It can have
arbitrary number of dimensions, but the length along ``axis``
(see below) must match the length of ``x``. Values must be finite.
x : scalar or array_like, shape (m,)
x : scalar or array-like, shape (m,)
axis : int, optional
Axis along which `y` is assumed to be varying. Meaning that for
``x[i]`` the corresponding values are ``np.take(y, i, axis=axis)``.
Expand Down Expand Up @@ -644,7 +644,7 @@ def _cubicspline_interpolate(xi, yi, x, axis=0, bc_type="not-a-knot", extrapolat
tuple `(order, deriv_values)` allowing to specify arbitrary
derivatives at curve ends:
* `order`: the derivative order, 1 or 2.
* `deriv_value`: array_like containing derivative values, shape must
* `deriv_value`: array-like containing derivative values, shape must
be the same as `y`, excluding ``axis`` dimension. For example, if
`y` is 1D, then `deriv_value` must be a scalar. If `y` is 3D with
the shape (n0, n1, n2) and axis=2, then `deriv_value` must be 2D
Expand All @@ -661,7 +661,7 @@ def _cubicspline_interpolate(xi, yi, x, axis=0, bc_type="not-a-knot", extrapolat

Returns
-------
y : scalar or array_like
y : scalar or array-like
The result, of shape (m,)

References
Expand Down
6 changes: 3 additions & 3 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def hist_frame(
y : label or position, optional
Allows plotting of one column versus another. If not specified,
all numerical columns are used.
color : str, array_like, or dict, optional
color : str, array-like, or dict, optional
The color for each of the DataFrame's columns. Possible values are:

- A single color string referred to by name, RGB or RGBA code,
Expand Down Expand Up @@ -1568,7 +1568,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
y : int or str
The column name or column position to be used as vertical
coordinates for each point.
s : str, scalar or array_like, optional
s : str, scalar or array-like, optional
The size of each point. Possible values are:

- A string with the name of the column to be used for marker's size.
Expand All @@ -1581,7 +1581,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs):

.. versionchanged:: 1.1.0

c : str, int or array_like, optional
c : str, int or array-like, optional
The color of each point. Possible values are:

- A single color string referred to by name, RGB or RGBA code,
Expand Down
4 changes: 4 additions & 0 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
ERROR_MSGS = {
"GL04": "Private classes ({mentioned_private_classes}) should not be "
"mentioned in public docstrings",
"GL05": "Use 'array-like' rather than 'array_like' in docstrings.",
"SA05": "{reference_name} in `See Also` section does not need `pandas` "
"prefix, use {right_reference} instead.",
"EX02": "Examples do not pass tests:\n{doctest_log}",
Expand Down Expand Up @@ -258,6 +259,9 @@ def pandas_validate(func_name: str):
pandas_error("EX04", imported_library=wrong_import)
)

if "array_like" in doc.raw_doc:
result["errors"].append(pandas_error("GL05"))

return result


Expand Down