graviti.portex.template
#
Template base class.
Module Contents#
Classes#
The base class of Portex external type. |
Functions#
|
Generate a Portex external type according to the input template. |
Attributes#
- class graviti.portex.template.PortexExternalType(*args, **kwargs)[source]#
Bases:
graviti.portex.base.PortexType
The base class of Portex external type.
- property internal_type(self)[source]#
Get the internal type of the PortexExternalType.
- Returns
The internal type of the PortexExternalType.
- Return type
- to_pyarrow(self)[source]#
Convert the Portex type to the corresponding builtin PyArrow DataType.
- Returns
The corresponding builtin PyArrow DataType.
- Return type
pyarrow.DataType
- graviti.portex.template.template(name, content, package=packages.locals)[source]#
Generate a Portex external type according to the input template.
- Parameters
name (str) – The class name of the Portex external type.
content (Dict[str, Any]) – A dict indicates a Portex template.
package (graviti.portex.package.Package[Any]) – The package this template belongs to.
- Returns
A subclass of
PortexExternalType
.- Return type
Type[PortexExternalType]
Examples
>>> import graviti.portex as pt >>> from graviti.portex.template import template >>> >>> vector_template = { ... "type": "template", ... "parameters": [ ... { ... "name": "coords", ... "default": {"type": "int32"}, ... }, ... { ... "name": "labels", ... "default": None, ... }, ... ], ... "declaration": { ... "type": "record", ... "fields": [ ... { ... "name": "x", ... "+": "$coords", ... }, ... { ... "name": "y", ... "+": "$coords", ... }, ... { ... "name": "label", ... "exist_if": "$labels", ... "type": "enum", ... "values": "$labels", ... }, ... ], ... }, ... } >>> Vector = template("Vector", vector_template) >>> vector2d_int = Vector() >>> vector2d_int Vector() >>> vector2d_int.internal_type record( fields={ 'x': int32(), 'y': int32(), }, ) >>> >>> vector2d_float = Vector(pt.float32()) >>> vector2d_float Vector( coords=float32(), ) >>> vector2d_float.internal_type record( fields={ 'x': float32(), 'y': float32(), }, ) >>> >>> labeled_vector = Vector(labels=["visble", "occluded"]) >>> labeled_vector Vector( labels=['visble', 'occluded'], ) >>> labeled_vector.internal_type record( fields={ 'x': int32(), 'y': int32(), 'label': enum( values=['visble', 'occluded'], ), }, )