The Morph class defines the restructuring actions performed on a single table in a Method. BaseMorph is the main definition for an action and is inherited by child classes in the /morph folder.

class core.BaseMorph

Custom Morphs inherit from this base class which describes the core functions and methodology for a Morph.

Morphs should redefine name, id, structure, and parameters, as well as produce a transform function. Everything else will probably remain as defined, but particularly complex Morphs should modify as required.

parameters can be an empty dict, but a morph may be defined by these parameters:

  • rows: the specific rows effected by the morph, a list of int
  • columns: the specific columns effected by the morph, a list of string

A morph defined as JSON is, e.g.:

    "name": "xxxxx",
    "parameters": {
        "rows": [1,2,3],
        "columns": ["column1"]

In markup, the user codes:

morph = ["MORPH_NAME", [rows], [columns]]

Where the presence and order of the lists is set by structure.


Returns the dict representation of the Morph.

Raises:NameError if parameters don’t yet exist.
Returns:Dict representation of a Morph.
Return type:dict
validates(df=Empty DataFrame Columns: [] Index: [], rows=None, columns=None, column_names=None)

Traverses a list defined by *structure, ensuring that the terms conform to that morph’s default structural requirements.

The format for defining a structure is as follows:

[morph, [rows], [columns], [column_names]]


["RENAME", ["column_1", "column_2"]]

A calling function would specify something like:

Morph.validates(df, **dict((zip(['rows','columns','column_names'], structure[1:])))
  • rows (int or list of int) –
  • columns (str or list of str) –
  • column_names (str or list of str) –
  • df (dataframe) – The source DataFrame.

True if valid

Return type:


transform(df=Empty DataFrame Columns: [] Index: [], **kwargs)

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


Assumes validates has been run.

  • df (DataFrame) – Working data to be transformed
  • **kwargs – Other fields which may be required in custom transforms

Containing the implementation of the Morph

Return type: