|
27 | 27 | ) |
28 | 28 | from skrub._to_float import ToFloat |
29 | 29 | from skrub._to_str import ToStr |
| 30 | +from skrub._utils import PassThrough |
30 | 31 | from skrub.conftest import _POLARS_INSTALLED |
31 | 32 |
|
32 | 33 | MSG_PANDAS_DEPRECATED_WARNING = "Skip deprecation warning" |
@@ -1280,38 +1281,61 @@ def test_duration_to_float(df_module): |
1280 | 1281 |
|
1281 | 1282 |
|
1282 | 1283 | 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 |
1298 | 1309 |
|
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 | + ) |
1300 | 1317 | _ = vectorizer.fit_transform(df) |
1301 | 1318 | vectorizer_output = vectorizer.list_transformations() |
1302 | 1319 | assert vectorizer_output == ( |
1303 | 1320 | "Columns with standardized nulls:\n\tlow_card\n\tdatetime\nColumns " |
1304 | 1321 | "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" |
1309 | 1330 | ) |
1310 | 1331 |
|
1311 | | - vectorizer = Cleaner() |
| 1332 | + vectorizer = Cleaner(drop_if_constant=True) |
1312 | 1333 | _ = vectorizer.fit_transform(df) |
1313 | 1334 | cleaner_output = vectorizer.list_transformations() |
1314 | 1335 | assert ( |
1315 | 1336 | 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" |
1317 | 1341 | ) |
0 commit comments