histogrammar.util.UserFcn

class histogrammar.util.UserFcn(expr, name=None)[source]

Bases: object

Base trait for user functions.

All functions passed to Histogrammar primitives get wrapped as UserFcn objects. Functions (instances of types.FunctionType, not any callable) are used as-is and strings and deferred for later evaluation. If a string-based UserFcn is used in a normal fill operation, it gets compiled (once) as a Python function of the input structure’s fields or a single-argument function for unstructured data.

The string need not be interpreted this way: backends targeting JIT compilation can interpret the strings as C code; backends targeting GPUs and FPGAs can interpret them as CUDA/OpenCL or pin-out names. As usual with Histogrammar, the only platform-specific part is the user functions.

UserFcns have a name parameter that may not be set. The user would ordinarily use the histogrammar.util.named function to give a function a name. Similarly, histogrammar.util.cached adds caching. (Naming and caching commute: they can be applied in either order.)

UserFcns are also 100% serializable, so that Histogrammar trees can be pickled and they can be passed through PySpark.

Note that the histogrammar.util.serializable function creates a UserFcn, avoids duplication, and commutes with histogrammar.util.named and histogrammar.util.cached (they can be applied in any order).