Skip to main content

Execute Python

Synopsis

Executes a Python script in an environment created by the Coding Environments Manager (CEM).

Description

This operator executes a python script in a selected Coding Environments Manager (CEM) environment. (From now on: only CEM) The script can be defined in two separate ways. It is possible to attach a script file, stored in Data Catalogue, to the first script file port of the operator. In this case please set the Use Input Script File to true value. If the value of the previously mentioned parameter is false, then it is possible to define the python script as a parameter, in a code editor. This code editor is prefilled with an example script that gives extra information about the Operator.

The arguments of the script correspond to the input ports, where IOTables, data, are converted to Pandas DataFrames. Analogously, the values returned by the script are delivered at the output ports of the operator, where DataFrames are converted to IOTables.

The operator supports environments provisioned by the CEM component, they are conda environments and they must need to include pyarrow as a dependency as it is a needed package to be able to execute a python script.

The Python script to execute must define a method with name 'rm_main' with as many arguments as connected input ports or alternatively a *args argument to use a dynamic number of attributes. The return values of the method 'rm_main' are delivered to the connected output ports. If the method returns a tuple then the single entries of the tuple are delivered to the output ports. Entries from the data type 'pandas.DataFrames' are converted to IOTables.

Accessing macros: you can access and modify the macros defined in RapidMiner from the Python code. You can call a macro by adding an extra argument to the rm_main method, that will be a python dictionary and it is possible to reach a macro value by key from the dictionary.

The console output of Python is shown in the Log View (Controls -> Workloads -> Your Workload -> Logs).

Input

input

The Script operator can have multiple inputs. IOTable based data entry tables will be converted automatically to a Pandas Dataframe. All other input data files will be downloaded and their locations will be sent to the script as input arguments.

Output

output

The Script operator can have multiple outputs. If the script returns a Pandas DataFrame then it will be converted to an IOTable. If the script returns a python obect, it must be serializable using the python pickle module. The object will then be delivered as a binary object to the output port, which can then in turn send it as an input to a different python execute operator.

Parameters

Coding environment

Coding environment where the python script will be executed.

Use file input connector

If set, file via file port will be used during the execution. Default: not set, which means that the python code is visible and will be used during the execution.

Python code

Python code which is visible if the above parameter is not set.

See Also