8000 DOC Fix doc of defaults in sklearn.utils.validation.py (#18048) · scikit-learn/scikit-learn@6a29e2c · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a29e2c

Browse files
DOC Fix doc of defaults in sklearn.utils.validation.py (#18048)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
1 parent 320b4c6 commit 6a29e2c

File tree

1 file changed

+56
-53
lines changed

1 file changed

+56
-53
lines changed

sklearn/utils/validation.py

+56-53
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333

3434

3535
def _deprecate_positional_args(f):
36-
"""Decorator for methods that issues warnings for positional arguments
36+
"""Decorator for methods that issues warnings for positional arguments.
3737
3838
Using the keyword-only argument syntax in pep 3102, arguments after the
3939
* will issue a warning when passed as a positional argument.
4040
4141
Parameters
4242
----------
43-
f : function
44-
function to check arguments on
43+
f : callable
44+
Function to check arguments on.
4545
"""
4646
sig = signature(f)
4747
kwonly_args = []
@@ -109,9 +109,9 @@ def assert_all_finite(X, *, allow_nan=False):
109109
110110
Parameters
111111
----------
112-
X : array or sparse matrix
112+
X : {ndarray, sparse matrix}
113113
114-
allow_nan : bool
114+
allow_nan : bool, default=False
115115
"""
116116
_assert_all_finite(X.data if sp.issparse(X) else X, allow_nan)
117117

@@ -132,7 +132,7 @@ def as_float_array(X, *, copy=True, force_all_finite=True):
132132
If True, a copy of X will be created. If False, a copy may still be
133133
returned if X's dtype is not a floating point type.
134134
135-
force_all_finite : boolean or 'allow-nan', default=True
135+
force_all_finite : bool or 'allow-nan', default=True
136136
Whether to raise an error on np.inf, np.nan, pd.NA in X. The
137137
possibilities are:
138138
@@ -149,8 +149,8 @@ def as_float_array(X, *, copy=True, force_all_finite=True):
149149
150150
Returns
151151
-------
152-
XT : {array, sparse matrix}
153-
An array of type float
152+
XT : {ndarray, sparse matrix}
153+
An array of type float.
154154
"""
155155
if isinstance(X, np.matrix) or (not isinstance(X, np.ndarray)
156156
and not sp.issparse(X)):
@@ -170,7 +170,7 @@ def as_float_array(X, *, copy=True, force_all_finite=True):
170170

171171

172172
def _is_arraylike(x):
173-
"""Returns whether the input is array-like"""
173+
"""Returns whether the input is array-like."""
174174
return (hasattr(x, '__len__') or
175175
hasattr(x, 'shape') or
176176
hasattr(x, '__array__'))
@@ -263,7 +263,7 @@ def _make_indexable(iterable):
263263
264264
Parameters
265265
----------
266-
iterable : {list, dataframe, array, sparse} or None
266+
iterable : {list, dataframe, ndarray, sparse matrix} or None
267267
Object to be converted to an indexable iterable.
268268
"""
269269
if sp.issparse(iterable):
@@ -284,7 +284,7 @@ def indexable(*iterables):
284284
285285
Parameters
286286
----------
287-
*iterables : lists, dataframes, arrays, sparse matrices
287+
*iterables : {lists, dataframes, ndarrays, sparse matrices}
288288
List of objects to ensure sliceability.
289289
"""
290290
result = [_make_indexable(X) for X in iterables]
@@ -300,24 +300,24 @@ def _ensure_sparse_format(spmatrix, accept_sparse, dtype, copy,
300300
301301
Parameters
302302
----------
303-
spmatrix : scipy sparse matrix
303+
spmatrix : sparse matrix
304304
Input to validate and convert.
305305
306-
accept_sparse : string, boolean or list/tuple of strings
306+
accept_sparse : str, bool or list/tuple of str
307307
String[s] representing allowed sparse matrix formats ('csc',
308308
'csr', 'coo', 'dok', 'bsr', 'lil', 'dia'). If the input is sparse but
309309
not in the allowed format, it will be converted to the first listed
310310
format. True allows the input to be any format. False means
311311
that a sparse matrix input will raise an error.
312312
313-
dtype : string, type or None
313+
dtype : str, type or None
314314
Data type of result. If None, the dtype of the input is preserved.
315315
316-
copy : boolean
316+
copy : bool
317317
Whether a forced copy will be triggered. If copy=False, a copy might
318318
be triggered by a conversion.
319319
320-
force_all_finite : boolean or 'allow-nan', default=True
320+
force_all_finite : bool or 'allow-nan'
321321
Whether to raise an error on np.inf, np.nan, pd.NA in X. The
322322
possibilities are:
323323
@@ -334,7 +334,7 @@ def _ensure_sparse_format(spmatrix, accept_sparse, dtype, copy,
334334
335335
Returns
336336
-------
337-
spmatrix_converted : scipy sparse matrix.
337+
spmatrix_converted : sparse matrix.
338338
Matrix that is ensured to have an allowed type.
339339
"""
340340
if dtype is None:
@@ -410,7 +410,7 @@ def check_array(array, accept_sparse=False, *, accept_large_sparse=True,
410410
array : object
411411
Input object to check / convert.
412412
413-
accept_sparse : string, boolean or list/tuple of strings, default=False
413+
accept_sparse : str, bool or list/tuple of str, default=False
414414
String[s] representing allowed sparse matrix formats, such as 'csc',
415415
'csr', etc. If the input is sparse but not in the allowed format,
416416
it will be converted to the first listed format. True allows the input
@@ -424,24 +424,24 @@ def check_array(array, accept_sparse=False, *, accept_large_sparse=True,
424424
425425
.. versionadded:: 0.20
426426
427-
dtype : string, type, list of types or None, default="numeric"
427+
dtype : 'numeric', type, list of type or None, default='numeric'
428428
Data type of result. If None, the dtype of the input is preserved.
429429
If "numeric", dtype is preserved unless array.dtype is object.
430430
If dtype is a list of types, conversion on the first type is only
431431
performed if the dtype of the input is not in the list.
432432
433-
order : 'F', 'C' or None, default=None
433+
order : {'F', 'C'} or None, default=None
434434
Whether an array will be forced to be fortran or c-style.
435435
When order is None (default), then if copy=False, nothing is ensured
436436
about the memory layout of the output array; otherwise (copy=True)
437437
the memory layout of the returned array is kept as close as possible
438438
to the original array.
439439
440-
copy : boolean, default=False
440+
copy : bool, default=False
441441
Whether a forced copy will be triggered. If copy=False, a copy might
442442
be triggered by a conversion.
443443
444-
force_all_finite : boolean or 'allow-nan', default=True
444+
force_all_finite : bool or 'allow-nan', default=True
445445
Whether to raise an error on np.inf, np.nan, pd.NA in array. The
446446
possibilities are:
447447
@@ -456,10 +456,10 @@ def check_array(array, accept_sparse=False, *, accept_large_sparse=True,
456456
.. versionchanged:: 0.23
457457
Accepts `pd.NA` and converts it into `np.nan`
458458
459-
ensure_2d : boolean, default=True
459+
ensure_2d : bool, default=True
460460
Whether to raise a value error if array is not 2D.
461461
462-
allow_nd : boolean, default=False
462+
allow_nd : bool, default=False
463463
Whether to allow array.ndim > 2.
464464
465465
ensure_min_samples : int, default=1
@@ -701,13 +701,13 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
701701
702702
Parameters
703703
----------
704-
X : nd-array, list or sparse matrix
704+
X : {ndarray, list, sparse matrix}
705705
Input data.
706706
707-
y : nd-array, list or sparse matrix
707+
y : {ndarray, list, sparse matrix}
708708
Labels.
709709
710-
accept_sparse : string, boolean or list of string, default=False
710+
accept_sparse : str, bool or list of str, default=False
711711
String[s] representing allowed sparse matrix formats, such as 'csc',
712712
'csr', etc. If the input is sparse but not in the allowed format,
713713
it will be converted to the first listed format. True allows the input
@@ -721,20 +721,20 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
721721
722722
.. versionadded:: 0.20
723723
724-
dtype : string, type, list of types or None, default="numeric"
724+
dtype : 'numeric', type, list of type or None, default='numeric'
725725
Data type of result. If None, the dtype of the input is preserved.
726726
If "numeric", dtype is preserved unless array.dtype is object.
727727
If dtype is a list of types, conversion on the first type is only
728728
performed if the dtype of the input is not in the list.
729729
730-
order : 'F', 'C' or None, default=None
730+
order : {'F', 'C'}, default=None
731731
Whether an array will be forced to be fortran or c-style.
732732
733-
copy : boolean, default=False
733+
copy : bool, default=False
734734
Whether a forced copy will be triggered. If copy=False, a copy might
735735
be triggered by a conversion.
736736
737-
force_all_finite : boolean or 'allow-nan', default=True
737+
force_all_finite : bool or 'allow-nan', default=True
738738
Whether to raise an error on np.inf, np.nan, pd.NA in X. This parameter
739739
does not influence whether y can have np.inf, np.nan, pd.NA values.
740740
The possibilities are:
@@ -750,13 +750,13 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
750750
.. versionchanged:: 0.23
751751
Accepts `pd.NA` and converts it into `np.nan`
752752
753-
ensure_2d : boolean, default=True
753+
ensure_2d : bool, default=True
754754
Whether to raise a value error if X is not 2D.
755755
756-
allow_nd : boolean, default=False
756+
allow_nd : bool, default=False
757757
Whether to allow X.ndim > 2.
758758
759-
multi_output : boolean, default=False
759+
multi_output : bool, default=False
760760
Whether to allow 2D y (array or sparse matrix). If false, y will be
761761
validated as a vector. y cannot have np.nan or np.inf values if
762762
multi_output=True.
@@ -772,7 +772,7 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
772772
is originally 1D and ``ensure_2d`` is True. Setting to 0 disables
773773
this check.
774774
775-
y_numeric : boolean, default=False
775+
y_numeric : bool, default=False
776776
Whether to ensure that y has a numeric type. If dtype of y is object,
777777
it is converted to float64. Should only be used for regression
778778
algorithms.
@@ -815,18 +815,18 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
815815

816816
@_deprecate_positional_args
817817
def column_or_1d(y, *, warn=False):
818-
""" Ravel column or 1d numpy array, else raises an error
818+
""" Ravel column or 1d numpy array, else raises an error.
819819
820820
Parameters
821821
----------
822822
y : array-like
823823
824-
warn : boolean, default False
824+
warn : bool, default=False
825825
To control display of warnings.
826826
827827
Returns
828828
-------
829-
y : array
829+
y : ndarray
830830
831831
"""
832832
y = np.asarray(y)
@@ -851,7 +851,7 @@ def check_random_state(seed):
851851
852852
Parameters
853853
----------
854-
seed : None | int | instance of RandomState
854+
seed : None, int or instance of RandomState
855855
If seed is None, return the RandomState singleton used by np.random.
856856
If seed is an int, return a new RandomState instance seeded with seed.
857857
If seed is already a RandomState instance, return it.
@@ -905,19 +905,22 @@ def check_symmetric(array, *, tol=1E-10, raise_warning=True,
905905
906906
Parameters
907907
----------
908-
array : nd-array or sparse matrix
908+
array : {ndarray, sparse matrix}
909909
Input object to check / convert. Must be two-dimensional and square,
910910
otherwise a ValueError will be raised.
911-
tol : float
911+
912+
tol : float, default=1e-10
912913
Absolute tolerance for equivalence of arrays. Default = 1E-10.
913-
raise_warning : boolean, default=True
914+
915+
raise_warning : bool, default=True
914916
If True then raise a warning if conversion is required.
915-
raise_exception : boolean, default=False
917+
918+
raise_exception : bool, default=False
916919
If True then raise an exception if array is not symmetric.
917920
918921
Returns
919922
-------
920-
array_sym : ndarray or sparse matrix
923+
array_sym : {ndarray, sparse matrix}
921924
Symmetrized version of the input array, i.e. the average of array
922925
and array.transpose(). If sparse, then duplicate entries are first
923926
summed and zeros are eliminated.
@@ -964,7 +967,7 @@ def check_is_fitted(estimator, attributes=None, *, msg=None, all_or_any=all):
964967
965968
Parameters
966969
----------
967-
estimator : estimator instance.
970+
estimator : estimator instance
968971
estimator instance for which the check is performed.
969972
970973
attributes : str, list or tuple of str, default=None
@@ -975,7 +978,7 @@ def check_is_fitted(estimator, attributes=None, *, msg=None, all_or_any=all):
975978
attribute that ends with a underscore and does not start with double
976979
underscore.
977980
978-
msg : string
981+
msg : str, default=None
979982
The default error message is, "This %(name)s instance is not fitted
980983
yet. Call 'fit' with appropriate arguments before using this
981984
estimator."
@@ -1024,10 +1027,10 @@ def check_non_negative(X, whom):
10241027
10251028
Parameters
10261029
----------
1027-
X : array-like or sparse matrix
1030+
X : {array-like, sparse matrix}
10281031
Input data.
10291032
1030-
whom : string
1033+
whom : str
10311034
Who passed X to this funct 10000 ion.
10321035
"""
10331036
# avoid X.min() on sparse matrix since it also sorts the indices
@@ -1263,7 +1266,7 @@ def _check_sample_weight(sample_weight, X, dtype=None):
12631266
sample_weight : {ndarray, Number or None}, shape (n_samples,)
12641267
Input sample weights.
12651268
1266-
X : nd-array, list or sparse matrix
1269+
X : {ndarray, list, sparse matrix}
12671270
Input data.
12681271
12691272
dtype: dtype
@@ -1275,7 +1278,7 @@ def _check_sample_weight(sample_weight, X, dtype=None):
12751278
12761279
Returns
12771280
-------
1278-
sample_weight : ndarray, shape (n_samples,)
1281+
sample_weight : ndarray of shape (n_samples,)
12791282
Validated sample weight. It is guaranteed to be "C" contiguous.
12801283
"""
12811284
n_samples = _num_samples(X)
@@ -1311,14 +1314,14 @@ def _allclose_dense_sparse(x, y, rtol=1e-7, atol=1e-9):
13111314
13121315
Parameters
13131316
----------
1314-
x : array-like or sparse matrix
1317+
x : {array-like, sparse matrix}
13151318
First array to compare.
13161319
1317-
y : array-like or sparse matrix
1320+
y : {array-like, sparse matrix}
13181321
Second array to compare.
13191322
13201323
rtol : float, default=1e-7
1321-
relative tolerance; see numpy.allclose
1324+
Relative tolerance; see numpy.allclose.
13221325
13231326
atol : float, default=1e-9
13241327
absolute tolerance; see numpy.allclose. Note that the default here is

0 commit comments

Comments
 (0)
0