convert#

convert(obj, from_type: str, to_type: str, as_scitype: str = None, store=None, store_behaviour: str = None, return_to_mtype: bool = False)[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 mtype to convert “obj” to, a valid mtype string

or list of str, this specifies admissible types for conversion to; if list, will convert to first mtype of the same scitype as from_mtype

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

return_to_mtype: bool, optional (default=False)

if True, also returns the str of the mtype converted to

Returns:
converted_objto_type - object obj converted to mtype to_type

if obj was None, is None

to_typestr, only returned if return_to_mtype=True

mtype of converted_obj - useful of to_type was a list

Raises:
KeyError if conversion is not implemented
TypeError or ValueError if inputs do not match specification