credmark.cmf.types.compose.MapInputsOutput

DTO class MapInputsOutput(*, results=[])[source]

Bases: IterableListGenericDTO[MapInputsResult], Generic[INPUTDTOCLS, DTOCLS]

A DTO for the output of “compose.map-inputs” model which runs another model over a list of inputs.

The generic types specify the classes to use as the input and output in the MapInputsResult.

For example map_result = MapInputsOutput[MyInputClass, MyOutputClass](**data) where map_result.results[0].input will be an instance of MyInputClass where map_result.result[0].output will be an instance of MyOutputClass

If a permanent error occurs during a model run, the block with error will be added to the series array. If a non-permanent error occurs during a model run, the entire series will generate an error.

The output can be converted to list (to_list) or Panda’s DataFrame (to_dataframe()) with customized lambdas to extract certain field(s) of the output into values (in a list) or columns (in a dataframe).

Show JSON schema
{
   "title": "MapInputsOutput",
   "description": "A DTO for the output of \"compose.map-inputs\" model which runs another\nmodel over a list of inputs.\n\nThe generic types specify the classes to use as the input and output\nin the ``MapInputsResult``.\n\nFor example ``map_result = MapInputsOutput[MyInputClass, MyOutputClass](**data)``\nwhere ``map_result.results[0].input`` will be an instance of ``MyInputClass``\nwhere ``map_result.result[0].output`` will be an instance of ``MyOutputClass``\n\nIf a permanent error occurs during a model run, the block with error\nwill be added to the series array.\nIf a non-permanent error occurs during a model run, the entire series\nwill generate an error.\n\nThe output can be converted to list (to_list) or Panda's DataFrame (to_dataframe())\nwith customized lambdas to extract certain field(s) of the output into\nvalues (in a list) or columns (in a dataframe).",
   "type": "object",
   "properties": {
      "results": {
         "title": "Results",
         "description": "List of model run results",
         "default": [],
         "type": "array",
         "items": {
            "$ref": "#/definitions/MapInputsResult"
         }
      }
   },
   "examples": [
      {
         "results": {
            "input": {
               "address": "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72"
            },
            "output": {
               "result": 42
            },
            "error": null
         }
      }
   ],
   "definitions": {
      "ModelCallStackEntry": {
         "title": "ModelCallStackEntry",
         "description": "An item in an error's call stack.",
         "type": "object",
         "properties": {
            "slug": {
               "title": "Slug",
               "description": "Model slug",
               "type": "string"
            },
            "version": {
               "title": "Version",
               "description": "Model version",
               "type": "string"
            },
            "chainId": {
               "title": "Chainid",
               "description": "Context chain id",
               "type": "integer"
            },
            "blockNumber": {
               "title": "Blocknumber",
               "description": "Context block number",
               "type": "integer"
            },
            "input": {
               "title": "Input",
               "description": "Context input"
            },
            "trace": {
               "title": "Trace",
               "description": "Trace of code that generated the error",
               "type": "string"
            }
         },
         "required": [
            "slug",
            "version"
         ]
      },
      "ModelErrorDTO": {
         "title": "ModelErrorDTO",
         "description": "Data fields common to all error types:\nModelDataError, ModelRunError, ModelInputError etc.",
         "type": "object",
         "properties": {
            "type": {
               "title": "Type",
               "description": "Error type",
               "type": "string"
            },
            "message": {
               "title": "Message",
               "description": "Error message",
               "type": "string"
            },
            "stack": {
               "title": "Stack",
               "description": "Model call stack. Last element is the model that raised the error.",
               "default": [],
               "type": "array",
               "items": {
                  "$ref": "#/definitions/ModelCallStackEntry"
               }
            },
            "code": {
               "title": "Code",
               "description": "Short identifier for the type of error",
               "default": "generic",
               "type": "string"
            },
            "detail": {
               "title": "Detail",
               "description": "Arbitrary data object related to the error."
            },
            "permanent": {
               "title": "Permanent",
               "description": "If true, the error will always give the same result for the same context.",
               "default": false,
               "type": "boolean"
            }
         },
         "required": [
            "type",
            "message"
         ]
      },
      "MapInputsResult": {
         "title": "MapInputsResult",
         "description": "A data row in an input series.\nThe generic type specifies the classes to use as the input and output.\n\nFor example ``row = MapInputResult[MyInputClass, MyOutputClass](**data)``\nwhere ``row.input`` will be an instance of ``MyInputClass``\nand ``row.output`` will be an instance of ``MyOutputClass``",
         "type": "object",
         "properties": {
            "input": {
               "title": "Input",
               "description": "Input used for the run.",
               "anyOf": [
                  {},
                  {
                     "type": "object"
                  }
               ]
            },
            "output": {
               "title": "Output",
               "description": "Model output of result. Will not be present if there is an error."
            },
            "error": {
               "title": "Error",
               "description": "Error DTO from model run. Will not be present if output exists.",
               "allOf": [
                  {
                     "$ref": "#/definitions/ModelErrorDTO"
                  }
               ]
            }
         },
         "required": [
            "input"
         ],
         "examples": [
            {
               "input": {
                  "address": "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72"
               },
               "output": {
                  "result": 42
               },
               "error": null
            }
         ]
      }
   }
}

Config
  • schema_extra: dict = {‘examples’: [{‘results’: {‘input’: {‘address’: ‘0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72’}, ‘output’: {‘result’: 42}, ‘error’: None}}]}

Fields
Parameters

results (List[MapInputsResult]) –

Return type

None

field results: List[MapInputsResult] = []

List of model run results

append(obj)
extend(obj)
to_dataframe(fields=None)[source]
Parameters

fields (List[Tuple[str, Callable]] | None) – List of field name and lambda to extract certain field from output. Leave empty to extract the entire output.

Return type

DataFrame

Extract tuples from results data

to_list(fields=None)[source]
Parameters

fields (List[Callable] | None) – List of lambda to extract certain field from output. Leave empty to extract the entire output.

Return type

List[List]

Extract tuples from results data