Action

The Action class defines the restructuring actions performed in a Method. BaseAction is the main definition for an action and is inherited by child classes in the /action folder.

class core.BaseAction

Custom Actions inherit from this base class which describes the core functions and methodology for an Action.

Actions should redefine name, title, description, modifiers and structure, as well as produce a transform function. Everything else will probably remain as defined, but particularly complex Actions should modify as required.

modifiers

Describes the modifiers for the Action. Typical modifiers are + or - but the Action can implement any type of modifier as part of the transform function.

As an example:

[
    {
        "name": "+",
        "title": "Add",
        "type": "modifier"
    },
    {
        "name": "-",
        "title": "Subtract",
        "type": "modifier"
    }
]
Returns:Dict representation of the modifiers.
Return type:None or dict
validates(structure, working_columns=[])

Traverses a list defined by *structure, ensuring that the terms conform to that action’s default structural requirements. Nested structures are permitted. Note that the responsibility for digging in to the nested structures lies with the calling function.

The format for defining a structure is as follows:

[action, column_name, [action, column_name]]

e.g.:

["CATEGORISE", "+", ["ORDER", "column_1", "column_2"]]

A calling function would specify:

Action.validates(structure[1:], working_columns)
Parameters:
  • structure (list) – Each structure list must conform to the requirements for that action. Nested actions defined by nested lists.
  • working_columns (list) – List of valid field names from the working data columns.
Returns:

True if valid

Return type:

bool

settings

Returns the dict representation of the Action.

Returns:Dict representation of an Action.
Return type:dict
transform(df, field_name, structure, **kwargs)

Perform a transformation. This function must be overridden by child Actions and describe a unique new method.

Warning

Assumes validates has been run.

Parameters:
  • df (DataFrame) – Working data to be transformed
  • field_name (str) – Name of the target schema field
  • structure (list) – List of fields with restructuring action defined by term 0 (i.e. this action)
  • **kwargs – Other fields which may be required in custom transforms
Returns:

Containing the implementation of the Action

Return type:

Dataframe