@@ -25,6 +25,14 @@ import Test.HUnit
2525-- Shared fixtures
2626------------------------------------------------------------------------
2727
28+ {- | Build a 'TargetInfo' or fail loudly; the test fixtures always satisfy
29+ 'mkTargetInfo', so a 'Nothing' here is a broken test, not a runtime case.
30+ -}
31+ requireTargetInfo :: T. Text -> D. DataFrame -> TargetInfo T. Text
32+ requireTargetInfo target df = case mkTargetInfo @ T. Text target df of
33+ Just ti -> ti
34+ Nothing -> error (" requireTargetInfo: no target info for " <> T. unpack target)
35+
2836-- 4 rows: label = ["A","B","A","C"], x = [1.0,2.0,3.0,4.0]
2937fixtureDF :: D. DataFrame
3038fixtureDF =
@@ -853,19 +861,19 @@ taoLinearProducesSparsity = TestCase $ do
853861 -- With sufficient L1 strength, the chosen split should mention only a and b.
854862 let n = 50 :: Int
855863 xs = [fromIntegral i / 10 - 2.5 :: Double | i <- [0 .. n - 1 ]]
856- as = xs
864+ avals = xs
857865 bs = map (* 0.7 ) xs
858866 -- noise: take xs and shift them so they don't correlate with a+b
859867 cs = [fromIntegral ((i * 7 ) `mod` 11 ) / 5 - 1 :: Double | i <- [0 .. n - 1 ]]
860868 ds = [fromIntegral ((i * 13 ) `mod` 7 ) / 3 - 1 :: Double | i <- [0 .. n - 1 ]]
861869 labels =
862- [ if (as !! i) + (bs !! i) > 0 then " pos" else " neg" :: T. Text
870+ [ if (avals !! i) + (bs !! i) > 0 then " pos" else " neg" :: T. Text
863871 | i <- [0 .. n - 1 ]
864872 ]
865873 df =
866874 D. fromNamedColumns
867875 [ (" label" , DI. fromList labels)
868- , (" a" , DI. fromList as )
876+ , (" a" , DI. fromList avals )
869877 , (" b" , DI. fromList bs)
870878 , (" c" , DI. fromList cs)
871879 , (" d" , DI. fromList ds)
@@ -967,7 +975,7 @@ breimanBinaryDF =
967975
968976testCategoricalBreimanBinary :: Test
969977testCategoricalBreimanBinary = TestCase $ do
970- let Just ti = mkTargetInfo @ T. Text " label" breimanBinaryDF
978+ let ti = requireTargetInfo " label" breimanBinaryDF
971979 conds =
972980 discreteConditions @ T. Text
973981 ti
@@ -993,7 +1001,7 @@ testCategoricalSubsetsMulticlassLowCard = TestCase $ do
9931001 ]
9941002 |> D. rename " 0" " feat"
9951003 |> D. rename " 1" " label"
996- Just ti = mkTargetInfo @ T. Text " label" df
1004+ ti = requireTargetInfo " label" df
9971005 conds = discreteConditions @ T. Text ti defaultTreeConfig (D. exclude [" label" ] df)
9981006 feat = " feat"
9991007 feats' = filter (\ c -> feat `elem` getColumns c) conds
@@ -1013,7 +1021,7 @@ testCategoricalSingletonsMulticlassHighCard = TestCase $ do
10131021 ]
10141022 |> D. rename " 0" " feat"
10151023 |> D. rename " 1" " label"
1016- Just ti = mkTargetInfo @ T. Text " label" df
1024+ ti = requireTargetInfo " label" df
10171025 conds = discreteConditions @ T. Text ti defaultTreeConfig (D. exclude [" label" ] df)
10181026 feat = " feat"
10191027 feats' = filter (\ c -> feat `elem` getColumns c) conds
@@ -1030,7 +1038,7 @@ testCategoricalCardZero = TestCase $ do
10301038 ]
10311039 |> D. rename " 0" " feat"
10321040 |> D. rename " 1" " label"
1033- Just ti = mkTargetInfo @ T. Text " label" df
1041+ ti = requireTargetInfo " label" df
10341042 conds = discreteConditions @ T. Text ti defaultTreeConfig (D. exclude [" label" ] df)
10351043 feat = " feat"
10361044 feats' = filter (\ c -> feat `elem` getColumns c) conds
@@ -1083,7 +1091,7 @@ testCategoricalNullableBinary = TestCase $ do
10831091 ]
10841092 |> D. rename " 0" " feat"
10851093 |> D. rename " 1" " label"
1086- Just ti = mkTargetInfo @ T. Text " label" df
1094+ ti = requireTargetInfo " label" df
10871095 conds = discreteConditions @ T. Text ti defaultTreeConfig (D. exclude [" label" ] df)
10881096 feat = " feat" :: T. Text
10891097 feats' = filter (\ c -> feat `elem` getColumns c) conds
0 commit comments