antimatter.extra_helper#

Module Contents#

Functions#

extra_dict_from_string(→ Dict[str, Any])

Parses an 'extra' dictionary from a string. The string, if present, is

extra_for_session(→ Dict[str, Any])

Arranges an 'extra' dictionary for a Session using the given Datatype

extra_for_capsule(→ Dict[str, Any])

Arranges an 'extra' dictionary for a Capsule using the given Datatype to

get_field_type(→ antimatter.fieldtype.fieldtypes.FieldType)

Helper function to get the field type from a Capsule level 'extra' dictionary

without_meta(→ Optional[Dict[str, Any]])

Helper function to strip special metadata keys from the provided 'extra'

Attributes#

antimatter.extra_helper.META_TYPE_KEY = '_metadtype'#
antimatter.extra_helper.COL_TYPE_KEY = '_coltype'#
antimatter.extra_helper.DTYPE_KEY = '_dtype'#
antimatter.extra_helper.ALL_META_KEYS#
antimatter.extra_helper.DEFAULT_COL_NAME = 'content'#
antimatter.extra_helper.extra_dict_from_string(serialized_extra: str | None, row_cnt: int = -1, col_names: List[str] = None) Dict[str, Any]#

Parses an ‘extra’ dictionary from a string. The string, if present, is expected to be a serialized JSON format dictionary.

If ‘extra’ is empty or None, a default extra dict will be returned based on the row count and column names, following these rules for determining the default type when the ‘extra’ dictionary is not supplied: 1. If it can be determined that the data is a scalar value by virtue of only one row and column of data existing with the default ‘content’ column name, the default type will be set as a Scalar value. 2. Otherwise, if only one row exists, the default type will be set as a Dict. 3. In all other cases, the default type will be set as a DictList.

Parameters:
  • serialized_extra – The serialized ‘extra’ dictionary

  • row_cnt – The number of rows in the data set

  • col_names – The names of the columns in the data set

Returns:

A parsed ‘extra’ dictionary

antimatter.extra_helper.extra_for_session(dt: antimatter.datatype.datatypes.Datatype, from_capsule: Dict[str, Any], session_extra: Dict[str, Any] | None = None) Dict[str, Any]#

Arranges an ‘extra’ dictionary for a Session using the given Datatype and the ‘extra’ dictionary built from a handler’s “to_generic” method. If an existing session “extra” dictionary is provided, it will be updated with the additional information.

Parameters:
  • dt – the Datatype for the capsule data

  • from_capsule – the ‘extra’ data from the capsule level generic handling

  • session_extra – an optional existing Session level ‘extra’ dict

Returns:

a Session level ‘extra’ dict for passing metadata to a Capsule

antimatter.extra_helper.extra_for_capsule(dt: antimatter.datatype.datatypes.Datatype, session_extra: Dict[str, Any] | None, **kwargs) Dict[str, Any]#

Arranges an ‘extra’ dictionary for a Capsule using the given Datatype to load the Capsule in and the Session level ‘extra’ dictionary. If kwargs are provided, they will be passed as-is to the ‘extra’ dictionary.

Parameters:
  • dt – the Datatype for the Capsule data

  • session_extra – the Session level ‘extra’ dict

  • kwargs – the kwargs passed to a Capsule for reading data

Returns:

a Capsule level ‘extra’ dict for passing metadata to a data handler

antimatter.extra_helper.get_field_type(col_name: str, extra: Dict[str, Any] | None, default: antimatter.fieldtype.fieldtypes.FieldType = FieldType.String) antimatter.fieldtype.fieldtypes.FieldType#

Helper function to get the field type from a Capsule level ‘extra’ dictionary for the provided column name, falling back to the default value.

Parameters:
  • col_name – the name of the column to get the field type metadata for

  • extra – the Capsule level ‘extra’ dict containing handler metadata

  • default – fallback FieldType value (String by default)

Returns:

the FieldType of the given column as found in the ‘extra’ metadata

antimatter.extra_helper.without_meta(extra: Dict[str, Any] | None) Dict[str, Any] | None#

Helper function to strip special metadata keys from the provided ‘extra’ dictionary. A new copy of the dictionary is made and returned.

Parameters:

extra – the ‘extra’ dict to strip special metadata from

Returns:

the ‘extra’ dict with special metadata stripped