Record
toksearch.record.Record
Bases: object
A class to hold a record of data for a single shot
The Record class is a dictionary-like object that holds data for a single shot. It has a 'shot' field that is required to be an integer, and it has an 'errors' field that is a dictionary of errors that have occurred while processing the data.
Most of the time, you will not need to instantiate a Record object directly. Instead, the Pipeline class will create Record objects for you.
__contains__(key)
Check if a field is in the record
__delitem__(key)
Delete a field from the record
__getitem__(key)
Get a field from the record
__init__(shot)
Create a Record object with a shot number
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shot |
int
|
The shot number for this record |
required |
Raises:
Type | Description |
---|---|
InvalidShotNumber
|
If the shot number is not castable to an integer |
__len__()
Get the number of fields in the record
__repr__()
Get a string representation of the record
__setitem__(key, value)
Set a field in the record
discard(keys)
Remove all fields in keys from the record
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
List[Any]
|
A list of keys to remove from the record |
required |
from_dict(input_dict)
classmethod
Instantiate a Record object from a dictionary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
dict
|
Must contain the key 'shot', and must NOT contain the keys 'key' or 'errors' |
required |
Returns:
Name | Type | Description |
---|---|---|
Record |
Record
|
A Record object with the fields from input_dict |
Raises:
Type | Description |
---|---|
MissingShotNumber
|
If the input_dict does not contain the key 'shot' |
InvalidRecordField
|
If the input_dict contains the key 'key' or 'errors' |
get(key, default)
Get a field from the record with a default value if the field does not exist
keep(keys)
Remove all fields from the record that are not in keys
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
List[Any]
|
A list of keys to keep in the record |
required |
keys()
Get the keys of the record
pop(key)
Remove a field from the record
set_error(field, exception)
Set an error for a field in the record
Updates the 'errors' field in the record with key 'field' to store the exception (including the traceback in a serializable format)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
The field name to set the error for |
required |
exception |
Exception
|
The exception to store |
required |