Skip to content

Commit 0bb9b57

Browse files
author
Eloi Massoulié
committed
Improved test coverage
1 parent 35195e2 commit 0bb9b57

2 files changed

Lines changed: 48 additions & 30 deletions

File tree

skrub/_table_vectorizer.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ def _list_transformations(estimator):
202202
if dropped:
203203
message += "Columns dropped by DropUninformative:" + "\n\t"
204204
message += "\n\t".join(limit_cols(dropped))
205-
message += f"Used inputs: {transformer.used_inputs_}" + "\n"
206205
# case ToFloat():
207206
# if transformer not in post:
208207
# message += "Columns transformed to float:" + "\n"
@@ -1233,8 +1232,9 @@ def list_transformations(self):
12331232
if self.specific_transformers:
12341233
for t in self.specific_transformers:
12351234
specific_transformations += (
1236-
f"specific transformer {t} was applied to {limit_cols(specific)}"
1235+
f"specific transformer {t[0]} was applied to:" + "\n\t"
12371236
)
1237+
specific_transformations += "\n\t".join(limit_cols(specific)) + "\n"
12381238

12391239
return (
12401240
preprocessing_transformations
@@ -1245,12 +1245,6 @@ def list_transformations(self):
12451245
)
12461246

12471247

1248-
def repr_format(s):
1249-
without_spaces = repr(s).replace(" ", "")
1250-
without_lineskip = without_spaces.replace("\n", "")
1251-
return without_lineskip
1252-
1253-
12541248
def limit_cols(col_names, max_cols=10):
12551249
if len(col_names) > max_cols:
12561250
list_cols = list(col_names)[:max_cols] + ["..."]

skrub/tests/test_table_vectorizer.py

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828
from skrub._to_float import ToFloat
2929
from skrub._to_str import ToStr
30+
from skrub._utils import PassThrough
3031
from skrub.conftest import _POLARS_INSTALLED
3132

3233
MSG_PANDAS_DEPRECATED_WARNING = "Skip deprecation warning"
@@ -1280,38 +1281,61 @@ def test_duration_to_float(df_module):
12801281

12811282

12821283
def test_list_transformations(df_module):
1283-
df = df_module.make_dataframe(
1284-
{
1285-
"numbers": [1, 2, 3, 4, 5, 6, None],
1286-
"low_card": ["up", "up", "up", "down", "down", "up", "down"],
1287-
"datetime": [
1288-
"2026-06-01",
1289-
"2026-06-04",
1290-
"2026-07-03",
1291-
"2026-05-29",
1292-
"2026-01-08",
1293-
"2026-06-20",
1294-
None,
1295-
],
1296-
}
1297-
)
1284+
passthrough_line = [
1285+
"red",
1286+
"orange",
1287+
"yellow",
1288+
"green",
1289+
"blue",
1290+
"indigo",
1291+
"violet",
1292+
]
1293+
df_dict = {
1294+
"numbers": [1, 2, 3, 4, 5, 6, None],
1295+
"low_card": ["up", "up", "up", "down", "down", "up", "down"],
1296+
"datetime": [
1297+
"2026-06-01",
1298+
"2026-06-04",
1299+
"2026-07-03",
1300+
"2026-05-29",
1301+
"2026-01-08",
1302+
"2026-06-20",
1303+
None,
1304+
],
1305+
"uninformative": [False, False, False, False, False, False, False],
1306+
}
1307+
for i in range(1, 12):
1308+
df_dict[f"passthrough_{i}"] = passthrough_line
12981309

1299-
vectorizer = TableVectorizer()
1310+
df = df_module.make_dataframe(df_dict)
1311+
1312+
vectorizer = TableVectorizer(
1313+
specific_transformers=[
1314+
(PassThrough(), [f"passthrough_{i}" for i in range(1, 12)])
1315+
]
1316+
)
13001317
_ = vectorizer.fit_transform(df)
13011318
vectorizer_output = vectorizer.list_transformations()
13021319
assert vectorizer_output == (
13031320
"Columns with standardized nulls:\n\tlow_card\n\tdatetime\nColumns "
13041321
"transformed to datetime:\n\tdatetime\n\n\nnumeric transformer is "
1305-
"PassThrough and was applied to:\n\tnumbers\ndatetime transformer "
1306-
"is DatetimeEncoder and was applied to:\n\tdatetime\nlow_cardinality "
1307-
"transformer is OneHotEncoder and was applied to:\n\tlow_card\n"
1308-
"No high_cardinality columns have been detected.\n\n\n"
1322+
"PassThrough and was applied to:\n\tnumbers\n\tuninformative\ndatetime "
1323+
"transformer is DatetimeEncoder and was applied to:\n\tdatetime\n"
1324+
"low_cardinality transformer is OneHotEncoder and was applied to:\n\t"
1325+
"low_card\nNo high_cardinality columns have been detected.\n\n\nspecific "
1326+
"transformer PassThrough() was applied to:\n\tpassthrough_1\n\t"
1327+
"passthrough_2\n\tpassthrough_3\n\tpassthrough_4\n\tpassthrough_5\n\t"
1328+
"passthrough_6\n\tpassthrough_7\n\tpassthrough_8\n\tpassthrough_9\n\t"
1329+
"passthrough_10\n\t...\n"
13091330
)
13101331

1311-
vectorizer = Cleaner()
1332+
vectorizer = Cleaner(drop_if_constant=True)
13121333
_ = vectorizer.fit_transform(df)
13131334
cleaner_output = vectorizer.list_transformations()
13141335
assert (
13151336
cleaner_output == "Columns with standardized nulls:\n\tlow_card\n\t"
1316-
"datetime\nColumns transformed to datetime:\n\tdatetime\n"
1337+
"datetime\n\tpassthrough_1\n\tpassthrough_2\n\tpassthrough_3\n\t"
1338+
"passthrough_4\n\tpassthrough_5\n\tpassthrough_6\n\tpassthrough_7\n\t"
1339+
"passthrough_8\n\t...\nColumns dropped by DropUninformative:\n\t"
1340+
"uninformativeColumns transformed to datetime:\n\tdatetime\n"
13171341
)

0 commit comments

Comments
 (0)