convert#
- convert(obj, from_type: str, to_type: str, as_scitype: Optional[str] = None, store=None, store_behaviour: Optional[str] = None)[source]#
Convert objects between different machine representations, subject to scitype.
- Parameters:
- objobject to convert - any type, should comply with mtype spec for as_scitype
- from_typestr - the type to convert “obj” to, a valid mtype string
valid mtype strings, with explanation, are in datatypes.MTYPE_REGISTER
- to_typestr - the type to convert “obj” to, a valid mtype string
valid mtype strings, with explanation, are in datatypes.MTYPE_REGISTER
- as_scitypestr, optional - name of scitype the object “obj” is considered as
default = inferred from from_type valid scitype strings, with explanation, are in datatypes.SCITYPE_REGISTER
- storeoptional, reference of storage for lossy conversions, default=None (no ref)
is updated by side effect if not None and store_behaviour=”reset” or “update”
- store_behaviourstr, optional, one of None (default), “reset”, “freeze”, “update”
“reset” - store is emptied and then updated from conversion “freeze” - store is read-only, may be read/used by conversion but not changed “update” - store is updated from conversion and retains previous contents None - automatic: “update” if store is empty and not None; “freeze”, otherwise
- Returns:
- converted_objto_type - object obj converted to to_type
if obj was None, returns None
- Raises:
- KeyError if conversion is not implemented
- TypeError or ValueError if inputs do not match specification