Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37e821b

Browse files
lestevejeremiedbb
authored andcommitted
MNT Adjust code after NEP 51 numpy scalar formatting changes (#27042)
1 parent 0ba978f commit 37e821b

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

sklearn/dummy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def fit(self, X, y, sample_weight=None):
227227
"The constant target value must be present in "
228228
"the training data. You provided constant={}. "
229229
"Possible values are: {}.".format(
230-
self.constant, list(self.classes_[k])
230+
self.constant, self.classes_[k].tolist()
231231
)
232232
)
233233
raise ValueError(err_msg)

sklearn/impute/tests/test_impute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def test_imputation_median_special_cases():
259259
@pytest.mark.parametrize("dtype", [None, object, str])
260260
def test_imputation_mean_median_error_invalid_type(strategy, dtype):
261261
X = np.array([["a", "b", 3], [4, "e", 6], ["g", "h", 9]], dtype=dtype)
262-
msg = "non-numeric data:\ncould not convert string to float: '"
262+
msg = "non-numeric data:\ncould not convert string to float:"
263263
with pytest.raises(ValueError, match=msg):
264264
imputer = SimpleImputer(strategy=strategy)
265265
imputer.fit_transform(X)
@@ -272,7 +272,7 @@ def test_imputation_mean_median_error_invalid_type_list_pandas(strategy, type):
272272
if type == "dataframe":
273273
pd = pytest.importorskip("pandas")
274274
X = pd.DataFrame(X)
275-
msg = "non-numeric data:\ncould not convert string to float: '"
275+
msg = "non-numeric data:\ncould not convert string to float:"
276276
with pytest.raises(ValueError, match=msg):
277277
imputer = SimpleImputer(strategy=strategy)
278278
imputer.fit_transform(X)

sklearn/preprocessing/_encoders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,8 @@ def _map_drop_idx_to_infrequent(self, feature_idx, drop_idx):
774774
if infrequent_indices is not None and drop_idx in infrequent_indices:
775775
categories = self.categories_[feature_idx]
776776
raise ValueError(
777-
f"Unable to drop category {categories[drop_idx]!r} from feature"
778-
f" {feature_idx} because it is infrequent"
777+
f"Unable to drop category {categories[drop_idx].item()!r} from"
778+
f" feature {feature_idx} because it is infrequent"
779779
)
780780
return default_to_infrequent[drop_idx]
781781

sklearn/utils/class_weight.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ def compute_class_weight(class_weight, *, classes, y):
6868

6969
n_weighted_classes = len(classes) - len(unweighted_classes)
7070
if unweighted_classes and n_weighted_classes != len(class_weight):
71+
unweighted_classes_user_friendly_str = np.array(unweighted_classes).tolist()
7172
raise ValueError(
72-
f"The classes, {unweighted_classes}, are not in class_weight"
73+
f"The classes, {unweighted_classes_user_friendly_str}, are not in"
74+
" class_weight"
7375
)
7476

7577
return weight

sklearn/utils/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ def _check_pos_label_consistency(pos_label, y_true):
22432243
or np.array_equal(classes, [1])
22442244
)
22452245
):
2246-
classes_repr = ", ".join(repr(c) for c in classes)
2246+
classes_repr = ", ".join([repr(c) for c in classes.tolist()])
22472247
raise ValueError(
22482248
f"y_true takes value in {{{classes_repr}}} and pos_label is not "
22492249
"specified: either make y_true take value in {0, 1} or "

0 commit comments

Comments
 (0)