gemseo.utils.variable_renaming module#
Tools to facilitate the renaming of discipline input and output variables.
- class VariableRenamer[source]#
Bases:
object
Renamer of discipline input and output variable names.
- add_translation(translation)[source]#
Add a translation.
- Parameters:
translation (VariableTranslation | tuple[str, str, str]) -- A variable translation. If tuple, formatted as
(discipline_name, variable_name, new_variable_name)
.- Raises:
ValueError -- When a variable has already been renamed.
- Return type:
None
- add_translations_by_discipline(discipline_name, variable_names_to_new_variable_names)[source]#
Add one or more translations for a given discipline.
- add_translations_by_variable(new_variable_name, discipline_names_to_variable_names)[source]#
Add one or more translations for a same variable.
- classmethod from_csv(file_path, sep=',')[source]#
Create from a CSV file.
Structured as discipline_name, variable_name, new_variable_name.
- classmethod from_dictionary(translations)[source]#
Create from dictionaries.
- classmethod from_spreadsheet(file_path)[source]#
Create from a spreadsheet file.
Structured as discipline_name, variable_name, new_variable_name.
- Parameters:
file_path (str | Path) -- The path to the spreadsheet file.
- Returns:
A renamer.
- Return type:
Self
- classmethod from_translations(*translations)[source]#
Create from translations.
- Parameters:
*translations (VariableTranslation | tuple[str, str, str]) -- The translations of the discipline input and output variables. If
tuple
, formatted as(discipline_name, variable_name, new_variable_name)
.- Returns:
A renamer.
- Return type:
- property translations: tuple[VariableTranslation, ...]#
The translations of the discipline input and output variables.
- class VariableTranslation(discipline_name, variable_name, new_variable_name)[source]#
Bases:
NamedTuple
The translation of a discipline input or output variable.
Create new instance of VariableTranslation(discipline_name, variable_name, new_variable_name)
- rename_discipline_variables(disciplines, translators)[source]#
Rename input and output variables of disciplines.
- Parameters:
disciplines (Iterable[Discipline]) -- The disciplines.
translators (Mapping[str, Mapping[str, str]]) -- The translators of the form
{discipline_name: {variable_name: new_variable_name}}
.
- Raises:
ValueError -- when a translator uses a wrong
variable_name
.- Return type:
None