| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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
- data SomeExpr where
- SomeExpr :: forall a. Columnable a => TypeRep a -> Expr a -> SomeExpr
- encodeExpr :: Columnable a => Expr a -> Either String Value
- encodeExprToBytes :: Columnable a => Expr a -> Either String ByteString
- decodeExprAny :: Value -> Either String SomeExpr
- decodeExprAt :: Columnable a => Value -> Either String (Expr a)
- parseSomeExpr :: Value -> Parser SomeExpr
- typeTagOf :: Typeable a => Maybe Text
- withTypeTag :: Text -> (forall a. Columnable a => Proxy a -> Parser r) -> Parser r
- withOrdTypeTag :: Text -> (forall a. (Columnable a, Ord a) => Proxy a -> Parser r) -> Parser r
- withNumTypeTag :: Text -> (forall a. (Columnable a, Num a) => Proxy a -> Parser r) -> Parser r
- withFracTypeTag :: Text -> (forall a. (Columnable a, Fractional a) => Proxy a -> Parser r) -> Parser r
- withRealTypeTag :: Text -> (forall a. (Columnable a, Real a) => Proxy a -> Parser r) -> Parser r
- withRealUnboxTypeTag :: Text -> (forall a. (Columnable a, Real a, Unbox a) => Proxy a -> Parser r) -> Parser r
Documentation
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 #
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.
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).