@@ -90,6 +90,7 @@ def pipeline_ml_with_intermediary_artifacts():
90
90
inputs = "data" ,
91
91
outputs = "encoder" ,
92
92
tags = ["training" ],
93
+ name = "node_fit_encoder_fun_data" ,
93
94
),
94
95
node (
95
96
func = apply_encoder_fun ,
@@ -258,11 +259,69 @@ def catalog_with_parameters():
258
259
return catalog_with_parameters
259
260
260
261
262
+ def test_pipeline_ml_only_nodes (
263
+ caplog ,
264
+ pipeline_ml_with_intermediary_artifacts ,
265
+ ):
266
+ """When the pipeline is filtered with only_nodes, we return only the training pipeline. This is for kedro-viz and resume hints compatibility"""
267
+
268
+ # pipeline_ml_with_namespace are fixture in conftest
269
+
270
+ # remember : the arguments are iterable, so do not pass string directly (e.g ["training"] rather than training)
271
+
272
+ filtered_pipeline_ml = pipeline_ml_with_intermediary_artifacts .only_nodes (
273
+ "node_fit_encoder_fun_data"
274
+ )
275
+
276
+ # PipelineML class must be preserved when filtering
277
+ # inference should be unmodified
278
+ # training pipeline nodes must be identical to kedro filtering.
279
+ assert isinstance (filtered_pipeline_ml , Pipeline )
280
+ assert not isinstance (filtered_pipeline_ml , PipelineML )
281
+ assert str (filtered_pipeline_ml ) == str (
282
+ pipeline_ml_with_intermediary_artifacts .training .only_nodes (
283
+ "node_fit_encoder_fun_data"
284
+ )
285
+ )
286
+ assert (
287
+ "for compatibility with kedro-viz and pipeline resume hints on failure"
288
+ in caplog .text
289
+ )
290
+
291
+
292
+ def test_pipeline_ml_only_nodes_with_outputs (
293
+ caplog ,
294
+ pipeline_ml_with_intermediary_artifacts ,
295
+ ):
296
+ """When the pipeline is filtered with only_nodes, we return only the training pipeline. This is for kedro-viz and resume hints compatibility"""
297
+
298
+ # pipeline_ml_with_intermediary_artifacts are fixture in conftest
299
+
300
+ # remember : the arguments are iterable, so do not pass string directly (e.g ["training"] rather than training)
301
+
302
+ filtered_pipeline_ml = (
303
+ pipeline_ml_with_intermediary_artifacts .only_nodes_with_outputs ("data" )
304
+ )
305
+
306
+ # PipelineML class must be preserved when filtering
307
+ # inference should be unmodified
308
+ # training pipeline nodes must be identical to kedro filtering.
309
+ assert isinstance (filtered_pipeline_ml , Pipeline )
310
+ assert not isinstance (filtered_pipeline_ml , PipelineML )
311
+ assert str (filtered_pipeline_ml ) == str (
312
+ pipeline_ml_with_intermediary_artifacts .training .only_nodes_with_outputs ("data" )
313
+ )
314
+ assert (
315
+ "for compatibility with kedro-viz and pipeline resume hints on failure"
316
+ in caplog .text
317
+ )
318
+
319
+
261
320
def test_pipeline_ml_only_nodes_with_namespace (
262
321
caplog ,
263
322
pipeline_ml_with_namespace ,
264
323
):
265
- """When the pipeline is filtered with only_nodes_with_namespace , we return only the training pipeline. This is for kedro viz compatibility"""
324
+ """When the pipeline is filtered with only_nodes , we return only the training pipeline. This is for kedro- viz and resume hints compatibility"""
266
325
267
326
# pipeline_ml_with_namespace are fixture in conftest
268
327
@@ -278,7 +337,10 @@ def test_pipeline_ml_only_nodes_with_namespace(
278
337
assert isinstance (filtered_pipeline_ml , Pipeline )
279
338
assert not isinstance (filtered_pipeline_ml , PipelineML )
280
339
assert str (filtered_pipeline_ml ) == str (pipeline_ml_with_namespace .training )
281
- assert "kedro-viz but should never be" in caplog .text
340
+ assert (
341
+ "for compatibility with kedro-viz and pipeline resume hints on failure"
342
+ in caplog .text
343
+ )
282
344
283
345
284
346
def test_pipeline_ml_substraction (
@@ -301,7 +363,58 @@ def test_pipeline_ml_substraction(
301
363
# training pipeline nodes must be identical to kedro filtering.
302
364
assert isinstance (filtered_pipeline_ml , Pipeline )
303
365
assert not isinstance (filtered_pipeline_ml , PipelineML )
304
- assert "kedro-viz but should never be" in caplog .text
366
+ assert (
367
+ "for compatibility with kedro-viz and pipeline resume hints on failure"
368
+ in caplog .text
369
+ )
370
+
371
+
372
+ def test_pipeline_ml_addition (
373
+ caplog ,
374
+ pipeline_ml_with_namespace ,
375
+ pipeline_ml_with_tag ,
376
+ ):
377
+ """When the pipeline is filtered with only_nodes_with_namespace, we return only the training pipeline. This is for kedro viz compatibility"""
378
+
379
+ # pipeline_ml_with_namespace are fixture in conftest
380
+
381
+ # remember : the arguments are iterable, so do not pass string directly (e.g ["training"] rather than training)
382
+
383
+ sum_of_pipeline_ml = pipeline_ml_with_namespace + pipeline_ml_with_tag
384
+
385
+ # PipelineML class must be preserved when filtering
386
+ # inference should be unmodified
387
+ # training pipeline nodes must be identical to kedro filtering.
388
+ assert isinstance (sum_of_pipeline_ml , Pipeline )
389
+ assert not isinstance (sum_of_pipeline_ml , PipelineML )
390
+ assert (
391
+ "for compatibility with kedro-viz and pipeline resume hints on failure"
392
+ in caplog .text
393
+ )
394
+
395
+
396
+ def test_pipeline_ml_or (
397
+ caplog ,
398
+ pipeline_ml_with_namespace ,
399
+ pipeline_ml_with_tag ,
400
+ ):
401
+ """When the pipeline is filtered with only_nodes_with_namespace, we return only the training pipeline. This is for kedro viz compatibility"""
402
+
403
+ # pipeline_ml_with_namespace are fixture in conftest
404
+
405
+ # remember : the arguments are iterable, so do not pass string directly (e.g ["training"] rather than training)
406
+
407
+ or_of_pipeline_ml = pipeline_ml_with_namespace | pipeline_ml_with_tag
408
+
409
+ # PipelineML class must be preserved when filtering
410
+ # inference should be unmodified
411
+ # training pipeline nodes must be identical to kedro filtering.
412
+ assert isinstance (or_of_pipeline_ml , Pipeline )
413
+ assert not isinstance (or_of_pipeline_ml , PipelineML )
414
+ assert (
415
+ "for compatibility with kedro-viz and pipeline resume hints on failure"
416
+ in caplog .text
417
+ )
305
418
306
419
307
420
@pytest .mark .parametrize (
@@ -316,7 +429,7 @@ def test_pipeline_ml_substraction(
316
429
(None , None , None , None , ["data" ]),
317
430
],
318
431
)
319
- def test_filtering_pipeline_ml (
432
+ def test_pipeline_ml_filtering (
320
433
mocker ,
321
434
pipeline_with_tag ,
322
435
pipeline_ml_with_tag ,
@@ -374,7 +487,7 @@ def test_filtering_pipeline_ml(
374
487
(None , None , None , ["preprocess_fun([raw_data]) -> [data]" ], None ),
375
488
],
376
489
)
377
- def test_filtering_generate_invalid_pipeline_ml (
490
+ def test_pipeline_ml__filtering_generate_invalid_pipeline_ml (
378
491
mocker ,
379
492
pipeline_ml_obj ,
380
493
tags ,
@@ -405,7 +518,7 @@ def test_filtering_generate_invalid_pipeline_ml(
405
518
# pass
406
519
407
520
408
- def test_too_many_free_inputs ():
521
+ def test_pipeline_ml_too_many_free_inputs ():
409
522
with pytest .raises (KedroMlflowPipelineMLError , match = "No free input is allowed" ):
410
523
pipeline_ml_factory (
411
524
training = Pipeline (
@@ -430,7 +543,7 @@ def test_too_many_free_inputs():
430
543
)
431
544
432
545
433
- def test_tagging (pipeline_ml_with_tag ):
546
+ def test_pipeline_ml_tagging (pipeline_ml_with_tag ):
434
547
new_pl = pipeline_ml_with_tag .tag (["hello" ])
435
548
assert all (["hello" in node .tags for node in new_pl .nodes ])
436
549
0 commit comments