MCPcopy Index your code
hub / github.com/plotly/dash / flatten_grouping

Function flatten_grouping

dash/_grouping.py:20–60  ·  view source on GitHub ↗

Convert a grouping value to a list of scalar values :param grouping: grouping value to flatten :param schema: If provided, a grouping value representing the expected structure of the input grouping value. If not provided, the grouping value is its own schema. A schema i

(grouping, schema=None)

Source from the content-addressed store, hash-verified

18
19
20def flatten_grouping(grouping, schema=None):
21 """
22 Convert a grouping value to a list of scalar values
23
24 :param grouping: grouping value to flatten
25 :param schema: If provided, a grouping value representing the expected structure of
26 the input grouping value. If not provided, the grouping value is its own schema.
27 A schema is required in order to be able treat tuples and dicts in the input
28 grouping as scalar values.
29
30 :return: list of the scalar values in the input grouping
31 """
32 stack = []
33 result = []
34
35 # Avoid repeated recursive Python calls by using an explicit stack
36 push = stack.append
37 pop = stack.pop
38
39 # Only validate once at the top if schema is provided
40 if schema is None:
41 schema = grouping
42 else:
43 validate_grouping(grouping, schema)
44
45 push((grouping, schema))
46 while stack:
47 group, sch = pop()
48 # Inline isinstance checks for perf
49 typ = type(sch)
50 if typ is tuple or typ is list:
51 # Avoid double recursion / excessive list construction
52 for ge, se in zip(group, sch):
53 push((ge, se))
54 elif typ is dict:
55 for k in sch:
56 push((group[k], sch[k]))
57 else:
58 result.append(group)
59 result.reverse() # Since we LIFO, leaf values are in reverse order
60 return result
61
62
63def grouping_len(grouping):

Callers 15

_dep_param_mapMethod · 0.90
test_flatten_scalarFunction · 0.90
test_flatten_listFunction · 0.90
test_flatten_dictFunction · 0.90
test_flatten_mixedFunction · 0.90
test_flatten_odd_valueFunction · 0.90
test_map_grouping_mixedFunction · 0.90
_prepare_responseFunction · 0.85
register_callbackFunction · 0.85

Calls 5

validate_groupingFunction · 0.85
pushFunction · 0.50
popFunction · 0.50
appendMethod · 0.45
reverseMethod · 0.45

Tested by 9

test_flatten_scalarFunction · 0.72
test_flatten_listFunction · 0.72
test_flatten_dictFunction · 0.72
test_flatten_mixedFunction · 0.72
test_flatten_odd_valueFunction · 0.72
test_map_grouping_mixedFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…