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 (DataMapping) – A dict-like object or a
DisciplineData
object. IfNone
, an empty dictionary is used.
- clear() None. Remove all items from D. ¶
- Return type:
None
- copy(keys=(), with_namespace=True)¶
Create a shallow copy.
- Parameters:
- Returns:
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.
- restrict(*keys)¶
Remove all but the given keys.
- Parameters:
*keys (str) – The keys of the elements to keep.
- Return type:
None
- 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.
- values() an object providing a view on D's values ¶
- SEPARATOR = '~'¶
The character used to separate the shared dict key from the column of a pandas DataFrame.