ColumnArithmetic
Combine the selected columns into a new numeric column.
Applies addition, subtraction, multiplication, or division element-wise
to the columns selected in scope. Select two columns to operate
between them, or one column to operate between it and a fixed
constant (e.g. column * 2). The operands are taken from the
selection: with two columns the operation is
<first column> <op> <second column> in dataset order, which can be
reversed with swap_operands (relevant for subtract and
divide). Division by zero yields NaN instead of raising an
error.
The original columns are left untouched; the result is appended as a new
column named output_column_name, or, if not provided,
<column_a>_<operation>_<column_b> or <column_a>_<operation>_<constant>.
The output column is Integer when both operands are Integer (a
whole-number constant counts as Integer), the operation is
add, subtract, or multiply (all of which stay exact on
integers), and neither operand column has missing values (since a
missing value has no exact integer representation). divide always
produces a Float column, since integer division is not exact in
general, and any operation involving a Float operand, or an
operand column with missing values, also produces a Float column.
Parameters
- operation : string, default=
add - Arithmetic operation to apply between the selected columns (or between the single selected column and 'constant').
- constant, default=
None - Fixed number used as the second operand. Only used (and required) when a single column is selected.
- swap_operands : boolean, default=
False - When two columns are selected, swap the operand order. By default the operation is 'first column' OP 'second column' (in dataset order); enable this to compute 'second' OP 'first' instead. Only affects subtract and divide.
- output_column_name, default=
None - Name of the resulting column. If null, a name is generated from the operands and the operation.
Methods
fit(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'ColumnArithmetic'
ColumnArithmeticDerive the operands from scope and validate them.
Parameters
- x : DashAIDataset
- The scoped dataset, expected to contain one or two columns.
- y : DashAIDataset, optional
- Ignored. Defaults to None.
Returns
- ColumnArithmetic
- The fitted converter instance (self).
get_output_type(self, column_name: str = None) -> DashAI.back.types.dashai_data_type.DashAIDataType
ColumnArithmeticReturn the output type for the arithmetic result.
Parameters
- column_name : str, optional
- Not used; the result column always has the same type. Defaults to None.
Returns
- DashAIDataType
- An
Integertype backed bypyarrow.int64(), or aFloattype backed bypyarrow.float64().
transform(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'DashAIDataset'
ColumnArithmeticCompute the arithmetic result and append it as a new column.
Parameters
- x : DashAIDataset
- The dataset containing the operand column(s) derived during
fit. - y : DashAIDataset, optional
- Ignored. Defaults to None.
Returns
- DashAIDataset
- The original dataset with the arithmetic result appended as a new column, typed
IntegerorFloatdepending on the operands and the operation (see class docstring).
get_metadata(cls) -> 'Dict[str, Any]'
BaseConverterGet metadata for the converter, used by the DashAI frontend.
Parameters
- cls : type
- The converter class (injected automatically by Python for classmethods).
Returns
- Dict[str, Any]
- Dictionary containing display name, short description, image preview path, category, icon, color, and whether the converter is supervised.
get_schema(cls) -> dict
ConfigObjectGenerates the component related Json Schema.
Returns
- dict
- Dictionary representing the Json Schema of the component.
validate_and_transform(self, raw_data: dict) -> dict
ConfigObjectIt takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.
Parameters
- raw_data : dict
- A dictionary with the data provided by the user to initialize the model.
Returns
- dict
- A validated dictionary with the necessary objects.