| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
DataFrame.Internal.Column
Synopsis
- type Bitmap = Vector Word8
- data Column where
- BoxedColumn :: forall a. Columnable a => Maybe Bitmap -> Vector a -> Column
- UnboxedColumn :: forall a. (Columnable a, Unbox a) => Maybe Bitmap -> Vector a -> Column
- PackedText :: Maybe Bitmap -> !PackedTextData -> Column
- data MutableColumn where
- MBoxedColumn :: forall a. Columnable a => IOVector a -> MutableColumn
- MUnboxedColumn :: forall a. (Columnable a, Unbox a) => IOVector a -> MutableColumn
- bitmapTestBit :: Bitmap -> Int -> Bool
- allValidBitmap :: Int -> Bitmap
- buildBitmapFromValid :: Vector Word8 -> Bitmap
- buildBitmapFromNulls :: Int -> [Int] -> Bitmap
- bitmapSlice :: Int -> Int -> Bitmap -> Bitmap
- bitmapConcat :: Int -> Bitmap -> Int -> Bitmap -> Bitmap
- mergeBitmaps :: Bitmap -> Bitmap -> Bitmap
- fromMaybeVec :: Columnable a => Vector (Maybe a) -> Column
- fromMaybeVecUnboxed :: (Columnable a, Unbox a) => Vector (Maybe a) -> Column
- columnElemIsNull :: Column -> Int -> Bool
- columnBitmap :: Column -> Maybe Bitmap
- materializePacked :: Column -> Column
- isPackedText :: Column -> Bool
- data TypedColumn a where
- TColumn :: forall a. Columnable a => Column -> TypedColumn a
- unwrapTypedColumn :: TypedColumn a -> Column
- vectorFromTypedColumn :: TypedColumn a -> Vector a
- hasMissing :: Column -> Bool
- allMissing :: Column -> Bool
- isNumeric :: Column -> Bool
- hasElemType :: Columnable a => Column -> Bool
- columnVersionString :: Column -> String
- columnTypeString :: Column -> String
- forceColumn :: Column -> ()
- eqBoxedCols :: Eq a => Maybe Bitmap -> Vector a -> Maybe Bitmap -> Vector a -> Bool
- eqPackedCols :: Maybe Bitmap -> PackedTextData -> Maybe Bitmap -> PackedTextData -> Bool
- class ColumnifyRep (r :: Rep) a where
- toColumnRep :: Vector a -> Column
- 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))
- fromVector :: (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column
- fromUnboxedVector :: (Columnable a, Unbox a) => Vector a -> Column
- fromList :: (Columnable a, ColumnifyRep (KindOf a) a) => [a] -> Column
- mkRandom :: (RandomGen g, Columnable a, ColumnifyRep (KindOf a) a, UniformRange a) => g -> Int -> a -> a -> Column
- throwTypeMismatch :: (Typeable a, Typeable b) => Either DataFrameException Column
- mapColumn :: (Columnable b, Columnable c) => (b -> c) -> Column -> Either DataFrameException Column
- imapColumn :: (Columnable b, Columnable c) => (Int -> b -> c) -> Column -> Either DataFrameException Column
- columnLength :: Column -> Int
- numElements :: Column -> Int
- takeColumn :: Int -> Column -> Column
- takeLastColumn :: Int -> Column -> Column
- sliceColumn :: Int -> Int -> Column -> Column
- atIndicesStable :: Vector Int -> Column -> Column
- gatherWithSentinel :: Vector Int -> Column -> Column
- getIndices :: Vector Int -> Vector a -> Vector a
- getIndicesUnboxed :: Unbox a => Vector Int -> Vector a -> Vector a
- findIndices :: Columnable a => (a -> Bool) -> Column -> Either DataFrameException (Vector Int)
- ifoldrColumn :: (Columnable a, Columnable b) => (Int -> a -> b -> b) -> b -> Column -> Either DataFrameException b
- foldlColumn :: (Columnable a, Columnable b) => (b -> a -> b) -> b -> Column -> Either DataFrameException b
- foldl1Column :: Columnable a => (a -> a -> a) -> Column -> Either DataFrameException a
- foldl1DirectGroups :: Columnable a => (a -> a -> a) -> Column -> Vector Int -> Vector Int -> Either DataFrameException Column
- foldLinearGroups :: (Columnable b, Columnable acc) => (acc -> b -> acc) -> acc -> Column -> Vector Int -> Int -> Either DataFrameException Column
- headColumn :: Columnable a => Column -> Either DataFrameException a
- zipColumns :: Column -> Column -> Column
- mergeColumns :: Column -> Column -> Column
- zipWithColumns :: (Columnable a, Columnable b, Columnable c) => (a -> b -> c) -> Column -> Column -> Either DataFrameException Column
- zipWithColumnsGeneral :: (Columnable a, Columnable b, Columnable c) => (a -> b -> c) -> Column -> Column -> Either DataFrameException Column
- freezeColumnEither :: [(Int, Text)] -> MutableColumn -> IO Column
- ensureOptional :: Column -> Column
- expandColumn :: Int -> Column -> Column
- leftExpandColumn :: Int -> Column -> Column
- concatColumns :: Column -> Column -> Either DataFrameException Column
- concatManyColumns :: [Column] -> Column
- concatColumnsEither :: Column -> Column -> Column
- newMutableColumn :: Int -> Column -> IO MutableColumn
- copyIntoMutableColumn :: MutableColumn -> Int -> Column -> IO ()
- freezeMutableColumn :: MutableColumn -> IO Column
- toList :: Columnable a => Column -> [a]
- toVector :: forall a v. (Vector v a, Columnable a) => Column -> Either DataFrameException (v a)
- toDoubleVector :: Column -> Either DataFrameException (Vector Double)
- toFloatVector :: Column -> Either DataFrameException (Vector Float)
- toIntVector :: Column -> Either DataFrameException (Vector Int)
- toUnboxedVector :: (Columnable a, Unbox a) => Column -> Either DataFrameException (Vector a)
- finalizeParseResult :: Unbox a => STVector s a -> STVector s Word8 -> Bool -> ST s (Maybe (Maybe Bitmap, Vector a))
Documentation
type Bitmap = Vector Word8 Source #
A bit-packed validity bitmap. Bit i = 1 means row i is valid (not null).
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).
Constructors
| BoxedColumn :: forall a. Columnable a => Maybe Bitmap -> Vector a -> Column | |
| UnboxedColumn :: forall a. (Columnable a, Unbox a) => Maybe Bitmap -> Vector a -> Column | |
| PackedText :: Maybe Bitmap -> !PackedTextData -> Column |
Instances
data MutableColumn where Source #
A mutable companion struct to dataframe columns.
Used mostly as an intermediate structure for I/O.
Constructors
| MBoxedColumn :: forall a. Columnable a => IOVector a -> MutableColumn | |
| MUnboxedColumn :: forall a. (Columnable a, Unbox a) => IOVector a -> MutableColumn |
allValidBitmap :: Int -> Bitmap Source #
Build a fully-valid bitmap for n rows (all bits set).
buildBitmapFromValid :: Vector Word8 -> Bitmap Source #
Build a bitmap from a VU.Vector Word8 validity vector
(1 = valid, 0 = null), as produced by Arrow / Parquet decoders.
buildBitmapFromNulls :: Int -> [Int] -> Bitmap Source #
Build a bitmap from a list of null-row indices.
nullIdxs are the positions that are NULL.
bitmapSlice :: Int -> Int -> Bitmap -> Bitmap Source #
Slice a bitmap for rows [start .. start+len-1].
bitmapConcat :: Int -> Bitmap -> Int -> Bitmap -> Bitmap Source #
Concatenate two bitmaps covering n1 and n2 rows respectively.
mergeBitmaps :: Bitmap -> Bitmap -> Bitmap Source #
Combine two bitmaps with AND (both must be valid for result to be valid).
fromMaybeVec :: Columnable a => Vector (Maybe a) -> Column Source #
Materialize a nullable column from VB.Vector (Maybe a); picks UnboxedColumn
when a is unboxable, else BoxedColumn. Always attaches a bitmap so the column
reads as nullable even with no Nothing values.
fromMaybeVecUnboxed :: (Columnable a, Unbox a) => Vector (Maybe a) -> Column Source #
Materialize a nullable UnboxedColumn to VB.Vector (Maybe a) using runST.
Always attaches a bitmap so the column is recognized as nullable even when
no Nothing values are present (preserves the Maybe type marker).
materializePacked :: Column -> Column Source #
Decode a PackedText into a BoxedColumn Text (bit-identical to
materializing at freeze). Identity on every other column.
isPackedText :: Column -> Bool Source #
Whether a column is a PackedText.
data TypedColumn a where Source #
A wrapper around the type-erased Column carrying a phantom element type,
used to type-check expressions. The phantom is not guaranteed to match the
underlying vector's type.
Constructors
| TColumn :: forall a. Columnable a => Column -> TypedColumn a |
Instances
| Show a => Show (TypedColumn a) Source # | |
Defined in DataFrame.Internal.Column Methods showsPrec :: Int -> TypedColumn a -> ShowS # show :: TypedColumn a -> String # showList :: [TypedColumn a] -> ShowS # | |
| Eq a => Eq (TypedColumn a) Source # | |
Defined in DataFrame.Internal.Column Methods (==) :: TypedColumn a -> TypedColumn a -> Bool # (/=) :: TypedColumn a -> TypedColumn a -> Bool # | |
unwrapTypedColumn :: TypedColumn a -> Column Source #
Gets the underlying value from a TypedColumn.
vectorFromTypedColumn :: TypedColumn a -> Vector a Source #
Gets the underlying vector from a TypedColumn.
hasMissing :: Column -> Bool Source #
Checks if a column contains missing values (has a bitmap).
allMissing :: Column -> Bool Source #
Checks if a column contains only missing values.
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.
columnVersionString :: Column -> String Source #
An internal/debugging function to get the column type of a column.
columnTypeString :: Column -> String Source #
An internal/debugging function to get the type stored in the outermost vector of a column.
forceColumn :: Column -> () Source #
Force evaluation of all elements in a column. Replacement for the removed
instance NFData Column; used by the IO and lazy-executor strict paths.
eqBoxedCols :: Eq a => Maybe Bitmap -> Vector a -> Maybe Bitmap -> Vector a -> Bool Source #
Compare two nullable boxed columns element by element, skipping null slots. Uses a manual loop to avoid stream fusion forcing null-slot error thunks.
eqPackedCols :: Maybe Bitmap -> PackedTextData -> Maybe Bitmap -> PackedTextData -> Bool Source #
Byte-slice equality of two packed-text columns, skipping null slots
(a null compares equal only to a null), mirroring eqBoxedCols.
class ColumnifyRep (r :: Rep) a where Source #
A class for converting a vector to a column of the appropriate type.
Given each Rep we tell the toColumnRep function which Column type to pick.
Methods
toColumnRep :: Vector a -> Column Source #
Instances
| Columnable a => ColumnifyRep 'RBoxed a Source # | |
Defined in DataFrame.Internal.Column Methods toColumnRep :: Vector a -> Column Source # | |
| (Columnable a, Unbox a) => ColumnifyRep 'RUnboxed a Source # | |
Defined in DataFrame.Internal.Column Methods toColumnRep :: Vector a -> Column Source # | |
| Columnable a => ColumnifyRep 'RNullableBoxed (Maybe a) Source # | |
Defined in DataFrame.Internal.Column Methods toColumnRep :: Vector (Maybe a) -> Column Source # | |
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.
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]
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]
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]
throwTypeMismatch :: (Typeable a, Typeable b) => Either DataFrameException Column Source #
mapColumn :: (Columnable b, Columnable c) => (b -> c) -> Column -> Either DataFrameException Column Source #
An internal function to map a function over the values of a column.
imapColumn :: (Columnable b, Columnable c) => (Int -> b -> c) -> Column -> Either DataFrameException Column Source #
Applies a function that returns an unboxed result to an unboxed vector, storing the result in a column.
columnLength :: Column -> Int Source #
O(1) Gets the number of elements in the column.
numElements :: Column -> Int Source #
O(n) Gets the number of non-null elements in the column.
sliceColumn :: Int -> Int -> Column -> Column Source #
O(n) Takes n values after a given column index.
atIndicesStable :: Vector Int -> Column -> Column Source #
O(n) Selects the elements at a given set of indices. Does not change the order.
gatherWithSentinel :: Vector Int -> Column -> Column Source #
Like atIndicesStable but treats negative indices as null.
Keeps the index vector fully unboxed (no VB.Vector (Maybe Int)).
getIndices :: Vector Int -> Vector a -> Vector a Source #
Internal helper to get indices in a boxed vector.
getIndicesUnboxed :: Unbox a => Vector Int -> Vector a -> Vector a Source #
Internal helper to get indices in an unboxed vector.
findIndices :: Columnable a => (a -> Bool) -> Column -> Either DataFrameException (Vector Int) Source #
ifoldrColumn :: (Columnable a, Columnable b) => (Int -> a -> b -> b) -> b -> Column -> Either DataFrameException b Source #
Fold (right) column with index.
foldlColumn :: (Columnable a, Columnable b) => (b -> a -> b) -> b -> Column -> Either DataFrameException b Source #
foldl1Column :: Columnable a => (a -> a -> a) -> Column -> Either DataFrameException a Source #
foldl1DirectGroups :: Columnable a => (a -> a -> a) -> Column -> Vector Int -> Vector Int -> Either DataFrameException Column Source #
O(n) Seedless fold over groups using the first element of each group as seed.
Like foldDirectGroups but for the case where no initial accumulator is available.
foldLinearGroups :: (Columnable b, Columnable acc) => (acc -> b -> acc) -> acc -> Column -> Vector Int -> Int -> Either DataFrameException Column Source #
O(n) fold over groups by scanning the column linearly (rowToGroup[i] = group
of row i). Random writes hit the small per-group accumulator array; when acc is
unboxable that array is unboxed, avoiding pointer indirection.
headColumn :: Columnable a => Column -> Either DataFrameException a Source #
zipWithColumns :: (Columnable a, Columnable b, Columnable c) => (a -> b -> c) -> Column -> Column -> Either DataFrameException Column Source #
An internal, column version of zipWith.
zipWithColumnsGeneral :: (Columnable a, Columnable b, Columnable c) => (a -> b -> c) -> Column -> Column -> Either DataFrameException Column Source #
freezeColumnEither :: [(Int, Text)] -> MutableColumn -> IO Column Source #
Freeze a mutable column into an Either Text a column: every recorded
null position becomes Left rawText (preserving the original input), every
other position becomes Right v. Used by CSV readers under EitherRead mode.
ensureOptional :: Column -> Column Source #
Promote a non-nullable column to a nullable one (add an all-valid bitmap). No-op when already nullable.
expandColumn :: Int -> Column -> Column Source #
Fills the end of a column, up to n, with null rows. Does nothing if column has length >= n.
leftExpandColumn :: Int -> Column -> Column Source #
Fills the beginning of a column, up to n, with null rows. Does nothing if column has length >= n.
concatColumns :: Column -> Column -> Either DataFrameException Column Source #
Concatenates two columns. Returns Nothing if the columns are of different types.
concatManyColumns :: [Column] -> Column Source #
Like concatColumns but also combines columns of different types by wrapping
values in Either (e.g. [1,2] and ["a","b"] become
[Left 1, Left 2, Right "a", Right "b"]).
O(n) Concatenate a list of same-type columns in a single allocation.
All columns must have the same constructor and element type (as they will
within a single Parquet column). Calls error on mismatch.
newMutableColumn :: Int -> Column -> IO MutableColumn Source #
Allocate a mutable column of size n matching the constructor/type of the given column.
copyIntoMutableColumn :: MutableColumn -> Int -> Column -> IO () Source #
Copy a column chunk into a mutable column starting at offset off.
freezeMutableColumn :: MutableColumn -> IO Column Source #
Freeze a mutable column into an immutable column.
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)
toDoubleVector :: Column -> Either DataFrameException (Vector Double) Source #
Convert a column to an unboxed Double vector, coercing numeric types
(realToFrac for floats, fromIntegral for integrals; nulls become NaN).
Left TypeMismatchException when the column is not numeric.
toFloatVector :: Column -> Either DataFrameException (Vector Float) Source #
Convert a column to an unboxed Float vector, coercing numeric types (nulls
become NaN); Left TypeMismatchException when not numeric. Converting from
Double may lose precision.
toIntVector :: Column -> Either DataFrameException (Vector Int) Source #
Convert a column to an unboxed Int vector, coercing numeric types
(floats are rounded via banker's rounding); Left TypeMismatchException
when the column is not numeric. Does not support nullable columns.
toUnboxedVector :: (Columnable a, Unbox a) => Column -> Either DataFrameException (Vector a) Source #