| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
DataFrame.Core
Description
Synopsis
- data DataFrame
- data GroupedDataFrame
- empty :: DataFrame
- fromNamedColumns :: [(Text, Column)] -> DataFrame
- insertColumn :: Text -> Column -> DataFrame -> DataFrame
- columnNames :: DataFrame -> [Text]
- null :: DataFrame -> Bool
- data Column
- fromList :: (Columnable a, ColumnifyRep (KindOf a) a) => [a] -> Column
- fromVector :: (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column
- fromUnboxedVector :: (Columnable a, Unbox a) => Vector a -> Column
- mkRandom :: (RandomGen g, Columnable a, ColumnifyRep (KindOf a) a, UniformRange a) => g -> Int -> a -> a -> Column
- toList :: Columnable a => Column -> [a]
- toVector :: forall a v. (Vector v a, Columnable a) => Column -> Either DataFrameException (v a)
- hasElemType :: Columnable a => Column -> Bool
- hasMissing :: Column -> Bool
- isNumeric :: Column -> Bool
- type Columnable a = (Columnable' a, ColumnifyRep (KindOf a) a, UnboxIf a, IntegralIf a, FloatingIf a, SBoolI (Unboxable a), SBoolI (Numeric a), SBoolI (IntegralTypes a), SBoolI (FloatingTypes a))
- type Columnable' a = (Typeable a, Show a, Eq a)
- type Row = Vector Any
- data Any
- toAny :: Columnable a => a -> Any
- fromAny :: Columnable a => Any -> Maybe a
- rowValue :: Expr a -> [(Text, Any)] -> Maybe a
- toRowList :: DataFrame -> [[(Text, Any)]]
- toRowVector :: [Text] -> DataFrame -> Vector Row
- data Expr a
- type NamedExpr = (Text, UExpr)
- toNamedExpr :: Columnable a => Text -> Expr a -> NamedExpr
- toUExpr :: Columnable a => Expr a -> UExpr
- fromUExpr :: Columnable a => UExpr -> Maybe (Expr a)
- eSize :: Expr a -> Int
- prettyPrint :: Expr a -> String
- prettyPrintWidth :: Int -> Expr a -> String
- data TruncateConfig = TruncateConfig {
- maxRows :: Int
- maxColumns :: Int
- maxCellWidth :: Int
- defaultTruncateConfig :: TruncateConfig
- toCsv :: DataFrame -> Text
- toCsv' :: DataFrame -> String
- toSeparated :: Char -> DataFrame -> Text
- toMarkdown :: DataFrame -> Text
- toMarkdown' :: DataFrame -> String
The DataFrame
data GroupedDataFrame Source #
A record that contains information about how and what
rows are grouped in the dataframe. This can only be used with
aggregate.
Instances
| Show GroupedDataFrame Source # | |
Defined in DataFrame.Internal.DataFrame Methods showsPrec :: Int -> GroupedDataFrame -> ShowS # show :: GroupedDataFrame -> String # showList :: [GroupedDataFrame] -> ShowS # | |
| Eq GroupedDataFrame Source # | |
Defined in DataFrame.Internal.DataFrame Methods (==) :: GroupedDataFrame -> GroupedDataFrame -> Bool # (/=) :: GroupedDataFrame -> GroupedDataFrame -> Bool # | |
fromNamedColumns :: [(Text, Column)] -> DataFrame Source #
Build a DataFrame from a list of (name, column) pairs using insertColumn.
insertColumn :: Text -> Column -> DataFrame -> DataFrame Source #
Insert a column into a DataFrame. If a column with the same name already exists it is replaced in-place; otherwise the column is appended at the end. Other columns are expanded (padded with nulls) to match the new row count.
columnNames :: DataFrame -> [Text] Source #
O(k) Get column names of the DataFrame in order of insertion.
Columns
Type-erased column GADT. Pattern-matching on the constructor recovers the
representation; nullability is an optional bit-packed Bitmap (Nothing = no
nulls, Just bm = bit i set iff row i is valid).
Instances
fromList :: (Columnable a, ColumnifyRep (KindOf a) a) => [a] -> Column Source #
O(n) Convert a list to a column. Automatically picks the best representation of a vector to store the underlying data in.
Examples:
> fromList [(1 :: Int), 2, 3, 4] [1,2,3,4]
fromVector :: (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column Source #
O(n) Convert a vector to a column. Automatically picks the best representation of a vector to store the underlying data in.
Examples:
> import qualified Data.Vector as V > fromVector (VB.fromList [(1 :: Int), 2, 3, 4]) [1,2,3,4]
fromUnboxedVector :: (Columnable a, Unbox a) => Vector a -> Column Source #
O(n) Convert an unboxed vector to a column. This avoids the extra conversion if you already have the data in an unboxed vector.
Examples:
> import qualified Data.Vector.Unboxed as V > fromUnboxedVector (VB.fromList [(1 :: Int), 2, 3, 4]) [1,2,3,4]
mkRandom :: (RandomGen g, Columnable a, ColumnifyRep (KindOf a) a, UniformRange a) => g -> Int -> a -> a -> Column Source #
O(n) Create a column of random elements within a range.
Takes a random number generator, a length, and a lower and upper bound for the random values.
Examples:
> import System.Random (mkStdGen) > mkRandom (mkStdGen 42) 4 0 10 [4,2,6,5]
toList :: Columnable a => Column -> [a] Source #
O(n) Converts a column to a list. Throws an exception if the wrong type is specified.
Examples:
> column = fromList [(1 :: Int), 2, 3, 4]
> toList Int column
[1,2,3,4]
> toList Double column
exception: ...
toVector :: forall a v. (Vector v a, Columnable a) => Column -> Either DataFrameException (v a) Source #
Type-safe conversion of a column to a vector of element type a (specify via
type application); Left TypeMismatchException when the column's type differs.
>>>toVector @Int @VU.Vector columnRight (unboxed vector of Ints)
>>>toVector @Text @VB.Vector columnRight (boxed vector of Text)
hasElemType :: Columnable a => Column -> Bool Source #
Whether the column stores element type a. For nullable columns, also
True when a = Maybe b and the column stores b internally.
hasMissing :: Column -> Bool Source #
Checks if a column contains missing values (has a bitmap).
Element constraints
type Columnable a = (Columnable' a, ColumnifyRep (KindOf a) a, UnboxIf a, IntegralIf a, FloatingIf a, SBoolI (Unboxable a), SBoolI (Numeric a), SBoolI (IntegralTypes a), SBoolI (FloatingTypes a)) Source #
Constraint synonym for what we can put into columns.
Rows
toAny :: Columnable a => a -> Any Source #
Wraps a value into an Any type. This helps up represent rows as heterogenous lists.
rowValue :: Expr a -> [(Text, Any)] -> Maybe a Source #
Given a row gets the value associated with a field.
Examples
>>>map (rowValue (F.col @Int "age")) (toRowList df)[25,30, ...]
toRowList :: DataFrame -> [[(Text, Any)]] Source #
Convert the whole dataframe to a list of rows, one per row index in natural
order; each row lists all columns ordered by column index. Materializes every
row, so prefer toRowVector for large frames.
>>>toRowList df[[("name", "Alice"), ("age", 25), ...], [("name", "Bob"), ("age", 30), ...], ...]
toRowVector :: [Text] -> DataFrame -> Vector Row Source #
Convert the dataframe to a vector of rows containing only the named columns, in the given order. An empty name list yields one empty row per dataframe row.
>>>toRowVector ["name", "age"] dfVector of rows with only name and age fields
Expressions
Instances
| ToTExpr cols (Expr r) Source # | |
| (IsString a, Columnable a) => IsString (Expr a) Source # | |
Defined in DataFrame.Internal.Expression Methods fromString :: String -> Expr a # | |
| (Floating a, Columnable a) => Floating (Expr a) Source # | |
| (Num a, Columnable a) => Num (Expr a) Source # | |
| (Fractional a, Columnable a) => Fractional (Expr a) Source # | |
| Show a => Show (Expr a) Source # | |
toNamedExpr :: Columnable a => Text -> Expr a -> NamedExpr Source #
prettyPrint :: Expr a -> String Source #
Render an expression as readable, width-aware pseudo-code at the default
width (defaultWidth). See prettyPrintWidth to control wrapping.
prettyPrintWidth :: Int -> Expr a -> String Source #
Render an expression as readable, width-aware pseudo-code: long binary chains
wrap onto aligned continuation lines, ifthenelse break onto their own lines
(nested else if form a flat ladder), and sub-exprs are parenthesized by precedence.
Rendering & serialization
data TruncateConfig Source #
Configures how a DataFrame is rendered as text: maxRows caps rendered
rows, maxColumns collapses middle columns past the limit into an ellipsis, and
maxCellWidth truncates long cells. A non-positive field means "no limit".
Constructors
| TruncateConfig | |
Fields
| |
Instances
| Show TruncateConfig Source # | |
Defined in DataFrame.Internal.DataFrame Methods showsPrec :: Int -> TruncateConfig -> ShowS # show :: TruncateConfig -> String # showList :: [TruncateConfig] -> ShowS # | |
| Eq TruncateConfig Source # | |
Defined in DataFrame.Internal.DataFrame Methods (==) :: TruncateConfig -> TruncateConfig -> Bool # (/=) :: TruncateConfig -> TruncateConfig -> Bool # | |
defaultTruncateConfig :: TruncateConfig Source #
Sensible defaults for GHCi: 20 rows, 10 columns, 30 characters per cell.
toSeparated :: Char -> DataFrame -> Text Source #
Convert a DataFrame to a text representation with a custom separator.
toMarkdown :: DataFrame -> Text Source #
For showing the dataframe as markdown in notebooks.
toMarkdown' :: DataFrame -> String Source #
For showing the dataframe as a string markdown in notebooks.