dataframe-expr-serializer-1.2.0.1: Serialize and deserialize dataframe expressions and pipelines.
Safe HaskellNone
LanguageHaskell2010

DataFrame.IR.ExprJson

Description

JSON wire format for Expr values.

The Python bindings build expression trees as JSON; this module decodes them back into Expr GADTs (typed) and encodes them in the reverse direction (used for shipping fitted decision trees back to Python).

Encoded shape:

{ "node": "col"   , "out_type": "double", "name": "x" }
{ "node": "lit"   , "out_type": "int"   , "value": 42 }
{ "node": "unary" , "out_type": "double", "op": "toDouble"
                  , "arg_type": "int"   , "arg": <expr> }
{ "node": "binary", "out_type": "bool"  , "op": "leq"
                  , "arg_type": "double", "lhs": <expr>, "rhs": <expr> }
{ "node": "if"    , "out_type": "text"  , "cond": <expr>
                  , "then": <expr>, "else": <expr> }

Operator names follow binaryName / unaryName from DataFrame.Internal.Expression. Nullable variants ("nulladd", "nullor", …) are accepted on decode and treated as their non-null equivalents — Python data crosses the FFI boundary as non-null Arrow buffers, so this is lossless for the supported workflow.

Synopsis

Documentation

data SomeExpr where Source #

Existential wrapper around a typed expression decoded from JSON. TODO: mchavinda - Maybe consolidate with UExpr from the main package.

Constructors

SomeExpr :: forall a. Columnable a => TypeRep a -> Expr a -> SomeExpr 

encodeExpr :: Columnable a => Expr a -> Either String Value Source #

Encode an Expr to a JSON value. Returns Left on unsupported constructors (Agg, Over, CastWith, CastExprWith) or unsupported operator names (binaryUdf, unaryUdf, …).

encodeExprToBytes :: Columnable a => Expr a -> Either String ByteString Source #

Encode an Expr to a strict ByteString of JSON.

decodeExprAny :: Value -> Either String SomeExpr Source #

Decode a JSON value into a SomeExpr. The output type comes from the out_type field on the root node.

decodeExprAt :: Columnable a => Value -> Either String (Expr a) Source #

Decode a JSON value, asserting the result type matches a.

parseSomeExpr :: Value -> Parser SomeExpr Source #

The Aeson.Parser entry point — useful when composing with bigger parsers.

typeTagOf :: Typeable a => Maybe Text Source #

Map a Haskell type to its wire-format tag string.

withTypeTag :: Text -> (forall a. Columnable a => Proxy a -> Parser r) -> Parser r Source #

Dispatch on a type tag with a Columnable continuation.

withOrdTypeTag :: Text -> (forall a. (Columnable a, Ord a) => Proxy a -> Parser r) -> Parser r Source #

Subset that supports Ord (for comparison ops).

withNumTypeTag :: Text -> (forall a. (Columnable a, Num a) => Proxy a -> Parser r) -> Parser r Source #

Subset that supports Num (arithmetic).

withFracTypeTag :: Text -> (forall a. (Columnable a, Fractional a) => Proxy a -> Parser r) -> Parser r Source #

Subset that supports Fractional (division).

withRealTypeTag :: Text -> (forall a. (Columnable a, Real a) => Proxy a -> Parser r) -> Parser r Source #

Subset that supports Real (used by toDouble source types).

withRealUnboxTypeTag :: Text -> (forall a. (Columnable a, Real a, Unbox a) => Proxy a -> Parser r) -> Parser r Source #

Subset that supports both Real and Unbox (used by variance/median). Integer is deliberately omitted — it is Real but not Unbox.