gemseo / core / grammars

Show inherited members

defaults module

The grammar default values.

class gemseo.core.grammars.defaults.Defaults(grammar, data)[source]

Bases: DisciplineData

A class for handling grammar default values.

A dictionary-like interface to bind grammar names to default values. The namespace settings of the grammar are taken into account.

Examples

>>> from gemseo.core.discipline_data import DisciplineData
>>> import numpy as np
>>> import pandas as pd
>>> data = {
...         'x': 0,
...         'y': pd.DataFrame(data={'a': np.array([0])}),
...     }
>>> disc_data = DisciplineData(data)
>>> disc_data['x']
0
>>> disc_data['y']
   a
0  0
>>> # DataFrame content can be accessed with the ~ separator.
>>> disc_data['y~a']
array([0])
>>> # New columns can be inserted into a DataFrame with the ~ separator.
>>> disc_data['y~b'] = np.array([1])
>>> data['y']['b']
0    1
Name: b, dtype: int64
>>> # New DataFrame can be added.
>>> disc_data['z~c'] = np.array([2])
>>> data['z']
   c
0  2
>>> type(data['z'])
<class 'pandas.core.frame.DataFrame'>
>>> # DataFrame's columns can be deleted.
>>> del disc_data['z~c']
>>> data['z']
Empty DataFrame
Columns: []
Index: [0]
>>> # Iterating is only done over the exposed keys.
>>> list(disc_data)
['x', 'y~a', 'y~b']
>>> # The length is consistent with the iterator.
>>> len(disc_data)
3

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • grammar (BaseGrammar) – The grammar bound to the defaults.

  • data (MutableData) – A dict-like object or a DisciplineData object. If None, an empty dictionary is used.

rename(name, new_name)[source]

Rename a name.

Parameters:
  • name (str) – The current name.

  • new_name (str) – The new name.

Return type:

None