8000 DOC Remove some str/unicode leftovers from Python 2 · scikit-learn/scikit-learn@8b16f5c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b16f5c

Browse files
DOC Remove some str/unicode leftovers from Python 2
* string → str (when meant as Python 2 `str` or `unicode` and not `bytes`) * unicode → str and str → bytes (when meant as Python 2 types) * str → bytes or str (when primarily meant for `bytes` and no-op for `str`)
1 parent 686ab3e commit 8b16f5c

17 files changed

+25
-26
lines changed

sklearn/datasets/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ def load_files(
141141
142142
Parameters
143143
----------
144-
container_path : str or unicode
144+
container_path : str
145145
Path to the main folder holding one subfolder per category
146146
147-
description : str or unicode, default=None
147+
description : str, default=None
148148
A paragraph describing the characteristic of the dataset: its source,
149149
reference, etc.
150150

sklearn/datasets/_california_housing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def fetch_california_housing(
102102
If ``as_frame`` is True, ``target`` is a pandas object.
103103
feature_names : list of length 8
104104
Array of ordered feature names used in the dataset.
105-
DESCR : string
105+
DESCR : str
106106
Description of the California housing dataset.
107107
frame : pandas DataFrame
108108
Only present when `as_frame=True`. DataFrame with ``data`` and

sklearn/datasets/_lfw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def fetch_lfw_people(
301301
target : numpy array of shape (13233,)
302302
Labels associated to each face image.
303303
Those labels range from 0-5748 and correspond to the person IDs.
304-
DESCR : string
304+
DESCR : str
305305
Description of the Labeled Faces in the Wild (LFW) dataset.
306306
307307
(data, target) : tuple if ``return_X_y`` is True
@@ -486,7 +486,7 @@ def fetch_lfw_pairs(
486486
target : numpy array of shape (2200,). Shape depends on ``subset``.
487487
Labels associated to each pair of images.
488488
The two label values being different persons or the same person.
489-
DESCR : string
489+
DESCR : str
490490
Description of the Labeled Faces in the Wild (LFW) dataset.
491491
492492
"""

sklearn/datasets/_svmlight_format_io.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def dump_svmlight_file(
446446
integer or float, or array-like objects of integer or float for
447447
multilabel classifications.
448448
449-
f : string or file-like in binary mode
449+
f : str or file-like in binary mode
450450
If string, specifies the path that will contain the data.
451451
If file-like, data will be written to f. f should be opened in binary
452452
mode.
@@ -455,7 +455,7 @@ def dump_svmlight_file(
455455
Whether column indices should be written zero-based (True) or one-based
456456
(False).
457457
458-
comment : string, default=None
458+
comment : str, default=None
459459
Comment to insert at the top of the file. This should be either a
460460
Unicode string, which will be encoded as UTF-8, or an ASCII byte
461461
string.
@@ -478,7 +478,6 @@ def dump_svmlight_file(
478478
# Convert comment string to list of lines in UTF-8.
479479
# If a byte string is passed, then check whether it's ASCII;
480480
# if a user wants to get fancy, they'll have to decode themselves.
481-
# Avoid mention of str and unicode types for Python 3.x compat.
482481
if isinstance(comment, bytes):
483482
comment.decode("ascii") # just for the exception
484483
else:

sklearn/datasets/_twenty_newsgroups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def fetch_20newsgroups(
184184
Select the dataset to load: 'train' for the training set, 'test'
185185
for the test set, 'all' for both, with shuffled ordering.
186186
187-
categories : array-like, dtype=str or unicode, default=None
187+
categories : array-like, dtype=str, default=None
188188
If None (default), load all the categories.
189189
If not None, list of category names to load (other categories
190190
ignored).

sklearn/feature_extraction/text.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def strip_accents_ascii(s):
156156
157157
Parameters
158158
----------
159-
s : string
159+
s : str
160160
The string to strip
161161
162162
See Also
@@ -175,7 +175,7 @@ def strip_tags(s):
175175
176176
Parameters
177177
----------
178-
s : string
178+
s : str
179179
The string to strip
180180
"""
181181
return re.compile(r"<([^>]+)>", flags=re.UNICODE).sub(" ", s)
@@ -204,7 +204,7 @@ def decode(self, doc):
204204
205205
Parameters
206206
----------
207-
doc : str
207+
doc : bytes or str
208208
The string to decode.
209209
210210
Returns
@@ -620,7 +620,7 @@ class HashingVectorizer(TransformerMixin, _VectorizerMixin, BaseEstimator):
620620
Remove accents and perform other character normalization
621621
during the preprocessing step.
622622
'ascii' is a fast method that only works on characters that have
623-
an direct ASCII mapping.
623+
a direct ASCII mapping.
624624
'unicode' is a slightly slower method that works on any characters.
625625
None (default) does nothing.
626626

sklearn/linear_model/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _deprecate_normalize(normalize, default, estimator_name):
6666
default : bool,
6767
default normalize value used by the estimator
6868
69-
estimator_name : string,
69+
estimator_name : str,
7070
name of the linear estimator which calls this function.
7171
The name will be used for writing the deprecation warnings
7272

sklearn/linear_model/_stochastic_gradient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def fit_binary(
392392
C : float
393393
Maximum step size for passive aggressive
394394
395-
learning_rate : string
395+
learning_rate : str
396396
The learning rate. Accepted values are 'constant', 'optimal',
397397
'invscaling', 'pa1' and 'pa2'.
398398

sklearn/metrics/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _average_binary_score(binary_metric, y_true, y_score, average, sample_weight
3232
Target scores, can either be probability estimates of the positive
3333
class, confidence values, or binary decisions.
3434
35-
average : string, [None, 'micro', 'macro' (default), 'samples', 'weighted']
35+
average : str, [None, 'micro', 'macro' (default), 'samples', 'weighted']
3636
If ``None``, the scores for each class are returned. Otherwise,
3737
this determines the type of averaging performed on the data:
3838

sklearn/metrics/_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ def classification_report(
20092009
20102010
Returns
20112011
-------
2012-
report : string / dict
2012+
report : str / dict
20132013
Text summary of the precision, recall, F1 score for each class.
20142014
Dictionary returned if output_dict is True. Dictionary has the
20152015
following structure::

sklearn/mixture/_base.py

Lines changed: 1 addition & 1 deletion
< 1241 td data-grid-cell-id="diff-d8d678f0b7496d281f98b52bd246b678d2f75412a891bb5c258f1ae09ec51034-31-31-1" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">31
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _check_shape(param, param_shape, name):
2828
2929
param_shape : tuple
3030
31-
name : string
+
name : str
3232
"""
3333
param = np.array(param)
3434
if param.shape != param_shape:

sklearn/mixture/_gaussian_mixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _check_precisions(precisions, covariance_type, n_components, n_features):
108108
'diag' : shape of (n_components, n_features)
109109
'spherical' : shape of (n_components,)
110110
111-
covariance_type : string
111+
covariance_type : str
112112
113113
n_components : int
114114
Number of components.

sklearn/neighbors/_dist_metrics.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ cdef class DistanceMetric:
235235
236236
Parameters
237237
----------
238-
metric : string or class name
238+
metric : str or class name
239239
The distance metric to use
240240
**kwargs
241241
additional arguments will be passed to the requested metric

sklearn/preprocessing/tests/test_encoders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ def test_encoder_dtypes():
800800
for X in [
801801
np.array([[1, 2], [3, 4]], dtype="int64"),
802802
np.array([[1, 2], [3, 4]], dtype="float64"),
803-
np.array([["a", "b"], ["c", "d"]]), # unicode dtype
804-
np.array([[b"a", b"b"], [b"c", b"d"]]), # string dtype
803+
np.array([["a", "b"], ["c", "d"]]), # str dtype
804+
np.array([[b"a", b"b"], [b"c", b"d"]]), # bytes dtype
805805
np.array([[1, "a"], [3, "b"]], dtype="object"),
806806
]:
807807
enc.fit(X)

sklearn/tree/_export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def export_graphviz(
839839
840840
Returns
841841
-------
842-
dot_data : string
842+
dot_data : str
843843
String representation of the input tree in GraphViz dot format.
844844
Only returned if ``out_file`` is None.
845845
@@ -961,7 +961,7 @@ def export_text(
961961
962962
Returns
963963
-------
964-
report : string
964+
report : str
965965
Text summary of all the rules in the decision tree.
966966
967967
Examples

sklearn/utils/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def graph_shortest_path(dist_matrix, directed=True, method="auto"):
9292
if False, then find the shortest path on an undirected graph: the
9393
algorithm can progress from a point to its neighbors and vice versa.
9494
95-
method : string ['auto'|'FW'|'D']
95+
method : str ['auto'|'FW'|'D']
9696
method to use. Options are
9797
'auto' : attempt to choose the best method for the current problem
9898
'FW' : Floyd-Warshall algorithm. O[N^3]

sklearn/utils/metaestimators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def if_delegate_has_method(delegate):
205205
206206
Parameters
207207
----------
208-
delegate : string, list of strings or tuple of strings
208+
delegate : str, list of str or tuple of str
209209
Name of the sub-estimator that can be accessed as an attribute of the
210210
base object. If a list or a tuple of names are provided, the first
211211
sub-estimator that is an attribute of the base object will be used.

0 commit comments

Comments
 (0)
0