devctrl.utility.sample.Sample#

class Sample(key: str = '', filename: str | None = None, name: str = '', metadata: dict[str, str]=<factory>)[source]#

Bases: SettingsClass

Dataclass representing a sample.

Methods

as_dict

Convenience wrapper for dataclasses.asdict(self)

from_dict

Recursively construct a SettingsClass from a dictionary.

load_yaml

save_yaml

Attributes

__annotations__ = {'filename': typing.Optional[str], 'key': <class 'str'>, 'metadata': dict[str, str], 'name': <class 'str'>}#
__dataclass_fields__ = {'filename': Field(name='filename',type=typing.Optional[str],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Override the file name to use. If None, the key is used instead.'}),kw_only=False,_field_type=_FIELD), 'key': Field(name='key',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Sample Key'}),kw_only=False,_field_type=_FIELD), 'metadata': Field(name='metadata',type=dict[str, str],default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "Extra key-value pairs, e.g. 'batch' or 'date'"}),kw_only=False,_field_type=_FIELD), 'name': Field(name='name',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Full name of the sample, will be used for plot titles.'}),kw_only=False,_field_type=_FIELD)}#
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False,match_args=True,kw_only=False,slots=False,weakref_slot=False)#
__dict__ = mappingproxy({'__module__': 'devctrl.utility.sample', '__firstlineno__': 5, '__annotations__': {'key': <class 'str'>, 'filename': typing.Optional[str], 'name': <class 'str'>, 'metadata': dict[str, str]}, '__doc__': 'Dataclass representing a sample.', 'key': '', 'filename': None, 'name': '', '__static_attributes__': (), '__dataclass_params__': _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False,match_args=True,kw_only=False,slots=False,weakref_slot=False), '__dataclass_fields__': {'key': Field(name='key',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Sample Key'}),kw_only=False,_field_type=_FIELD), 'filename': Field(name='filename',type=typing.Optional[str],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Override the file name to use. If None, the key is used instead.'}),kw_only=False,_field_type=_FIELD), 'name': Field(name='name',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Full name of the sample, will be used for plot titles.'}),kw_only=False,_field_type=_FIELD), 'metadata': Field(name='metadata',type=dict[str, str],default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "Extra key-value pairs, e.g. 'batch' or 'date'"}),kw_only=False,_field_type=_FIELD)}, '__replace__': <function _replace>, '__hash__': None, '__init__': <function Sample.__init__>, '__repr__': <function Sample.__repr__>, '__eq__': <function Sample.__eq__>, '__match_args__': ('key', 'filename', 'name', 'metadata')})#
__eq__(other)#

Return self==value.

__firstlineno__ = 5#
__hash__ = None#
__init__(key: str = '', filename: str | None = None, name: str = '', metadata: dict[str, str]=<factory>) None#
__match_args__ = ('key', 'filename', 'name', 'metadata')#
__module__ = 'devctrl.utility.sample'#
__or__(other)#

Merge with another settings class or a dictionary.

__replace__(**changes)#
__repr__()#

Return repr(self).

__static_attributes__ = ()#
__weakref__#

list of weak references to the object

as_dict() dict#

Convenience wrapper for dataclasses.asdict(self)

filename: str | None = None#
classmethod from_dict(data: dict)#

Recursively construct a SettingsClass from a dictionary.

If the value of a field is another SettingsClass, from_dict() will be called for that field as well. Handled are:

  • SettingsClass

  • list[SettingsClass]

  • dict[<any>, SettingsClass]

  • all of the above as Optional (Union with None)

  • a Union with any handled types

Raises:
  • ValueError – If data contains a value that has the wrong type for the field of cls (ONLY if the type is a subclass of SettingsClass! Other types are not enforced)

  • KeyError – If data contains a key that is not a field name of cls

key: str = ''#
classmethod load_yaml(yaml_path: str, loader=<class 'yaml.loader.Loader'>)#
metadata: dict[str, str]#
name: str = ''#
save_yaml(yaml_path: str)#