base module¶
Base class for converting data values to NumPy arrays and vice versa.
- class gemseo.core.data_converters.base.BaseDataConverter(grammar)[source]¶
-
Base class for converting data values to NumPy arrays and vice versa.
Typically, data are dictionary-like object that map names to values, such as
DisciplineData
.By default, a data converter can handle the conversion of a data value that is a standard number (
int
,float
andcomplex
) or a 1D NumPy array. Other types could be handled in derived classes.A data converter can also be used to convert a data structure
{data_name: data_value, ...}
to a NumPy array and vice versa. In this class, a data structure is noteddata
.For performance reasons, no checking or error handling is done when calling the methods of this class or of its derivatives.
Note
The data converter uses a grammar, and in particular its mapping from data names to data types, to convert a NumPy array from/to a data value.
- Parameters:
grammar (T) – The grammar providing the data types used for the conversions.
- compute_names_to_sizes(names, data)[source]¶
Compute a mapping from data names to data value sizes.
See also
- compute_names_to_slices(names, data, names_to_sizes=mappingproxy({}))[source]¶
Compute a mapping from data names to data value slices.
The slices are relative to a NumPy array concatenating the data values associated with these data names.
- Parameters:
- Returns:
The mapping from the data names to the data slices of the expected concatenated NumPy array. and the size of this array.
- Return type:
- convert_array_to_data(array, names_to_slices)[source]¶
Convert a NumPy array to a data structure.
See also
- convert_array_to_value(name, array)[source]¶
Convert a NumPy array to a data value.
- Parameters:
name (str) – The data name.
array (NumberArray) – The NumPy array to convert.
- Returns:
The data value.
- Return type:
ValueType
- convert_data_to_array(names, data)[source]¶
Convert a part of a data structure to a NumPy array.
See also
- Parameters:
data (StrKeyMapping) – The data structure.
names (Iterable[str]) – The data names which values will be concatenated.
- Returns:
The concatenated NumPy array.
- Return type:
NumberArray
- convert_value_to_array(name, value)[source]¶
Convert a data value to a NumPy array.
- Parameters:
name (str) – The data name.
value (ValueType) – The data value.
- Returns:
The NumPy array.
- Return type:
NumberArray
- classmethod get_value_size(name, value)[source]¶
Return the size of a data value.
The size is typically what is returned by
ndarray.size
orlen(list)
. The size of a number is 1.
Examples using BaseDataConverter¶
Create a discipline that uses pandas DataFrames