Saltar al contenido principal

TypeCast

Converter
DashAI.back.converters.simple_converters.TypeCast

Change the DashAI type of the columns selected in scope.

Casts every column in scope to new_type (one of "Integer", "Float", "Text", or "Categorical"), reusing the exact same validation and conversion rules used when changing column types from the dataset upload preview screen (see DashAI.back.types.type_validation.validate_type_change, also used by the /datasets/validate_type_changes endpoint). This keeps behaviour consistent between the upload preview and pipeline-time type changes.

Columns already of new_type are left untouched. If a column's values cannot be safely converted (e.g. a Text column with non-numeric values targeting Integer, or a Float column with decimal values targeting Integer), the behaviour is controlled by on_error: "raise" (default) stops with a descriptive, column-specific error message, while "skip" leaves that column unchanged, prints a warning, and continues with the rest.

Parameters

new_type : string, default=Text
Target type to cast the columns in scope to.
on_error : string, default=raise
What to do when a column cannot be safely converted: 'raise' to stop with a descriptive error, or 'skip' to leave that column unchanged and continue with the rest.

Methods

fit(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'TypeCast'

Defined on TypeCast

Validate that every column in scope can be cast to new_type.

Parameters

x : DashAIDataset
The scoped dataset whose columns will be cast.
y : DashAIDataset, optional
Ignored. Defaults to None.

Returns

TypeCast
The fitted converter instance (self).

get_output_type(self, column_name: str = None) -> DashAI.back.types.dashai_data_type.DashAIDataType

Defined on TypeCast

Return the output type produced for any column cast by this converter.

Parameters

column_name : str, optional
Not used; every cast column has the same output type. Defaults to None.

Returns

DashAIDataType
An Integer, Float, Text, or Categorical type matching new_type. For Categorical, the categories are unknown until transform runs, so an empty placeholder is returned.

transform(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'DashAIDataset'

Defined on TypeCast

Cast the fitted columns to new_type.

Parameters

x : DashAIDataset
The dataset whose columns (matching those seen in fit) will be cast.
y : DashAIDataset, optional
Ignored. Defaults to None.

Returns

DashAIDataset
The dataset with the fitted columns cast to new_type. Columns that already had new_type, that had no known type, or that failed conversion under on_error="skip" are left unchanged.

get_metadata(cls) -> 'Dict[str, Any]'

Defined on BaseConverter

Get 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

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It 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.