dataframe-csv-th (empty) → 1.0.0.0
raw patch · 4 files changed
+122/−0 lines, 4 filesdep +basedep +dataframe-coredep +dataframe-csv
Dependencies added: base, dataframe-core, dataframe-csv, dataframe-th, template-haskell
Files
- LICENSE +20/−0
- dataframe-csv-th.cabal +38/−0
- src/DataFrame/TH/CSV.hs +39/−0
- src/DataFrame/Typed/TH/CSV.hs +25/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2026 Michael Chavinda++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ dataframe-csv-th.cabal view
@@ -0,0 +1,38 @@+cabal-version: 2.4+name: dataframe-csv-th+version: 1.0.0.0++synopsis: CSV-file-based Template Haskell splices for the dataframe ecosystem.+description:+ Splices that read CSV files at compile time and emit per-column+ bindings and typed schema synonyms. Record-based splices live in+ @dataframe-th@.++bug-reports: https://github.com/mchav/dataframe/issues+license: MIT+license-file: LICENSE+author: Michael Chavinda+maintainer: mschavinda@gmail.com+copyright: (c) 2024-2025 Michael Chavinda+category: Data+tested-with: GHC ==9.4.8 || ==9.6.7 || ==9.8.4 || ==9.10.3 || ==9.12.2++common warnings+ ghc-options:+ -Wincomplete-patterns+ -Wincomplete-uni-patterns+ -Wunused-imports+ -Wunused-local-binds++library+ import: warnings+ exposed-modules:+ DataFrame.TH.CSV+ DataFrame.Typed.TH.CSV+ build-depends: base >= 4 && < 5,+ dataframe-core ^>= 1.0,+ dataframe-csv ^>= 1.0,+ dataframe-th ^>= 1.0,+ template-haskell >= 2.0 && < 3+ hs-source-dirs: src+ default-language: Haskell2010
+ src/DataFrame/TH/CSV.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE FlexibleContexts #-}++{- |+Module : DataFrame.TH.CSV+License : MIT++CSV-file-based 'DataFrame.TH' splices. Splits out the CSV ingest path so+@dataframe-th@ stays IO-agnostic.+-}+module DataFrame.TH.CSV (+ declareColumnsFromCsvFile,+ declareColumnsFromCsvWithOpts,+) where++import Control.Monad.IO.Class (liftIO)+import Language.Haskell.TH++import qualified DataFrame.IO.CSV as CSV+import DataFrame.TH.Records (declareColumns)++{- | Splice a binding for every column of the 'DataFrame' read from a CSV+file. Each binding has type @Expr T@ where @T@ is the inferred column+type.+-}+declareColumnsFromCsvFile :: String -> DecsQ+declareColumnsFromCsvFile path = do+ df <-+ liftIO+ ( CSV.readSeparated+ (CSV.defaultReadOptions{CSV.numColumns = Just 100})+ path+ )+ declareColumns df++-- | Like 'declareColumnsFromCsvFile' but with custom 'CSV.ReadOptions'.+declareColumnsFromCsvWithOpts :: CSV.ReadOptions -> String -> DecsQ+declareColumnsFromCsvWithOpts opts path = do+ df <- liftIO (CSV.readSeparated opts path)+ declareColumns df
+ src/DataFrame/Typed/TH/CSV.hs view
@@ -0,0 +1,25 @@+{- |+Module : DataFrame.Typed.TH.CSV+License : MIT++CSV-file-based typed-schema derivation. Splits the CSV path out of+@DataFrame.Typed.TH@ so it can live in @dataframe-csv-th@.+-}+module DataFrame.Typed.TH.CSV (+ deriveSchemaFromCsvFile,+ deriveSchemaFromCsvFileWith,+) where++import Control.Monad.IO.Class (liftIO)+import Language.Haskell.TH++import qualified DataFrame.IO.CSV as D+import DataFrame.Typed.TH.Records (deriveSchema)++deriveSchemaFromCsvFile :: String -> String -> DecsQ+deriveSchemaFromCsvFile = deriveSchemaFromCsvFileWith D.defaultReadOptions++deriveSchemaFromCsvFileWith :: D.ReadOptions -> String -> String -> DecsQ+deriveSchemaFromCsvFileWith opts typeName path = do+ df <- liftIO (D.readSeparated opts path)+ deriveSchema typeName df