Get the modules as a dictionary. Returns ------- d : dict[str, list[module]] Dictionary with module names as keys, modules as values.
(self, orient='list')
| 41 | return l |
| 42 | |
| 43 | def to_dict(self, orient='list'): |
| 44 | """ |
| 45 | Get the modules as a dictionary. |
| 46 | |
| 47 | Returns |
| 48 | ------- |
| 49 | d : dict[str, list[module]] |
| 50 | Dictionary with module names as keys, modules as values. |
| 51 | |
| 52 | """ |
| 53 | |
| 54 | def _dict_update_vals(raw_container): |
| 55 | if orient == 'list': |
| 56 | return raw_container |
| 57 | elif orient == 'records': |
| 58 | return {(name, n): module for name, mod_list in raw_container.items() for n, module in |
| 59 | enumerate(mod_list)} |
| 60 | |
| 61 | def _list_update_vals(key, raw_container): |
| 62 | if orient == 'list': |
| 63 | return {key: raw_container} |
| 64 | elif orient == 'records': |
| 65 | return {(key, n): module for n, module in enumerate(raw_container)} |
| 66 | |
| 67 | raise ValueError(f"Unrecognized orient '{orient}'") |
| 68 | |
| 69 | d = dict() |
| 70 | |
| 71 | for k, raw_container in self.containers.items(): |
| 72 | if isinstance(raw_container, ModuleList): |
| 73 | d.update(_list_update_vals(k, raw_container)) |
| 74 | else: |
| 75 | d.update(_dict_update_vals(raw_container)) |
| 76 | |
| 77 | return d |
| 78 | |
| 79 | def to_tuples(self): |
| 80 | """ |
no test coverage detected