Skip to content

Commit

Permalink
fix wrong change
Browse files Browse the repository at this point in the history
  • Loading branch information
xadupre committed Sep 7, 2024
1 parent 69e9ef5 commit 169e9df
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mlinsights/helpers/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def to_str(self, nrows=5):
"""
rows = [f"BaseEstimatorDebugInformation({self.model.__class__.__name__})"]
for k in sorted(self.inputs):
assert k in self.outputs, f"Unable to find output for method '{k}'."
assert k in self.outputs, f"Unable to find output for method {k!r}."
rows.append(" " + k + "(")
self.display(self.inputs[k], nrows)
rows.append(textwrap.indent(self.display(self.inputs[k], nrows), " "))
Expand Down
2 changes: 1 addition & 1 deletion mlinsights/mlbatch/cache_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def as_key(params):
elif v is None:
sv = ""
else:
raise TypeError(f"Unable to create a key with value '{k}':{v}")
raise TypeError(f"Unable to create a key with value {k!r}:{v!r}")
els.append((k, sv))
return str(els)

Expand Down
13 changes: 7 additions & 6 deletions mlinsights/mlmodel/categories_to_integers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ def fit(self, X, y=None, **fit_params):
"""
if not isinstance(X, pandas.DataFrame):
raise TypeError(f"this transformer only accept Dataframes, not {type(X)}")
if self.columns:
columns = self.columns
else:
columns = [c for c, d in zip(X.columns, X.dtypes) if d in (object,)]
columns = (
self.columns
if self.columns
else [c for c, d in zip(X.columns, X.dtypes) if d in (object, str)]
)

self._fit_columns = columns
max_cat = max(len(X) // 2 + 1, 10000)
Expand All @@ -86,7 +87,7 @@ def fit(self, X, y=None, **fit_params):
raise ValueError(
f"Too many categories ({nb}) for one column '{c}' max_cat={max_cat}"
)
self._categories[c] = dict(enumerate(list(sorted(distinct))))
self._categories[c] = {c: i for i, c in enumerate(list(sorted(distinct)))}

self._schema = self._build_schema()
return self
Expand Down Expand Up @@ -181,7 +182,7 @@ def transform(v, vec):
lv.append("...")
m = "\n".join(map(str, lv))
raise ValueError(
f"Unable to find category value {k}: {v} "
f"Unable to find category value {k!r}: {v!r} "
f"type(v)={type(v)} among\n{m}"
)
p = pos[k]
Expand Down
2 changes: 1 addition & 1 deletion mlinsights/mlmodel/classification_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def set_params(self, **values):
elif k.startswith("c_"):
pc[k[2:]] = v
else:
raise ValueError(f"Unexpected parameter name '{k}'")
raise ValueError(f"Unexpected parameter name {k!r}")
self.clus.set_params(**pc)
self.estimator.set_params(**pe)

Expand Down
2 changes: 1 addition & 1 deletion mlinsights/mlmodel/kmeans_l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _validate_center_shape(X, k, centers):
"""Check if centers is compatible with X and n_clusters"""
assert centers.shape[0] == k, (
f"The shape of the initial centers {centers.shape} does not "
f"match the number of clusters {k}."
f"match the number of clusters {k!r}."
)
assert centers.shape[1] == X.shape[1], (
f"The shape of the initial centers {centers.shape} does not "
Expand Down
4 changes: 2 additions & 2 deletions mlinsights/mlmodel/sklearn_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def run_test_sklearn_clone(fct_model, ext=None, copy_fitted=False):
ext.assertEqual(p1[k], p2[k])
except AssertionError as e:
raise AssertionError(
f"Difference for key '{k}'\n==1 {p1[k]}\n==2 {p2[k]}"
f"Difference for key {k!r}\n==1 {p1[k]}\n==2 {p2[k]}"
) from e
return conv, cloned

Expand Down Expand Up @@ -303,7 +303,7 @@ def adjust(obj1, obj2):
v1 = getattr(obj1, k)
setattr(obj2, k, clone_with_fitted_parameters(v1))
else:
raise RuntimeError(f"Cloned object is missing '{k}' in {obj2}.")
raise RuntimeError(f"Cloned object is missing {k!r} in {obj2}.")

if isinstance(est, BaseEstimator):
cloned = clone(est)
Expand Down
6 changes: 3 additions & 3 deletions mlinsights/sklapi/sklearn_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def compare_params(
for k in p1:
if k not in p2:
if exc:
raise KeyError(f"Key '{k}' was removed.")
raise KeyError(f"Key {k!r} was removed.")
return False
for k in p2:
if k not in p1:
if exc:
raise KeyError(f"Key '{k}' was added.")
raise KeyError(f"Key {k!r} was added.")
return False
for k in sorted(p1):
v1, v2 = p1[k], p2[k]
Expand Down Expand Up @@ -133,7 +133,7 @@ def compare_params(
if not b:
if exc:
raise ValueError(
f"Values for key '{k}' are different.\n---\n{v1}\n---\n{v2}"
f"Values for key {k!r} are different.\n---\n{v1}\n---\n{v2}"
)
return False
return True
Expand Down
2 changes: 1 addition & 1 deletion mlinsights/sklapi/sklearn_base_transform_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def set_params(self, **values):
del values["method"]
for k in values:
if not k.startswith("model__"):
raise ValueError(f"Parameter '{k}' must start with 'model__'.")
raise ValueError(f"Parameter {k!r} must start with 'model__'.")
d = len("model__")
pars = {k[d:]: v for k, v in values.items()}
self.model.set_params(**pars)
Expand Down
2 changes: 1 addition & 1 deletion mlinsights/sklapi/sklearn_base_transform_stacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def set_params(self, **values):
del values["method"]
for k, _v in values.items():
if not k.startswith("models_"):
raise ValueError(f"Parameter '{k}' must start with 'models_'.")
raise ValueError(f"Parameter {k!r} must start with 'models_'.")
d = len("models_")
pars = [{} for m in self.models]
for k, v in values.items():
Expand Down

0 comments on commit 169e9df

Please sign in to comment.