@@ -383,5 +383,30 @@ duplicate_metrics = run_quality_metrics(
383383# The last 5 rows (with high values) should have lower mean anomaly scores
384384# Since they are all clumped between 2 and 4, whereas 0.1 is by itself
385385expect_true(mean(duplicate_metrics $ AnomalyScores [6 : 10 ]) < mean(duplicate_metrics $ AnomalyScores [1 : 5 ]),
386- info = " Rows 6-10 (values clumped 2-4) should have lower
386+ info = " Rows 6-10 (values clumped 2-4) should have lower
387387 anomaly scores than rows 1-5 (isolated value of 0.1)" )
388+
389+ nan_first_row_df = create_base_df(5 )
390+ nan_first_row_df $ QualityMetric.mean_increase = c(NA , 0.2 , 0.4 , 0.6 , 0.8 )
391+
392+ nan_first_row_result = tryCatch({
393+ MSstatsConvert ::: .runAnomalyModel(
394+ nan_first_row_df ,
395+ n_trees = 100 ,
396+ max_depth = " auto" ,
397+ cores = 1 ,
398+ split_column = " PSM" ,
399+ quality_metrics = c(" QualityMetric.mean_increase" ))
400+ }, error = function (e ) e )
401+
402+ expect_false(inherits(nan_first_row_result , " error" ),
403+ info = paste(
404+ " Anomaly model should not crash/error when a quality metric has a" ,
405+ " leading NA/NaN value within a PSM group." ,
406+ if (inherits(nan_first_row_result , " error" ))
407+ paste(" Got error:" , conditionMessage(nan_first_row_result )) else " " ))
408+
409+ if (! inherits(nan_first_row_result , " error" )) {
410+ expect_true(all(is.finite(nan_first_row_result $ AnomalyScores )),
411+ info = " Anomaly scores should be finite even when a quality metric has a leading missing value" )
412+ }
0 commit comments