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.

Parameters:
  • discipline_name (str) -- The name of the discipline.

  • variable_names_to_new_variable_names (Mapping[str, str]) -- The new variable names bound to the old variable names.

Return type:

None

add_translations_by_variable(new_variable_name, discipline_names_to_variable_names)[source]#

Add one or more translations for a same variable.

Parameters:
  • new_variable_name (str) -- The new name of the variable to rename discipline variables.

  • discipline_names_to_variable_names (Mapping[str, str]) -- The variable names bound to the discipline names.

Return type:

None

classmethod from_csv(file_path, sep=',')[source]#

Create from a CSV file.

Structured as discipline_name, variable_name, new_variable_name.

Parameters:
  • file_path (str | Path) -- The path to the CSV file.

  • sep (str) --

    The separator character.

    By default it is set to ",".

Returns:

A renamer.

Return type:

Self

classmethod from_dictionary(translations)[source]#

Create from dictionaries.

Parameters:

translations (Mapping[str, Mapping[str, str]]) -- The translations of the discipline input and output variables as {discipline_name: {variable_name: new_variable_name}}.

Returns:

A renamer.

Return type:

VariableRenamer

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:

VariableRenamer

property translations: tuple[VariableTranslation, ...]#

The translations of the discipline input and output variables.

property translators: Mapping[str, Mapping[str, str]]#

The translators.

As {discipline_name: {variable_name, new_variable_name}}.

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)

Parameters:
  • discipline_name (str)

  • variable_name (str)

  • new_variable_name (str)

discipline_name: str#

The name of the discipline.

new_variable_name: str#

The new name of the variable.

variable_name: str#

The name of the variable.

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