33
33
34
34
35
35
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.
37
37
38
38
Using the keyword-only argument syntax in pep 3102, arguments after the
39
39
* will issue a warning when passed as a positional argument.
40
40
41
41
Parameters
42
42
----------
43
- f : function
44
- function to check arguments on
43
+ f : callable
44
+ Function to check arguments on.
45
45
"""
46
46
sig = signature (f )
47
47
kwonly_args = []
@@ -109,9 +109,9 @@ def assert_all_finite(X, *, allow_nan=False):
109
109
110
110
Parameters
111
111
----------
112
- X : array or sparse matrix
112
+ X : {ndarray, sparse matrix}
113
113
114
- allow_nan : bool
114
+ allow_nan : bool, default=False
115
115
"""
116
116
_assert_all_finite (X .data if sp .issparse (X ) else X , allow_nan )
117
117
@@ -132,7 +132,7 @@ def as_float_array(X, *, copy=True, force_all_finite=True):
132
132
If True, a copy of X will be created. If False, a copy may still be
133
133
returned if X's dtype is not a floating point type.
134
134
135
- force_all_finite : boolean or 'allow-nan', default=True
135
+ force_all_finite : bool or 'allow-nan', default=True
136
136
Whether to raise an error on np.inf, np.nan, pd.NA in X. The
137
137
possibilities are:
138
138
@@ -149,8 +149,8 @@ def as_float_array(X, *, copy=True, force_all_finite=True):
149
149
150
150
Returns
151
151
-------
152
- XT : {array , sparse matrix}
153
- An array of type float
152
+ XT : {ndarray , sparse matrix}
153
+ An array of type float.
154
154
"""
155
155
if isinstance (X , np .matrix ) or (not isinstance (X , np .ndarray )
156
156
and not sp .issparse (X )):
@@ -170,7 +170,7 @@ def as_float_array(X, *, copy=True, force_all_finite=True):
170
170
171
171
172
172
def _is_arraylike (x ):
173
- """Returns whether the input is array-like"""
173
+ """Returns whether the input is array-like. """
174
174
return (hasattr (x , '__len__' ) or
175
175
hasattr (x , 'shape' ) or
176
176
hasattr (x , '__array__' ))
@@ -263,7 +263,7 @@ def _make_indexable(iterable):
263
263
264
264
Parameters
265
265
----------
266
- iterable : {list, dataframe, array , sparse} or None
266
+ iterable : {list, dataframe, ndarray , sparse matrix } or None
267
267
Object to be converted to an indexable iterable.
268
268
"""
269
269
if sp .issparse (iterable ):
@@ -284,7 +284,7 @@ def indexable(*iterables):
284
284
285
285
Parameters
286
286
----------
287
- *iterables : lists, dataframes, arrays , sparse matrices
287
+ *iterables : { lists, dataframes, ndarrays , sparse matrices}
288
288
List of objects to ensure sliceability.
289
289
"""
290
290
result = [_make_indexable (X ) for X in iterables ]
@@ -300,24 +300,24 @@ def _ensure_sparse_format(spmatrix, accept_sparse, dtype, copy,
300
300
301
301
Parameters
302
302
----------
303
- spmatrix : scipy sparse matrix
303
+ spmatrix : sparse matrix
304
304
Input to validate and convert.
305
305
306
- accept_sparse : string, boolean or list/tuple of strings
306
+ accept_sparse : str, bool or list/tuple of str
307
307
String[s] representing allowed sparse matrix formats ('csc',
308
308
'csr', 'coo', 'dok', 'bsr', 'lil', 'dia'). If the input is sparse but
309
309
not in the allowed format, it will be converted to the first listed
310
310
format. True allows the input to be any format. False means
311
311
that a sparse matrix input will raise an error.
312
312
313
- dtype : string , type or None
313
+ dtype : str , type or None
314
314
Data type of result. If None, the dtype of the input is preserved.
315
315
316
- copy : boolean
316
+ copy : bool
317
317
Whether a forced copy will be triggered. If copy=False, a copy might
318
318
be triggered by a conversion.
319
319
320
- force_all_finite : boolean or 'allow-nan', default=True
320
+ force_all_finite : bool or 'allow-nan'
321
321
Whether to raise an error on np.inf, np.nan, pd.NA in X. The
322
322
possibilities are:
323
323
@@ -334,7 +334,7 @@ def _ensure_sparse_format(spmatrix, accept_sparse, dtype, copy,
334
334
335
335
Returns
336
336
-------
337
- spmatrix_converted : scipy sparse matrix.
337
+ spmatrix_converted : sparse matrix.
338
338
Matrix that is ensured to have an allowed type.
339
339
"""
340
340
if dtype is None :
@@ -410,7 +410,7 @@ def check_array(array, accept_sparse=False, *, accept_large_sparse=True,
410
410
array : object
411
411
Input object to check / convert.
412
412
413
- accept_sparse : string, boolean or list/tuple of strings , default=False
413
+ accept_sparse : str, bool or list/tuple of str , default=False
414
414
String[s] representing allowed sparse matrix formats, such as 'csc',
415
415
'csr', etc. If the input is sparse but not in the allowed format,
416
416
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,
424
424
425
425
.. versionadded:: 0.20
426
426
427
- dtype : string , type, list of types or None, default=" numeric"
427
+ dtype : 'numeric' , type, list of type or None, default=' numeric'
428
428
Data type of result. If None, the dtype of the input is preserved.
429
429
If "numeric", dtype is preserved unless array.dtype is object.
430
430
If dtype is a list of types, conversion on the first type is only
431
431
performed if the dtype of the input is not in the list.
432
432
433
- order : 'F', 'C' or None, default=None
433
+ order : { 'F', 'C'} or None, default=None
434
434
Whether an array will be forced to be fortran or c-style.
435
435
When order is None (default), then if copy=False, nothing is ensured
436
436
about the memory layout of the output array; otherwise (copy=True)
437
437
the memory layout of the returned array is kept as close as possible
438
438
to the original array.
439
439
440
- copy : boolean , default=False
440
+ copy : bool , default=False
441
441
Whether a forced copy will be triggered. If copy=False, a copy might
442
442
be triggered by a conversion.
443
443
444
- force_all_finite : boolean or 'allow-nan', default=True
444
+ force_all_finite : bool or 'allow-nan', default=True
445
445
Whether to raise an error on np.inf, np.nan, pd.NA in array. The
446
446
possibilities are:
447
447
@@ -456,10 +456,10 @@ def check_array(array, accept_sparse=False, *, accept_large_sparse=True,
456
456
.. versionchanged:: 0.23
457
457
Accepts `pd.NA` and converts it into `np.nan`
458
458
459
- ensure_2d : boolean , default=True
459
+ ensure_2d : bool , default=True
460
460
Whether to raise a value error if array is not 2D.
461
461
462
- allow_nd : boolean , default=False
462
+ allow_nd : bool , default=False
463
463
Whether to allow array.ndim > 2.
464
464
465
465
ensure_min_samples : int, default=1
@@ -701,13 +701,13 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
701
701
702
702
Parameters
703
703
----------
704
- X : nd-array , list or sparse matrix
704
+ X : {ndarray , list, sparse matrix}
705
705
Input data.
706
706
707
- y : nd-array , list or sparse matrix
707
+ y : {ndarray , list, sparse matrix}
708
708
Labels.
709
709
710
- accept_sparse : string, boolean or list of string , default=False
710
+ accept_sparse : str, bool or list of str , default=False
711
711
String[s] representing allowed sparse matrix formats, such as 'csc',
712
712
'csr', etc. If the input is sparse but not in the allowed format,
713
713
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,
721
721
722
722
.. versionadded:: 0.20
723
723
724
- dtype : string , type, list of types or None, default=" numeric"
724
+ dtype : 'numeric' , type, list of type or None, default=' numeric'
725
725
Data type of result. If None, the dtype of the input is preserved.
726
726
If "numeric", dtype is preserved unless array.dtype is object.
727
727
If dtype is a list of types, conversion on the first type is only
728
728
performed if the dtype of the input is not in the list.
729
729
730
- order : 'F', 'C' or None , default=None
730
+ order : { 'F', 'C'} , default=None
731
731
Whether an array will be forced to be fortran or c-style.
732
732
733
- copy : boolean , default=False
733
+ copy : bool , default=False
734
734
Whether a forced copy will be triggered. If copy=False, a copy might
735
735
be triggered by a conversion.
736
736
737
- force_all_finite : boolean or 'allow-nan', default=True
737
+ force_all_finite : bool or 'allow-nan', default=True
738
738
Whether to raise an error on np.inf, np.nan, pd.NA in X. This parameter
739
739
does not influence whether y can have np.inf, np.nan, pd.NA values.
740
740
The possibilities are:
@@ -750,13 +750,13 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
750
750
.. versionchanged:: 0.23
751
751
Accepts `pd.NA` and converts it into `np.nan`
752
752
753
- ensure_2d : boolean , default=True
753
+ ensure_2d : bool , default=True
754
754
Whether to raise a value error if X is not 2D.
755
755
756
- allow_nd : boolean , default=False
756
+ allow_nd : bool , default=False
757
757
Whether to allow X.ndim > 2.
758
758
759
- multi_output : boolean , default=False
759
+ multi_output : bool , default=False
760
760
Whether to allow 2D y (array or sparse matrix). If false, y will be
761
761
validated as a vector. y cannot have np.nan or np.inf values if
762
762
multi_output=True.
@@ -772,7 +772,7 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
772
772
is originally 1D and ``ensure_2d`` is True. Setting to 0 disables
773
773
this check.
774
774
775
- y_numeric : boolean , default=False
775
+ y_numeric : bool , default=False
776
776
Whether to ensure that y has a numeric type. If dtype of y is object,
777
777
it is converted to float64. Should only be used for regression
778
778
algorithms.
@@ -815,18 +815,18 @@ def check_X_y(X, y, accept_sparse=False, *, accept_large_sparse=True,
815
815
816
816
@_deprecate_positional_args
817
817
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.
819
819
820
820
Parameters
821
821
----------
822
822
y : array-like
823
823
824
- warn : boolean , default False
824
+ warn : bool , default= False
825
825
To control display of warnings.
826
826
827
827
Returns
828
828
-------
829
- y : array
829
+ y : ndarray
830
830
831
831
"""
832
832
y = np .asarray (y )
@@ -851,7 +851,7 @@ def check_random_state(seed):
851
851
852
852
Parameters
853
853
----------
854
- seed : None | int | instance of RandomState
854
+ seed : None, int or instance of RandomState
855
855
If seed is None, return the RandomState singleton used by np.random.
856
856
If seed is an int, return a new RandomState instance seeded with seed.
857
857
If seed is already a RandomState instance, return it.
@@ -905,19 +905,22 @@ def check_symmetric(array, *, tol=1E-10, raise_warning=True,
905
905
906
906
Parameters
907
907
----------
908
- array : nd-array or sparse matrix
908
+ array : {ndarray, sparse matrix}
909
909
Input object to check / convert. Must be two-dimensional and square,
910
910
otherwise a ValueError will be raised.
911
- tol : float
911
+
912
+ tol : float, default=1e-10
912
913
Absolute tolerance for equivalence of arrays. Default = 1E-10.
913
- raise_warning : boolean, default=True
914
+
915
+ raise_warning : bool, default=True
914
916
If True then raise a warning if conversion is required.
915
- raise_exception : boolean, default=False
917
+
918
+ raise_exception : bool, default=False
916
919
If True then raise an exception if array is not symmetric.
917
920
918
921
Returns
919
922
-------
920
- array_sym : ndarray or sparse matrix
923
+ array_sym : { ndarray, sparse matrix}
921
924
Symmetrized version of the input array, i.e. the average of array
922
925
and array.transpose(). If sparse, then duplicate entries are first
923
926
summed and zeros are eliminated.
@@ -964,7 +967,7 @@ def check_is_fitted(estimator, attributes=None, *, msg=None, all_or_any=all):
964
967
965
968
Parameters
966
969
----------
967
- estimator : estimator instance.
970
+ estimator : estimator instance
968
971
estimator instance for which the check is performed.
969
972
970
973
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):
975
978
attribute that ends with a underscore and does not start with double
976
979
underscore.
977
980
978
- msg : string
981
+ msg : str, default=None
979
982
The default error message is, "This %(name)s instance is not fitted
980
983
yet. Call 'fit' with appropriate arguments before using this
981
984
estimator."
@@ -1024,10 +1027,10 @@ def check_non_negative(X, whom):
1024
1027
1025
1028
Parameters
1026
1029
----------
1027
- X : array-like or sparse matrix
1030
+ X : { array-like, sparse matrix}
1028
1031
Input data.
1029
1032
1030
- whom : string
1033
+ whom : str
1031
1034
Who passed X to this funct
10000
ion.
1032
1035
"""
1033
1036
# 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):
1263
1266
sample_weight : {ndarray, Number or None}, shape (n_samples,)
1264
1267
Input sample weights.
1265
1268
1266
- X : nd-array , list or sparse matrix
1269
+ X : {ndarray , list, sparse matrix}
1267
1270
Input data.
1268
1271
1269
1272
dtype: dtype
@@ -1275,7 +1278,7 @@ def _check_sample_weight(sample_weight, X, dtype=None):
1275
1278
1276
1279
Returns
1277
1280
-------
1278
- sample_weight : ndarray, shape (n_samples,)
1281
+ sample_weight : ndarray of shape (n_samples,)
1279
1282
Validated sample weight. It is guaranteed to be "C" contiguous.
1280
1283
"""
1281
1284
n_samples = _num_samples (X )
@@ -1311,14 +1314,14 @@ def _allclose_dense_sparse(x, y, rtol=1e-7, atol=1e-9):
1311
1314
1312
1315
Parameters
1313
1316
----------
1314
- x : array-like or sparse matrix
1317
+ x : { array-like, sparse matrix}
1315
1318
First array to compare.
1316
1319
1317
- y : array-like or sparse matrix
1320
+ y : { array-like, sparse matrix}
1318
1321
Second array to compare.
1319
1322
1320
1323
rtol : float, default=1e-7
1321
- relative tolerance; see numpy.allclose
1324
+ Relative tolerance; see numpy.allclose.
1322
1325
1323
1326
atol : float, default=1e-9
1324
1327
absolute tolerance; see numpy.allclose. Note that the default here is
0 commit comments