Skip to content

Commit e0990b9

Browse files
committed
fix: More formatting errors
1 parent ad1beff commit e0990b9

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

tests/Cart.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ tests =
5656
]
5757

5858
readJson :: (FromJSON a) => FilePath -> IO (Either String a)
59-
readJson path = do
60-
e <- try (BL.readFile path) :: IO (Either SomeException BL.ByteString)
59+
readJson fp = do
60+
e <- try (BL.readFile fp) :: IO (Either SomeException BL.ByteString)
6161
pure $ case e of
6262
Left _ -> Left "missing"
6363
Right raw -> eitherDecode raw

tests/DecisionTree.hs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
2937
fixtureDF :: D.DataFrame
3038
fixtureDF =
@@ -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

968976
testCategoricalBreimanBinary :: Test
969977
testCategoricalBreimanBinary = 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

tests/LinearSolver.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ testA1RecoverHyperplane = TestCase $ do
106106
, scTol = 1e-6
107107
}
108108
model = fitL1Logistic cfg rows labels (V.fromList ["x", "y"])
109-
cos = cosineSim (lmWeights model) groundTruth
109+
cosSim = cosineSim (lmWeights model) groundTruth
110110
sameSignAll =
111111
all
112112
(\i -> predict model (rows V.! i) == labels VU.! i)
113113
[0 .. V.length rows - 1]
114114
assertBool
115-
("recovered weights should align with ground truth (cos = " ++ show cos ++ ")")
116-
(cos > 0.99)
115+
("recovered weights should align with ground truth (cos = " ++ show cosSim ++ ")")
116+
(cosSim > 0.99)
117117
assertBool "all training points predicted correctly" sameSignAll
118118

119119
------------------------------------------------------------------------
@@ -669,7 +669,9 @@ testA19ElasticNetRecoveryHigh = TestCase $ do
669669
men = fitL1Logistic cfgEN rows labels names
670670
wEN = VU.toList (lmWeights men)
671671
nzCount xs = length (filter (/= 0) xs)
672-
[aEN, bEN] = take 2 wEN
672+
(aEN, bEN) = case wEN of
673+
(a : b : _) -> (a, b)
674+
_ -> error "elastic-net test: expected at least two weights"
673675
assertBool
674676
("ρ=0.97 EN keeps f0 non-zero; wEN[:2] = " ++ show (take 2 wEN))
675677
(aEN /= 0)
@@ -693,7 +695,9 @@ testA19ElasticNetRecoveryMid = TestCase $ do
693695
cfgEN = defaultSolverConfig{scL1Lambda = 0.05, scL2Lambda = 0.05, scMaxIter = 1000}
694696
men = fitL1Logistic cfgEN rows labels names
695697
wEN = VU.toList (lmWeights men)
696-
[aEN, bEN] = take 2 wEN
698+
(aEN, bEN) = case wEN of
699+
(a : b : _) -> (a, b)
700+
_ -> error "elastic-net test: expected at least two weights"
697701
assertBool
698702
("ρ=0.7 EN keeps f0 non-zero; wEN[:2] = " ++ show (take 2 wEN))
699703
(aEN /= 0)

tests/Properties/Simplify.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ genTree d
131131

132132
evalBool :: D.DataFrame -> Expr Bool -> Maybe (VU.Vector Bool)
133133
evalBool df e = case interpret @Bool df e of
134-
Right (TColumn col) -> either (const Nothing) Just (toVector @Bool @VU.Vector col)
134+
Right (TColumn tcol) -> either (const Nothing) Just (toVector @Bool @VU.Vector tcol)
135135
Left _ -> Nothing
136136

137137
evalMaybe :: D.DataFrame -> Expr (Maybe Bool) -> Maybe (V.Vector (Maybe Bool))
138138
evalMaybe df e = case interpret @(Maybe Bool) df e of
139-
Right (TColumn col) -> either (const Nothing) Just (toVector @(Maybe Bool) @V.Vector col)
139+
Right (TColumn tcol) -> either (const Nothing) Just (toVector @(Maybe Bool) @V.Vector tcol)
140140
Left _ -> Nothing
141141

142142
-- ---- properties ----

0 commit comments

Comments
 (0)