simuran.core.base_container module

This module holds containers to allow for batch processing.

class simuran.core.base_container.GenericContainer(container: list = <factory>)

Bases: object

A container in SIMURAN, a wrapper of a list.

This has some extra functionality, such as retrieving information from each item in the container, or grouping items by property.

container

The underlying list being wrapped.

Type:list
append(item)

Append item to self.container.

Parameters:item (object) – The item to append.
Returns:
Return type:None
extend(iterable)

Extend self.container

get_attrs() → dict[str, Any]
get_attrs_and_methods() → list[str]
get_possible_values(prop)

Return a list of all values of val.prop for val in self.

Parameters:prop (str) – The name of the attribute to retrieve values for.
Returns:All values of prop found in the container.
Return type:set
get_property(prop)

Return a list as item.prop for prop in self.

Parameters:prop (str) – The name of the attribute to retrieve from each item.
Returns:The value of the property for each item in the container.
Return type:list
group_by_property(prop, value)

Return all items in the container with item.prop == value.

Parameters:
  • prop (str) – The name of the attribute to group by.
  • value (object) – The value of the property to group by.
Returns:

  • group (list of objects) – The items in the container satisfying the conditions.
  • indices (list of int) – The index of each item in the container satisfying the conditions.

inspect(methods: bool = False, **kwargs) → None

Note: could also try objexplore

load(idx: Optional[int] = None) → Any
split_into_groups(prop)

Split into groups based on property.

Does not support mutable values (list or dict) in the property list.

Parameters:prop (str) – The name of the attribute to group by.
Returns:dict
Return type:key : (group, index), for key in set(self.get_property(prop))