Data Types

In order to standardize data handling in Empyric, values of variables as well as instrument knobs and meters are funneled into the following data types. Booleans, Integers, Floats, Strings and Arrays are stored internally as numpy.bool_, numpy.int64, numpy.float64, numpy.str_ and numpy.ndarray, respectively.

class empyric.types.Type

Abstract base class for all supported data types

class empyric.types.Boolean

Abstract base class for bool and numpy.bool_


class empyric.types.Toggle(state: str | bool | int | type)

Convenience class for handling toggle variables, which are either off or on.


class empyric.types.Integer

Abstract base class for int and numpy.integer


class empyric.types.Float

Abstract base class for float and numpy.floating


class empyric.types.String

Abstract base class for str and numpy.str_


class empyric.types.Array

Abstract base class for list, tuple, numpy.ndarray, pandas.Series and pandas.Dataframe

empyric.types.recast(value: ~typing.Any, to: type = <class 'empyric.types.Type'>) Type | None

Convert a value into the appropriate type for the information it contains.

If a subclass of Type is passed to the optional to keyword argument, the value is recast to that type. Otherwise, recasting goes as follows.

Booleans are converted into numpy booleans; integers are converted into 64-bit numpy integers; floats are converted into 64-bit numpy floats.

Array-like values are converted into the analogous numpy array.

Strings are inspected to determine if they represent boolean or numerical values and, if so, recasts values to the appropriate types. If a string is a path in either the working directory or the parent directory thereof, it is converted into the full absolute path. If a string does not represent boolean or numerical values and is not a path, then this function just returns the same string.

If the value argument does not fit into one of the above categories, a warning will be printed and None will be returned.

Parameters:
  • value – (Any) the value whose type needs converting

  • to – (Type) optional keyword argument indicating which type to convert to; default value is Type which indicates that the type should be inferred based on the value.