Skip to content

Commit 5e604eb

Browse files
committed
Fix bug with sorting.
Index errors.
1 parent 8078dd8 commit 5e604eb

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Data/DataFrame/Internal/Row.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mkRowFromArgs names df i = V.map get (V.fromList names)
3939
Just (UnboxedColumn column) -> toRowValue (column VU.! i)
4040

4141
mkRowRep :: DataFrame -> S.Set T.Text -> Int -> Row
42-
mkRowRep df names i = V.generate (S.size names) (\index -> get index (names' V.! index))
42+
mkRowRep df names i = V.generate (S.size names) (\index -> get (names' V.! index))
4343
where
4444
inOrderIndexes = map fst $ L.sortBy (compare `on` snd) $ M.toList (columnIndices df)
4545
names' = V.fromList [n | n <- inOrderIndexes, S.member n names]
@@ -48,23 +48,23 @@ mkRowRep df names i = V.generate (S.size names) (\index -> get index (names' V.!
4848
++ " has less items than "
4949
++ "the other columns at index "
5050
++ show i
51-
get index name = case getColumn name df of
52-
Just (BoxedColumn c) -> case c V.!? index of
51+
get name = case getColumn name df of
52+
Just (BoxedColumn c) -> case c V.!? i of
5353
Just e -> toRowValue e
5454
Nothing -> throwError name
55-
Just (UnboxedColumn c) -> case c VU.!? index of
55+
Just (UnboxedColumn c) -> case c VU.!? i of
5656
Just e -> toRowValue e
5757
Nothing -> throwError name
58-
Just (GroupedBoxedColumn c) -> case c V.!? index of
58+
Just (GroupedBoxedColumn c) -> case c V.!? i of
5959
Just e -> toRowValue e
6060
Nothing -> throwError name
61-
Just (GroupedUnboxedColumn c) -> case c V.!? index of
61+
Just (GroupedUnboxedColumn c) -> case c V.!? i of
6262
Just e -> toRowValue e
6363
Nothing -> throwError name
6464

6565
sortedIndexes' :: Bool -> V.Vector Row -> VU.Vector Int
6666
sortedIndexes' asc rows = runST $ do
6767
withIndexes <- VG.thaw (V.indexed rows)
68-
VA.sortBy (\(a, b) (a', b') -> (if asc then compare else flip compare) b b') withIndexes
68+
VA.sortBy ((if asc then compare else flip compare) `on` snd) withIndexes
6969
sorted <- VG.unsafeFreeze withIndexes
7070
return $ VU.generate (VG.length rows) (\i -> fst (sorted VG.! i))

src/Data/DataFrame/Internal/Types.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{-# LANGUAGE ScopedTypeVariables #-}
99
{-# LANGUAGE TypeApplications #-}
1010
{-# LANGUAGE TypeOperators #-}
11+
{-# LANGUAGE Strict #-}
1112
module Data.DataFrame.Internal.Types where
1213

1314
import Data.Int ( Int8, Int16, Int32, Int64 )
@@ -37,6 +38,10 @@ instance Ord RowValue where
3738
Refl <- testEquality (typeOf a) (typeOf b)
3839
return $ a <= b
3940

41+
instance Show RowValue where
42+
show :: RowValue -> String
43+
show (Value a) = show a
44+
4045
toRowValue :: forall a . (Columnable a) => a -> RowValue
4146
toRowValue = Value
4247

0 commit comments

Comments
 (0)