Python Transformer (Python Scripting)
Synopsis
This operator wraps a custom Python script as an Altair AI Studio operator, allowing for advanced data transformations using Python code.Description
The Python Transformer operator enables you to define and execute custom Python scripts directly within your Altair AI Studio workflows. Depending on its configuration, you can edit the operator's declaration—including capabilities, parameter types, and input and output ports—and modify the Python script that defines its behavior.
If the operator is editable, the parameter panel provides a set of buttons at the top of the parameter list that allow you to:
Edit Operator Declaration: Customize the operator's name, parameters, input and output ports using a JSON-like structure.
Edit Python Script: Modify the Python code that the operator will execute.
Save as Template: Save your customized operator configuration for reuse in other workflows.
The operator's behavior is determined by the Python script you provide, giving you the flexibility to perform complex data transformations. Parameters defined in the operator declaration are exposed in the UI, enabling dynamic configuration without altering the script. Configurations can be saved as templates for easy reuse and sharing.
By default, if no custom operator declaration is provided, or if the operator is not set to be editable, it functions identically to the Execute Python operator, allowing you to run Python scripts without additional configuration.
Defining Operator Parameters and Ports
You can define the operator's parameters and ports by editing the declaration in JSON-like syntax. For example:
{ "name": "Custom Python Transformer", "parameters": [ { "name": "selector", "type": "attributes", "value": "input" }, { "name": "1st_parameter", "type": "string", "optional": true }, { "name": "2nd_parameter", "type": "integer", "value": 100 }, { "name": "3rd_parameter", "type": "category", "categories": [ "Category A", "Category B", "Category C", "Default Category" ], "value": "Default Category" }, { "name": "4th_parameter", "type": "boolean" }, { "name": "5th_parameter", "type": "real", "value": 3.1415 }, { "name": "6th_parameter", "type": "string", "optional": true } ], "inputs": [ { "name": "input", "type": "table" } ], "outputs": [ { "name": "out", "type": "table" } ] }
After defining the operator declaration, the parameters and ports will appear in the UI, allowing you to interactively set parameter values and connect data flows.
Input
- input (Data table)
The operator can have multiple inputs. An input must be either an example set, a file object, a connection object, or a Python object generated by an 'Execute Python' operator.
Output
- out (Data table)
The operator can have multiple outputs. An output can be either an example set, a file object, or a Python object generated by this operator.
Parameters
- operator
If enabled, this parameter allows you to edit the operator declaration (e.g., parameter types and ports) and the Python script used to perform data transformations.