dantro.abc module¶
This module holds the abstract base classes needed for dantro
-
class
dantro.abc.AbstractDataContainer(*, name: str, data: Any)[source]¶ Bases:
objectThe AbstractDataContainer is the class defining the data container interface. It holds the bare basics of methods and attributes that _all_ dantro data tree classes should have in common: a name, some data, and some association with others via an optional parent object.
Via the parent and the name, path capabilities are provided. Thereby, each object in a data tree has some information about its location relative to a root object. Objects that have _no_ parent are regarded to be an object that is located “next to” root, i.e. having the path /<container_name>.
-
abstract
__init__(*, name: str, data: Any)[source]¶ Initialize the AbstractDataContainer, which holds the bare essentials of what a data container should have.
- Parameters
name (str) – The name of this container
data (Any) – The data that is to be stored
-
property
name¶ The name of this DataContainer-derived object.
-
property
classname¶ Returns the name of this DataContainer-derived class
-
property
logstr¶ Returns the classname and name of this object; a combination often used in logging…
-
property
data¶ The stored data.
-
property
parent¶ The associated parent of this container or group
-
property
path¶ The path to get to this container or group from some root path
-
_check_name(new_name: str) → None[source]¶ Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters
new_name (str) – The new name, which is to be checked.
-
_check_data(data: Any) → None[source]¶ This method can be used to check the data provided to this container
It is called before the data is stored in the __init__ method and should raise an exception or create a warning if the data is not as desired.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- NOTE The CheckDataMixin provides a generalised implementation of this
method to perform some type checks and react to unexpected types.
- Parameters
data (Any) – The data to check
-
__str__() → str[source]¶ An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
-
__format__(spec_str: str) → str[source]¶ Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
-
_format_logstr() → str[source]¶ A __format__ helper function: returns the log string, a combination of class name and name
-
abstract
_format_info() → str[source]¶ A __format__ helper function: returns an info string that is used to characterise this object. Should NOT include name and classname!
-
_abc_impl= <_abc_data object>¶
-
abstract
-
class
dantro.abc.AbstractDataGroup(*, name: str, data: Any)[source]¶ Bases:
dantro.abc.AbstractDataContainer,collections.abc.MutableMappingThe AbstractDataGroup is the abstract basis of all data groups.
It enforces a MutableMapping interface with a focus on _setting_ abilities and less so on deletion.
-
property
data¶ The stored data.
-
abstract
add(*conts, overwrite: bool = False) → None[source]¶ Adds the given containers to the group.
-
abstract
__contains__(cont: Union[str, dantro.abc.AbstractDataContainer]) → bool[source]¶ Whether the given container is a member of this group
-
abstract
get(key, default=None)[source]¶ Return the container at key, or default if container with name key is not available.
-
abstract
setdefault(key, default=None)[source]¶ If key is in the dictionary, return its value. If not, insert key with a value of default and return default. default defaults to None.
-
abstract
_format_tree() → str[source]¶ A __format__ helper function: tree representation of this group
-
abstract
_tree_repr(level: int = 0) → str[source]¶ Recursively creates a multi-line string tree representation of this group. This is used by, e.g., the _format_tree method.
-
_MutableMapping__marker= <object object>¶
-
abstract
__delitem__(key) → None¶ Deletes an item from the container.
-
__format__(spec_str: str) → str¶ Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
-
abstract
__getitem__(key)¶ Gets an item from the container.
-
abstract
__init__(*, name: str, data: Any)¶ Initialize the AbstractDataContainer, which holds the bare essentials of what a data container should have.
- Parameters
name (str) – The name of this container
data (Any) – The data that is to be stored
-
__repr__() → str¶ Same as __str__
-
abstract
__setitem__(key, val) → None¶ Sets an item in the container.
-
__str__() → str¶ An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
-
_abc_impl= <_abc_data object>¶
-
_check_data(data: Any) → None¶ This method can be used to check the data provided to this container
It is called before the data is stored in the __init__ method and should raise an exception or create a warning if the data is not as desired.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- NOTE The CheckDataMixin provides a generalised implementation of this
method to perform some type checks and react to unexpected types.
- Parameters
data (Any) – The data to check
-
_check_name(new_name: str) → None¶ Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters
new_name (str) – The new name, which is to be checked.
-
_format_cls_name() → str¶ A __format__ helper function: returns the class name
-
abstract
_format_info() → str¶ A __format__ helper function: returns an info string that is used to characterise this object. Should NOT include name and classname!
-
_format_logstr() → str¶ A __format__ helper function: returns the log string, a combination of class name and name
-
_format_name() → str¶ A __format__ helper function: returns the name
-
_format_path() → str¶ A __format__ helper function: returns the path to this container
-
property
classname¶ Returns the name of this DataContainer-derived class
-
clear() → None. Remove all items from D.¶
-
property
logstr¶ Returns the classname and name of this object; a combination often used in logging…
-
property
name¶ The name of this DataContainer-derived object.
-
property
parent¶ The associated parent of this container or group
-
property
path¶ The path to get to this container or group from some root path
-
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.
-
update([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
property
-
class
dantro.abc.AbstractDataAttrs(*, name: str, data: Any)[source]¶ Bases:
collections.abc.Mapping,dantro.abc.AbstractDataContainerThe BaseDataAttrs class defines the interface for the .attrs attribute of a data container.
This class derives from the abstract class as otherwise there would be circular inheritance. It stores the attributes as mapping and need not be subclassed.
-
abstract
__delitem__(key) → None¶ Deletes an item from the container.
-
__format__(spec_str: str) → str¶ Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_.
-
abstract
__init__(*, name: str, data: Any)¶ Initialize the AbstractDataContainer, which holds the bare essentials of what a data container should have.
- Parameters
name (str) – The name of this container
data (Any) – The data that is to be stored
-
__repr__() → str¶ Same as __str__
-
abstract
__setitem__(key, val) → None¶ Sets an item in the container.
-
__str__() → str¶ An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
-
_abc_impl= <_abc_data object>¶
-
_check_data(data: Any) → None¶ This method can be used to check the data provided to this container
It is called before the data is stored in the __init__ method and should raise an exception or create a warning if the data is not as desired.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- NOTE The CheckDataMixin provides a generalised implementation of this
method to perform some type checks and react to unexpected types.
- Parameters
data (Any) – The data to check
-
_check_name(new_name: str) → None¶ Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters
new_name (str) – The new name, which is to be checked.
-
_format_cls_name() → str¶ A __format__ helper function: returns the class name
-
abstract
_format_info() → str¶ A __format__ helper function: returns an info string that is used to characterise this object. Should NOT include name and classname!
-
_format_logstr() → str¶ A __format__ helper function: returns the log string, a combination of class name and name
-
_format_name() → str¶ A __format__ helper function: returns the name
-
_format_path() → str¶ A __format__ helper function: returns the path to this container
-
property
classname¶ Returns the name of this DataContainer-derived class
-
property
data¶ The stored data.
-
get(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
logstr¶ Returns the classname and name of this object; a combination often used in logging…
-
property
name¶ The name of this DataContainer-derived object.
-
property
parent¶ The associated parent of this container or group
-
property
path¶ The path to get to this container or group from some root path
-
abstract
-
class
dantro.abc.AbstractDataProxy(obj)[source]¶ Bases:
objectA data proxy fills in for the place of a data container, e.g. if data should only be loaded on demand. It needs to supply the resolve method.
-
abstract
__init__(obj)[source]¶ Initialize the proxy object, being supplied with the object that this proxy is to be proxy for.
-
property
classname¶ Returns this proxy’s class name
-
abstract
resolve(*, astype: type = None)[source]¶ Get the data that this proxy is a placeholder for and return it.
Note that this method does not place the resolved data in the container of which this proxy object is a placeholder for! This only returns the data.
The tags describing this proxy object
-
_abc_impl= <_abc_data object>¶
-
abstract
-
class
dantro.abc.AbstractPlotCreator(name: str, *, dm, **plot_cfg)[source]¶ Bases:
objectThis class defines the interface for PlotCreator classes
-
abstract
__init__(name: str, *, dm, **plot_cfg)[source]¶ Initialize the PlotCreator, given a data manager, the plot name, and the default plot configuration.
-
abstract
__call__(*, out_path: str = None, **update_plot_cfg)[source]¶ Perform the plot, updating the configuration passed to __init__ with the given values and then calling _plot.
-
abstract
plot(out_path: str = None, **cfg)[source]¶ Given a specific configuration, perform a plot.
This method should always be private and only be called from __call__.
-
_abc_impl= <_abc_data object>¶
-
abstract
prepare_cfg(*, plot_cfg: dict, pspace) → tuple[source]¶ Prepares the plot configuration for the PlotManager.
This function is called by the plot manager before the first plot is created.
The base implementation just passes the given arguments through. However, it can be re-implemented by derived classes to change the behaviour of the plot manager, e.g. by converting a plot configuration to a parameter space.
-
abstract
can_plot(creator_name: str, **plot_cfg) → bool[source]¶ Whether this plot creator is able to make a plot for the given plot configuration.
This function is used by the PlotManager’s auto-detect feature.
- Parameters
creator_name (str) – The name for this creator used within the PlotManager.
**plot_cfg – The plot configuration with which to decide this.
- Returns
Whether this creator can be used for the given plot config
- Return type
bool
-
abstract