Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
.
dataframe-fastcsv
examples
12 changes: 7 additions & 5 deletions examples/Main.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
module Main where

import qualified CaliforniaHousing
import qualified Chipotle
import qualified Iris
import qualified OneBillionRowChallenge
import qualified TypedHousingMini
import System.Environment (getArgs)

main :: IO ()
main = do
args <- getArgs
case args of
["chipotle"] -> Chipotle.run
["california_housing"] -> CaliforniaHousing.run
["california_housing"] ->
putStrLn "california_housing example requires hasktorch (disabled on Windows)."
["one_billion_row_challenge"] -> OneBillionRowChallenge.run
["iris"] -> Iris.run
["iris"] ->
putStrLn "iris example requires hasktorch (disabled on Windows)."
["typed_housing_mini"] -> TypedHousingMini.run
_ ->
putStrLn
"Usage: examples <chipotle|california_housing|one_billion_row_challenge|iris>"
"Usage: examples <chipotle|california_housing|one_billion_row_challenge|iris|typed_housing_mini>"
41 changes: 41 additions & 0 deletions examples/TypedHousingMini.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

module TypedHousingMini (run) where

import Data.Text (Text)
import qualified DataFrame as D
import qualified DataFrame.Typed as T

-- A small schema slice of `../data/housing.csv`.
--
-- NOTE: This is meant as a minimal TypedDataFrame integration example.
-- If the CSV inference/types drift, `T.freezeWithError` will report why.
type HousingMini =
'[ T.Column "median_income" Double
, T.Column "median_house_value" Double
, T.Column "ocean_proximity" Text
]

run :: IO ()
run = do
raw <- D.readCsv "../data/housing.csv"
let small =
D.select
["median_income", "median_house_value", "ocean_proximity"]
raw
case T.freezeWithError @HousingMini small of
Left err -> do
putStrLn "Failed to freeze into TypedDataFrame (schema mismatch):"
putStrLn (show err)
Right df -> do
putStrLn "OK: loaded TypedDataFrame slice from housing.csv"
print (T.nRows df)

let expensive =
T.filterWhere
(T.col @"median_house_value" T..>. T.lit 500000)
df
putStrLn ("Rows with median_house_value > 500000: " ++ show (T.nRows expensive))
15 changes: 9 additions & 6 deletions examples/examples.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ executable examples
ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N
default-extensions: Strict
other-modules: Chipotle,
CaliforniaHousing,
OneBillionRowChallenge,
Iris,
TypedHousingMini,
DataFrame,
DataFrame.Lazy,
DataFrame.Functions,
Expand All @@ -43,6 +42,7 @@ executable examples
DataFrame.Display.Terminal.PrettyPrint,
DataFrame.Display.Terminal.Colours,
DataFrame.Internal.DataFrame,
DataFrame.Internal.Grouping,
DataFrame.Internal.Row,
DataFrame.Internal.Schema,
DataFrame.Errors,
Expand Down Expand Up @@ -78,7 +78,6 @@ executable examples
DataFrame.Lazy.Internal.Optimizer,
DataFrame.Lazy.Internal.Executor,
DataFrame.Monad,
DataFrame.Hasktorch,
DataFrame.IO.Parquet.Seeking,
DataFrame.Internal.Binary,
DataFrame.Internal.Nullable,
Expand All @@ -95,8 +94,7 @@ executable examples
DataFrame.Typed.Expr,
DataFrame.Typed
hs-source-dirs: .,
../src,
../dataframe-hasktorch/src
../src
build-depends: base >= 4 && <5,
binary >= 0.8 && < 1,
aeson >= 0.11.0.0 && < 3,
Expand All @@ -110,7 +108,6 @@ executable examples
directory >= 1.3.0.0 && < 2,
granite ^>= 0.4,
hashable >= 1.2 && < 2,
hasktorch,
http-conduit,
process ^>= 1.6,
snappy-hs ^>= 0.1,
Expand All @@ -133,6 +130,12 @@ executable examples
stm >= 2.5 && < 3,
filepath >= 1.4 && < 2,
Glob >= 0.10 && < 1,
if !os(windows)
other-modules: CaliforniaHousing,
Iris,
DataFrame.Hasktorch
hs-source-dirs: ../dataframe-hasktorch/src
build-depends: hasktorch
if impl(ghc >= 9.12)
build-depends: ghc-typelits-natnormalise == 0.9.3
else
Expand Down