diff --git a/cabal.project b/cabal.project index 133bec4e..4854b6e3 100644 --- a/cabal.project +++ b/cabal.project @@ -1,3 +1,4 @@ packages: . dataframe-fastcsv + examples diff --git a/examples/Main.hs b/examples/Main.hs index f09d076e..9b2cc0b9 100644 --- a/examples/Main.hs +++ b/examples/Main.hs @@ -1,9 +1,8 @@ module Main where -import qualified CaliforniaHousing import qualified Chipotle -import qualified Iris import qualified OneBillionRowChallenge +import qualified TypedHousingMini import System.Environment (getArgs) main :: IO () @@ -11,9 +10,12 @@ 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 " + "Usage: examples " diff --git a/examples/TypedHousingMini.hs b/examples/TypedHousingMini.hs new file mode 100644 index 00000000..db2c2db6 --- /dev/null +++ b/examples/TypedHousingMini.hs @@ -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)) diff --git a/examples/examples.cabal b/examples/examples.cabal index d521a262..2fe90b0d 100644 --- a/examples/examples.cabal +++ b/examples/examples.cabal @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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