1
1
from collections import defaultdict
2
2
from collections .abc import Mapping
3
- from typing import Dict , Union , Optional , DefaultDict , Set
3
+ from typing import Dict , Union , Optional , DefaultDict , Set , Type
4
4
from ..graph import Graph
5
5
6
6
import pandas
@@ -22,14 +22,14 @@ class Assignment(Mapping):
22
22
'mapping'
23
23
]
24
24
25
- def __init__ (self , parts : Dict , mapping : Dict = None , validate : bool = True ) -> None :
25
+ def __init__ (self , parts : Dict , mapping : Optional [ Dict ] = None , validate : bool = True ) -> None :
26
26
"""
27
- :param parts: dictionary mapping partition assignments to sets or
28
- frozensets of nodes
27
+ :param parts: Dictionary mapping partition assignments frozensets of nodes.
29
28
:type parts: Dict
30
- :param mapping: dictionary mapping nodes to partition assignments
31
- :type mapping: Dict, optional
32
- :param validate: whether to validate the assignment
29
+ :param mapping: Dictionary mapping nodes to partition assignments.
30
+ Default is None.
31
+ :type mapping: Optional[Dict], optional
32
+ :param validate: Whether to validate the assignment. Default is True.
33
33
:type validate: bool, optional
34
34
35
35
:returns: None
@@ -163,6 +163,7 @@ def get_assignment(part_assignment: Union[str, Dict, Assignment],
163
163
:class:`Assignment` object corresponding to the desired assignment.
164
164
:type part_assignment: str
165
165
:param graph: The graph from which to extract the assignment.
166
+ Default is None.
166
167
:type graph: Optional[Graph], optional
167
168
168
169
:returns: An :class:`Assignment` object containing the assignment
@@ -190,16 +191,16 @@ def get_assignment(part_assignment: Union[str, Dict, Assignment],
190
191
raise TypeError ("Assignment must be a dict or a node attribute key" )
191
192
192
193
193
- def level_sets (mapping : Dict , container : Set = set ) -> DefaultDict :
194
+ def level_sets (mapping : Dict , container : Type [ Set ] = set ) -> DefaultDict :
194
195
"""
195
196
Inverts a dictionary. ``{key: value}`` becomes
196
197
``{value: <container of keys that map to value>}``.
197
198
198
199
:param mapping: A dictionary to invert. Keys and values can be of any type.
199
200
:type mapping: Dict
200
201
:param container: A container type used to collect keys that map to the same value.
201
- By default, it is a set.
202
- :type container: Set
202
+ By default, the container type is `` set`` .
203
+ :type container: Type[ Set], optional
203
204
204
205
:return: A dictionary where each key is a value from the original dictionary,
205
206
and the corresponding value is a container (by default, a set) of keys from
0 commit comments