skcriteria.utils.bunch module

Container object exposing keys as attributes.

class skcriteria.utils.bunch.Bunch(name, data)[source]

Bases: Mapping

Container object exposing keys as attributes.

Concept based on the sklearn.utils.Bunch.

Bunch objects are sometimes used as an output for functions and methods. They extend dictionaries by enabling values to be accessed by key, bunch[“value_key”], or by an attribute, bunch.value_key.

Examples

>>> b = SKCBunch("data", {"a": 1, "b": 2})
>>> b
data({a, b})
>>> b['b']
2
>>> b.b
2
>>> b.a = 3
>>> b['a']
3
get(key, default=None)[source]

Get item from bunch.

to_dict()[source]

Convert the Bunch object to a dictionary.

This method performs a deep copy of the _data attribute, ensuring that the original data remains unchanged.

Returns:

A deep copy of the _data attribute.

Return type:

dict

Example

>>> bunch = Bunch()
>>> bunch._data = {'key1': 'value1', 'key2': 'value2'}
>>> dict_data = bunch.to_dict()
>>> print(dict_data)
{'key1': 'value1', 'key2': 'value2'}