gemseo / core / grammars

Hide 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.


>>> 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"]
>>> disc_data["y"]
0  0
>>> # DataFrame content can be accessed with the ~ separator.
>>> disc_data["y~a"]
>>> # 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"]
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)

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

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

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

clear() None.  Remove all items from D.
Return type:


copy(keys=(), with_namespace=True)

Create a shallow copy.

  • keys (Iterable[str]) –

    The names of the items to keep, if empty then keep them all.

    By default it is set to ().

  • with_namespace (bool) –

    Whether to the keys are prefixed with the namespace.

    By default it is set to True.


The shallow copy.

Return type:


get(k[, d]) D[k] if k in D, else d.  d defaults to None.
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

rename(name, new_name)[source]

Rename a name.

  • name (str) – The current name.

  • new_name (str) – The new name.

Return type:



Remove all but the given keys.


*keys (str) – The keys of the elements to keep.

Return type:


setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
update(other, exclude=())

Update from another mapping but for some keys.

  • other (Mapping[str, Any]) – The data to update from.

  • exclude (Iterable[str]) –

    The keys that shall not be updated.

    By default it is set to ().

Return type:


values() an object providing a view on D's values

The character used to separate the shared dict key from the column of a pandas DataFrame.