sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:cmp; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:key; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:reverse; 13, False; 14, block; 14, 15; 14, 29; 15, if_statement; 15, 16; 15, 22; 16, boolean_operator:and; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:key; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_keys; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:key; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:KeyValue; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 38; 31, attribute; 31, 32; 31, 37; 32, call; 32, 33; 32, 34; 33, identifier:super; 34, argument_list; 34, 35; 34, 36; 35, identifier:CliTable; 36, identifier:self; 37, identifier:sort; 38, argument_list; 38, 39; 38, 42; 38, 45; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:cmp; 41, identifier:cmp; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:key; 44, identifier:key; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:reverse; 47, identifier:reverse | def sort(self, cmp=None, key=None, reverse=False):
if not key and self._keys:
key = self.KeyValue
super(CliTable, self).sort(cmp=cmp, key=key, reverse=reverse) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:cmp; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:key; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:reverse; 13, False; 14, block; 14, 15; 14, 58; 14, 64; 14, 74; 14, 86; 14, 98; 14, 107; 14, 116; 15, function_definition; 15, 16; 15, 17; 15, 19; 16, function_name:_DefaultKey; 17, parameters; 17, 18; 18, identifier:value; 19, block; 19, 20; 19, 24; 19, 56; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:result; 23, list:[]; 24, for_statement; 24, 25; 24, 26; 24, 29; 25, identifier:key; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:header; 29, block; 29, 30; 30, try_statement; 30, 31; 30, 44; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:result; 36, identifier:append; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:float; 40, argument_list; 40, 41; 41, subscript; 41, 42; 41, 43; 42, identifier:value; 43, identifier:key; 44, except_clause; 44, 45; 44, 46; 45, identifier:ValueError; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:result; 51, identifier:append; 52, argument_list; 52, 53; 53, subscript; 53, 54; 53, 55; 54, identifier:value; 55, identifier:key; 56, return_statement; 56, 57; 57, identifier:result; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:key; 61, boolean_operator:or; 61, 62; 61, 63; 62, identifier:key; 63, identifier:_DefaultKey; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:new_table; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_table; 71, slice; 71, 72; 71, 73; 72, integer:1; 73, colon; 74, if_statement; 74, 75; 74, 78; 75, comparison_operator:is; 75, 76; 75, 77; 76, identifier:cmp; 77, None; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:key; 82, call; 82, 83; 82, 84; 83, identifier:cmp_to_key; 84, argument_list; 84, 85; 85, identifier:cmp; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:new_table; 90, identifier:sort; 91, argument_list; 91, 92; 91, 95; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:key; 94, identifier:key; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:reverse; 97, identifier:reverse; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_table; 103, list:[self.header]; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:header; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:_table; 113, identifier:extend; 114, argument_list; 114, 115; 115, identifier:new_table; 116, for_statement; 116, 117; 116, 120; 116, 126; 117, pattern_list; 117, 118; 117, 119; 118, identifier:index; 119, identifier:row; 120, call; 120, 121; 120, 122; 121, identifier:enumerate; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:_table; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:row; 131, identifier:row; 132, identifier:index | def sort(self, cmp=None, key=None, reverse=False):
def _DefaultKey(value):
result = []
for key in self.header:
try:
result.append(float(value[key]))
except ValueError:
result.append(value[key])
return result
key = key or _DefaultKey
new_table = self._table[1:]
if cmp is not None:
key = cmp_to_key(cmp)
new_table.sort(key=key, reverse=reverse)
self._table = [self.header]
self._table.extend(new_table)
for index, row in enumerate(self._table):
row.row = index |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:find_order; 3, parameters; 3, 4; 4, identifier:graph; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, string:'''
Do a topological sort on the dependency graph dict.
'''; 8, while_statement; 8, 9; 8, 10; 9, identifier:graph; 10, block; 10, 11; 10, 28; 10, 39; 10, 45; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:leftmost; 14, list_comprehension; 14, 15; 14, 16; 14, 25; 15, identifier:l; 16, for_in_clause; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:l; 19, identifier:s; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:graph; 23, identifier:items; 24, argument_list; 25, if_clause; 25, 26; 26, not_operator; 26, 27; 27, identifier:s; 28, if_statement; 28, 29; 28, 31; 29, not_operator; 29, 30; 30, identifier:leftmost; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:ValueError; 35, argument_list; 35, 36; 36, binary_operator:%; 36, 37; 36, 38; 37, string:'Dependency cycle detected! %s'; 38, identifier:graph; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:leftmost; 43, identifier:sort; 44, argument_list; 45, for_statement; 45, 46; 45, 47; 45, 48; 46, identifier:result; 47, identifier:leftmost; 48, block; 48, 49; 48, 52; 48, 59; 49, expression_statement; 49, 50; 50, yield; 50, 51; 51, identifier:result; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:graph; 56, identifier:pop; 57, argument_list; 57, 58; 58, identifier:result; 59, for_statement; 59, 60; 59, 61; 59, 66; 60, identifier:bset; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:graph; 64, identifier:values; 65, argument_list; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:bset; 71, identifier:discard; 72, argument_list; 72, 73; 73, identifier:result | def find_order(graph):
'''
Do a topological sort on the dependency graph dict.
'''
while graph:
leftmost = [l for l, s in graph.items() if not s]
if not leftmost:
raise ValueError('Dependency cycle detected! %s' % graph)
leftmost.sort()
for result in leftmost:
yield result
graph.pop(result)
for bset in graph.values():
bset.discard(result) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:do_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:value; 5, default_parameter; 5, 6; 5, 7; 6, identifier:case_sensitive; 7, False; 8, block; 8, 9; 8, 41; 9, if_statement; 9, 10; 9, 12; 9, 35; 10, not_operator; 10, 11; 11, identifier:case_sensitive; 12, block; 12, 13; 13, function_definition; 13, 14; 13, 15; 13, 17; 14, function_name:sort_func; 15, parameters; 15, 16; 16, identifier:item; 17, block; 17, 18; 17, 33; 18, if_statement; 18, 19; 18, 24; 19, call; 19, 20; 19, 21; 20, identifier:isinstance; 21, argument_list; 21, 22; 21, 23; 22, identifier:item; 23, identifier:basestring; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:item; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:item; 31, identifier:lower; 32, argument_list; 33, return_statement; 33, 34; 34, identifier:item; 35, else_clause; 35, 36; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:sort_func; 40, None; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:sorted; 44, argument_list; 44, 45; 44, 46; 45, identifier:seq; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:key; 48, identifier:sort_func | def do_sort(value, case_sensitive=False):
if not case_sensitive:
def sort_func(item):
if isinstance(item, basestring):
item = item.lower()
return item
else:
sort_func = None
return sorted(seq, key=sort_func) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:dedupe; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:contains_dupes; 5, default_parameter; 5, 6; 5, 7; 6, identifier:threshold; 7, integer:70; 8, default_parameter; 8, 9; 8, 10; 9, identifier:scorer; 10, attribute; 10, 11; 10, 12; 11, identifier:fuzz; 12, identifier:token_set_ratio; 13, block; 13, 14; 13, 18; 13, 118; 13, 122; 13, 132; 13, 140; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:extractor; 17, list:[]; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:item; 20, identifier:contains_dupes; 21, block; 21, 22; 21, 36; 21, 50; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:matches; 25, call; 25, 26; 25, 27; 26, identifier:extract; 27, argument_list; 27, 28; 27, 29; 27, 30; 27, 33; 28, identifier:item; 29, identifier:contains_dupes; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:limit; 32, None; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:scorer; 35, identifier:scorer; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:filtered; 39, list_comprehension; 39, 40; 39, 41; 39, 44; 40, identifier:x; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:x; 43, identifier:matches; 44, if_clause; 44, 45; 45, comparison_operator:>; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:x; 48, integer:1; 49, identifier:threshold; 50, if_statement; 50, 51; 50, 57; 50, 69; 51, comparison_operator:==; 51, 52; 51, 56; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:filtered; 56, integer:1; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:extractor; 62, identifier:append; 63, argument_list; 63, 64; 64, subscript; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:filtered; 67, integer:0; 68, integer:0; 69, else_clause; 69, 70; 70, block; 70, 71; 70, 86; 70, 107; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:filtered; 74, call; 74, 75; 74, 76; 75, identifier:sorted; 76, argument_list; 76, 77; 76, 78; 77, identifier:filtered; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:key; 80, lambda; 80, 81; 80, 83; 81, lambda_parameters; 81, 82; 82, identifier:x; 83, subscript; 83, 84; 83, 85; 84, identifier:x; 85, integer:0; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:filter_sort; 89, call; 89, 90; 89, 91; 90, identifier:sorted; 91, argument_list; 91, 92; 91, 93; 91, 104; 92, identifier:filtered; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:key; 95, lambda; 95, 96; 95, 98; 96, lambda_parameters; 96, 97; 97, identifier:x; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:x; 103, integer:0; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:reverse; 106, True; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:extractor; 111, identifier:append; 112, argument_list; 112, 113; 113, subscript; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:filter_sort; 116, integer:0; 117, integer:0; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:keys; 121, dictionary; 122, for_statement; 122, 123; 122, 124; 122, 125; 123, identifier:e; 124, identifier:extractor; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:keys; 130, identifier:e; 131, integer:1; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:extractor; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:keys; 138, identifier:keys; 139, argument_list; 140, if_statement; 140, 141; 140, 150; 140, 153; 141, comparison_operator:==; 141, 142; 141, 146; 142, call; 142, 143; 142, 144; 143, identifier:len; 144, argument_list; 144, 145; 145, identifier:extractor; 146, call; 146, 147; 146, 148; 147, identifier:len; 148, argument_list; 148, 149; 149, identifier:contains_dupes; 150, block; 150, 151; 151, return_statement; 151, 152; 152, identifier:contains_dupes; 153, else_clause; 153, 154; 154, block; 154, 155; 155, return_statement; 155, 156; 156, identifier:extractor | def dedupe(contains_dupes, threshold=70, scorer=fuzz.token_set_ratio):
extractor = []
for item in contains_dupes:
matches = extract(item, contains_dupes, limit=None, scorer=scorer)
filtered = [x for x in matches if x[1] > threshold]
if len(filtered) == 1:
extractor.append(filtered[0][0])
else:
filtered = sorted(filtered, key=lambda x: x[0])
filter_sort = sorted(filtered, key=lambda x: len(x[0]), reverse=True)
extractor.append(filter_sort[0][0])
keys = {}
for e in extractor:
keys[e] = 1
extractor = keys.keys()
if len(extractor) == len(contains_dupes):
return contains_dupes
else:
return extractor |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_process_and_sort; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:s; 5, identifier:force_ascii; 6, default_parameter; 6, 7; 6, 8; 7, identifier:full_process; 8, True; 9, block; 9, 10; 9, 25; 9, 33; 9, 45; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:ts; 13, conditional_expression:if; 13, 14; 13, 23; 13, 24; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:utils; 17, identifier:full_process; 18, argument_list; 18, 19; 18, 20; 19, identifier:s; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:force_ascii; 22, identifier:force_ascii; 23, identifier:full_process; 24, identifier:s; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:tokens; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:ts; 31, identifier:split; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:sorted_string; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, string:u" "; 39, identifier:join; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:sorted; 43, argument_list; 43, 44; 44, identifier:tokens; 45, return_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:sorted_string; 49, identifier:strip; 50, argument_list | def _process_and_sort(s, force_ascii, full_process=True):
ts = utils.full_process(s, force_ascii=force_ascii) if full_process else s
tokens = ts.split()
sorted_string = u" ".join(sorted(tokens))
return sorted_string.strip() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:token_sort_ratio; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:s1; 5, identifier:s2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force_ascii; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:full_process; 11, True; 12, block; 12, 13; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:_token_sort; 16, argument_list; 16, 17; 16, 18; 16, 19; 16, 22; 16, 25; 17, identifier:s1; 18, identifier:s2; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:partial; 21, False; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:force_ascii; 24, identifier:force_ascii; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:full_process; 27, identifier:full_process | def token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
return _token_sort(s1, s2, partial=False, force_ascii=force_ascii, full_process=full_process) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:partial_token_sort_ratio; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:s1; 5, identifier:s2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force_ascii; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:full_process; 11, True; 12, block; 12, 13; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:_token_sort; 16, argument_list; 16, 17; 16, 18; 16, 19; 16, 22; 16, 25; 17, identifier:s1; 18, identifier:s2; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:partial; 21, True; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:force_ascii; 24, identifier:force_ascii; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:full_process; 27, identifier:full_process | def partial_token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
return _token_sort(s1, s2, partial=True, force_ascii=force_ascii, full_process=full_process) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:WRatio; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:s1; 5, identifier:s2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force_ascii; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:full_process; 11, True; 12, block; 12, 13; 12, 50; 12, 61; 12, 72; 12, 76; 12, 80; 12, 84; 12, 92; 12, 121; 12, 130; 12, 139; 13, if_statement; 13, 14; 13, 15; 13, 40; 14, identifier:full_process; 15, block; 15, 16; 15, 28; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:p1; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:utils; 22, identifier:full_process; 23, argument_list; 23, 24; 23, 25; 24, identifier:s1; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:force_ascii; 27, identifier:force_ascii; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:p2; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:utils; 34, identifier:full_process; 35, argument_list; 35, 36; 35, 37; 36, identifier:s2; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:force_ascii; 39, identifier:force_ascii; 40, else_clause; 40, 41; 41, block; 41, 42; 41, 46; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:p1; 45, identifier:s1; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:p2; 49, identifier:s2; 50, if_statement; 50, 51; 50, 58; 51, not_operator; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:utils; 55, identifier:validate_string; 56, argument_list; 56, 57; 57, identifier:p1; 58, block; 58, 59; 59, return_statement; 59, 60; 60, integer:0; 61, if_statement; 61, 62; 61, 69; 62, not_operator; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:utils; 66, identifier:validate_string; 67, argument_list; 67, 68; 68, identifier:p2; 69, block; 69, 70; 70, return_statement; 70, 71; 71, integer:0; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:try_partial; 75, True; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:unbase_scale; 79, float:.95; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:partial_scale; 83, float:.90; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:base; 87, call; 87, 88; 87, 89; 88, identifier:ratio; 89, argument_list; 89, 90; 89, 91; 90, identifier:p1; 91, identifier:p2; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:len_ratio; 95, binary_operator:/; 95, 96; 95, 110; 96, call; 96, 97; 96, 98; 97, identifier:float; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:max; 101, argument_list; 101, 102; 101, 106; 102, call; 102, 103; 102, 104; 103, identifier:len; 104, argument_list; 104, 105; 105, identifier:p1; 106, call; 106, 107; 106, 108; 107, identifier:len; 108, argument_list; 108, 109; 109, identifier:p2; 110, call; 110, 111; 110, 112; 111, identifier:min; 112, argument_list; 112, 113; 112, 117; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, identifier:p1; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, identifier:p2; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:<; 122, 123; 122, 124; 123, identifier:len_ratio; 124, float:1.5; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:try_partial; 129, False; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:>; 131, 132; 131, 133; 132, identifier:len_ratio; 133, integer:8; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:partial_scale; 138, float:.6; 139, if_statement; 139, 140; 139, 141; 139, 197; 140, identifier:try_partial; 141, block; 141, 142; 141, 152; 141, 168; 141, 184; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:partial; 145, binary_operator:*; 145, 146; 145, 151; 146, call; 146, 147; 146, 148; 147, identifier:partial_ratio; 148, argument_list; 148, 149; 148, 150; 149, identifier:p1; 150, identifier:p2; 151, identifier:partial_scale; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:ptsor; 155, binary_operator:*; 155, 156; 155, 167; 156, binary_operator:*; 156, 157; 156, 165; 156, 166; 157, call; 157, 158; 157, 159; 158, identifier:partial_token_sort_ratio; 159, argument_list; 159, 160; 159, 161; 159, 162; 160, identifier:p1; 161, identifier:p2; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:full_process; 164, False; 165, line_continuation:\; 166, identifier:unbase_scale; 167, identifier:partial_scale; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:ptser; 171, binary_operator:*; 171, 172; 171, 183; 172, binary_operator:*; 172, 173; 172, 181; 172, 182; 173, call; 173, 174; 173, 175; 174, identifier:partial_token_set_ratio; 175, argument_list; 175, 176; 175, 177; 175, 178; 176, identifier:p1; 177, identifier:p2; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:full_process; 180, False; 181, line_continuation:\; 182, identifier:unbase_scale; 183, identifier:partial_scale; 184, return_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:utils; 188, identifier:intr; 189, argument_list; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:max; 192, argument_list; 192, 193; 192, 194; 192, 195; 192, 196; 193, identifier:base; 194, identifier:partial; 195, identifier:ptsor; 196, identifier:ptser; 197, else_clause; 197, 198; 198, block; 198, 199; 198, 212; 198, 225; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:tsor; 202, binary_operator:*; 202, 203; 202, 211; 203, call; 203, 204; 203, 205; 204, identifier:token_sort_ratio; 205, argument_list; 205, 206; 205, 207; 205, 208; 206, identifier:p1; 207, identifier:p2; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:full_process; 210, False; 211, identifier:unbase_scale; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:tser; 215, binary_operator:*; 215, 216; 215, 224; 216, call; 216, 217; 216, 218; 217, identifier:token_set_ratio; 218, argument_list; 218, 219; 218, 220; 218, 221; 219, identifier:p1; 220, identifier:p2; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:full_process; 223, False; 224, identifier:unbase_scale; 225, return_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:utils; 229, identifier:intr; 230, argument_list; 230, 231; 231, call; 231, 232; 231, 233; 232, identifier:max; 233, argument_list; 233, 234; 233, 235; 233, 236; 234, identifier:base; 235, identifier:tsor; 236, identifier:tser | def WRatio(s1, s2, force_ascii=True, full_process=True):
if full_process:
p1 = utils.full_process(s1, force_ascii=force_ascii)
p2 = utils.full_process(s2, force_ascii=force_ascii)
else:
p1 = s1
p2 = s2
if not utils.validate_string(p1):
return 0
if not utils.validate_string(p2):
return 0
try_partial = True
unbase_scale = .95
partial_scale = .90
base = ratio(p1, p2)
len_ratio = float(max(len(p1), len(p2))) / min(len(p1), len(p2))
if len_ratio < 1.5:
try_partial = False
if len_ratio > 8:
partial_scale = .6
if try_partial:
partial = partial_ratio(p1, p2) * partial_scale
ptsor = partial_token_sort_ratio(p1, p2, full_process=False) \
* unbase_scale * partial_scale
ptser = partial_token_set_ratio(p1, p2, full_process=False) \
* unbase_scale * partial_scale
return utils.intr(max(base, partial, ptsor, ptser))
else:
tsor = token_sort_ratio(p1, p2, full_process=False) * unbase_scale
tser = token_set_ratio(p1, p2, full_process=False) * unbase_scale
return utils.intr(max(base, tsor, tser)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_depth; 3, parameters; 3, 4; 3, 5; 4, identifier:vals; 5, default_parameter; 5, 6; 5, 7; 6, identifier:reverse; 7, False; 8, block; 8, 9; 8, 28; 8, 44; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:lst; 12, list_comprehension; 12, 13; 12, 19; 13, list:[float(price), quantity]; 13, 14; 13, 18; 14, call; 14, 15; 14, 16; 15, identifier:float; 16, argument_list; 16, 17; 17, identifier:price; 18, identifier:quantity; 19, for_in_clause; 19, 20; 19, 23; 20, pattern_list; 20, 21; 20, 22; 21, identifier:price; 22, identifier:quantity; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:vals; 26, identifier:items; 27, argument_list; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:lst; 31, call; 31, 32; 31, 33; 32, identifier:sorted; 33, argument_list; 33, 34; 33, 35; 33, 41; 34, identifier:lst; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:key; 37, call; 37, 38; 37, 39; 38, identifier:itemgetter; 39, argument_list; 39, 40; 40, integer:0; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:reverse; 43, identifier:reverse; 44, return_statement; 44, 45; 45, identifier:lst | def sort_depth(vals, reverse=False):
lst = [[float(price), quantity] for price, quantity in vals.items()]
lst = sorted(lst, key=itemgetter(0), reverse=reverse)
return lst |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_get_fields; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:attrs; 5, identifier:field_class; 6, default_parameter; 6, 7; 6, 8; 7, identifier:pop; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:ordered; 11, False; 12, block; 12, 13; 12, 34; 12, 47; 12, 66; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:fields; 16, list_comprehension; 16, 17; 16, 20; 16, 28; 17, tuple; 17, 18; 17, 19; 18, identifier:field_name; 19, identifier:field_value; 20, for_in_clause; 20, 21; 20, 24; 21, pattern_list; 21, 22; 21, 23; 22, identifier:field_name; 23, identifier:field_value; 24, call; 24, 25; 24, 26; 25, identifier:iteritems; 26, argument_list; 26, 27; 27, identifier:attrs; 28, if_clause; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:is_instance_or_subclass; 31, argument_list; 31, 32; 31, 33; 32, identifier:field_value; 33, identifier:field_class; 34, if_statement; 34, 35; 34, 36; 35, identifier:pop; 36, block; 36, 37; 37, for_statement; 37, 38; 37, 41; 37, 42; 38, pattern_list; 38, 39; 38, 40; 39, identifier:field_name; 40, identifier:_; 41, identifier:fields; 42, block; 42, 43; 43, delete_statement; 43, 44; 44, subscript; 44, 45; 44, 46; 45, identifier:attrs; 46, identifier:field_name; 47, if_statement; 47, 48; 47, 49; 48, identifier:ordered; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:fields; 54, identifier:sort; 55, argument_list; 55, 56; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:key; 58, lambda; 58, 59; 58, 61; 59, lambda_parameters; 59, 60; 60, identifier:pair; 61, attribute; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:pair; 64, integer:1; 65, identifier:_creation_index; 66, return_statement; 66, 67; 67, identifier:fields | def _get_fields(attrs, field_class, pop=False, ordered=False):
fields = [
(field_name, field_value)
for field_name, field_value in iteritems(attrs)
if is_instance_or_subclass(field_value, field_class)
]
if pop:
for field_name, _ in fields:
del attrs[field_name]
if ordered:
fields.sort(key=lambda pair: pair[1]._creation_index)
return fields |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 66; 2, function_name:extract_features; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 28; 3, 33; 3, 38; 3, 43; 3, 48; 3, 53; 3, 58; 3, 63; 4, identifier:timeseries_container; 5, default_parameter; 5, 6; 5, 7; 6, identifier:default_fc_parameters; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:kind_to_fc_parameters; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:column_id; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:column_sort; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:column_kind; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:column_value; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:chunksize; 25, attribute; 25, 26; 25, 27; 26, identifier:defaults; 27, identifier:CHUNKSIZE; 28, default_parameter; 28, 29; 28, 30; 29, identifier:n_jobs; 30, attribute; 30, 31; 30, 32; 31, identifier:defaults; 32, identifier:N_PROCESSES; 33, default_parameter; 33, 34; 33, 35; 34, identifier:show_warnings; 35, attribute; 35, 36; 35, 37; 36, identifier:defaults; 37, identifier:SHOW_WARNINGS; 38, default_parameter; 38, 39; 38, 40; 39, identifier:disable_progressbar; 40, attribute; 40, 41; 40, 42; 41, identifier:defaults; 42, identifier:DISABLE_PROGRESSBAR; 43, default_parameter; 43, 44; 43, 45; 44, identifier:impute_function; 45, attribute; 45, 46; 45, 47; 46, identifier:defaults; 47, identifier:IMPUTE_FUNCTION; 48, default_parameter; 48, 49; 48, 50; 49, identifier:profile; 50, attribute; 50, 51; 50, 52; 51, identifier:defaults; 52, identifier:PROFILING; 53, default_parameter; 53, 54; 53, 55; 54, identifier:profiling_filename; 55, attribute; 55, 56; 55, 57; 56, identifier:defaults; 57, identifier:PROFILING_FILENAME; 58, default_parameter; 58, 59; 58, 60; 59, identifier:profiling_sorting; 60, attribute; 60, 61; 60, 62; 61, identifier:defaults; 62, identifier:PROFILING_SORTING; 63, default_parameter; 63, 64; 63, 65; 64, identifier:distributor; 65, None; 66, block; 66, 67; 66, 95; 66, 123; 66, 134; 66, 209; 66, 225; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 74; 68, 75; 69, pattern_list; 69, 70; 69, 71; 69, 72; 69, 73; 70, identifier:df_melt; 71, identifier:column_id; 72, identifier:column_kind; 73, identifier:column_value; 74, line_continuation:\; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:dataframe_functions; 78, identifier:_normalize_input_to_internal_representation; 79, argument_list; 79, 80; 79, 83; 79, 86; 79, 89; 79, 92; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:timeseries_container; 82, identifier:timeseries_container; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:column_id; 85, identifier:column_id; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:column_kind; 88, identifier:column_kind; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:column_sort; 91, identifier:column_sort; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:column_value; 94, identifier:column_value; 95, if_statement; 95, 96; 95, 103; 95, 110; 96, boolean_operator:and; 96, 97; 96, 100; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:default_fc_parameters; 99, None; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:kind_to_fc_parameters; 102, None; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:default_fc_parameters; 107, call; 107, 108; 107, 109; 108, identifier:ComprehensiveFCParameters; 109, argument_list; 110, elif_clause; 110, 111; 110, 118; 111, boolean_operator:and; 111, 112; 111, 115; 112, comparison_operator:is; 112, 113; 112, 114; 113, identifier:default_fc_parameters; 114, None; 115, comparison_operator:is; 115, 116; 115, 117; 116, identifier:kind_to_fc_parameters; 117, None; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:default_fc_parameters; 122, dictionary; 123, if_statement; 123, 124; 123, 125; 124, identifier:profile; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:profiler; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:profiling; 132, identifier:start_profiling; 133, argument_list; 134, with_statement; 134, 135; 134, 142; 135, with_clause; 135, 136; 136, with_item; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:warnings; 140, identifier:catch_warnings; 141, argument_list; 142, block; 142, 143; 142, 163; 142, 199; 143, if_statement; 143, 144; 143, 146; 143, 154; 144, not_operator; 144, 145; 145, identifier:show_warnings; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:warnings; 151, identifier:simplefilter; 152, argument_list; 152, 153; 153, string:"ignore"; 154, else_clause; 154, 155; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:warnings; 160, identifier:simplefilter; 161, argument_list; 161, 162; 162, string:"default"; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:result; 166, call; 166, 167; 166, 168; 167, identifier:_do_extraction; 168, argument_list; 168, 169; 168, 172; 168, 175; 168, 178; 168, 181; 168, 184; 168, 187; 168, 190; 168, 193; 168, 196; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:df; 171, identifier:df_melt; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:column_id; 174, identifier:column_id; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:column_value; 177, identifier:column_value; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:column_kind; 180, identifier:column_kind; 181, keyword_argument; 181, 182; 181, 183; 182, identifier:n_jobs; 183, identifier:n_jobs; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:chunk_size; 186, identifier:chunksize; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:disable_progressbar; 189, identifier:disable_progressbar; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:default_fc_parameters; 192, identifier:default_fc_parameters; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:kind_to_fc_parameters; 195, identifier:kind_to_fc_parameters; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:distributor; 198, identifier:distributor; 199, if_statement; 199, 200; 199, 203; 200, comparison_operator:is; 200, 201; 200, 202; 201, identifier:impute_function; 202, None; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:impute_function; 207, argument_list; 207, 208; 208, identifier:result; 209, if_statement; 209, 210; 209, 211; 210, identifier:profile; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:profiling; 216, identifier:end_profiling; 217, argument_list; 217, 218; 217, 219; 217, 222; 218, identifier:profiler; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:filename; 221, identifier:profiling_filename; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:sorting; 224, identifier:profiling_sorting; 225, return_statement; 225, 226; 226, identifier:result | def extract_features(timeseries_container, default_fc_parameters=None,
kind_to_fc_parameters=None,
column_id=None, column_sort=None, column_kind=None, column_value=None,
chunksize=defaults.CHUNKSIZE,
n_jobs=defaults.N_PROCESSES, show_warnings=defaults.SHOW_WARNINGS,
disable_progressbar=defaults.DISABLE_PROGRESSBAR,
impute_function=defaults.IMPUTE_FUNCTION,
profile=defaults.PROFILING,
profiling_filename=defaults.PROFILING_FILENAME,
profiling_sorting=defaults.PROFILING_SORTING,
distributor=None):
df_melt, column_id, column_kind, column_value = \
dataframe_functions._normalize_input_to_internal_representation(
timeseries_container=timeseries_container,
column_id=column_id, column_kind=column_kind,
column_sort=column_sort,
column_value=column_value)
if default_fc_parameters is None and kind_to_fc_parameters is None:
default_fc_parameters = ComprehensiveFCParameters()
elif default_fc_parameters is None and kind_to_fc_parameters is not None:
default_fc_parameters = {}
if profile:
profiler = profiling.start_profiling()
with warnings.catch_warnings():
if not show_warnings:
warnings.simplefilter("ignore")
else:
warnings.simplefilter("default")
result = _do_extraction(df=df_melt,
column_id=column_id, column_value=column_value,
column_kind=column_kind,
n_jobs=n_jobs, chunk_size=chunksize,
disable_progressbar=disable_progressbar,
default_fc_parameters=default_fc_parameters,
kind_to_fc_parameters=kind_to_fc_parameters,
distributor=distributor)
if impute_function is not None:
impute_function(result)
if profile:
profiling.end_profiling(profiler, filename=profiling_filename,
sorting=profiling_sorting)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:convert_to_output_format; 3, parameters; 3, 4; 4, identifier:param; 5, block; 5, 6; 5, 34; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:add_parenthesis_if_string_value; 8, parameters; 8, 9; 9, identifier:x; 10, block; 10, 11; 11, if_statement; 11, 12; 11, 17; 11, 27; 12, call; 12, 13; 12, 14; 13, identifier:isinstance; 14, argument_list; 14, 15; 14, 16; 15, identifier:x; 16, identifier:string_types; 17, block; 17, 18; 18, return_statement; 18, 19; 19, binary_operator:+; 19, 20; 19, 26; 20, binary_operator:+; 20, 21; 20, 22; 21, string:'"'; 22, call; 22, 23; 22, 24; 23, identifier:str; 24, argument_list; 24, 25; 25, identifier:x; 26, string:'"'; 27, else_clause; 27, 28; 28, block; 28, 29; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:str; 32, argument_list; 32, 33; 33, identifier:x; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:"__"; 38, identifier:join; 39, generator_expression; 39, 40; 39, 53; 40, binary_operator:+; 40, 41; 40, 47; 41, binary_operator:+; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:str; 44, argument_list; 44, 45; 45, identifier:key; 46, string:"_"; 47, call; 47, 48; 47, 49; 48, identifier:add_parenthesis_if_string_value; 49, argument_list; 49, 50; 50, subscript; 50, 51; 50, 52; 51, identifier:param; 52, identifier:key; 53, for_in_clause; 53, 54; 53, 55; 54, identifier:key; 55, call; 55, 56; 55, 57; 56, identifier:sorted; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:param; 61, identifier:keys; 62, argument_list | def convert_to_output_format(param):
def add_parenthesis_if_string_value(x):
if isinstance(x, string_types):
return '"' + str(x) + '"'
else:
return str(x)
return "__".join(str(key) + "_" + add_parenthesis_if_string_value(param[key]) for key in sorted(param.keys())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:end_profiling; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:profiler; 5, identifier:filename; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sorting; 8, None; 9, block; 9, 10; 9, 16; 9, 24; 9, 41; 9, 47; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:profiler; 14, identifier:disable; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:s; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:six; 22, identifier:StringIO; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:ps; 27, call; 27, 28; 27, 39; 28, attribute; 28, 29; 28, 38; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:pstats; 32, identifier:Stats; 33, argument_list; 33, 34; 33, 35; 34, identifier:profiler; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:stream; 37, identifier:s; 38, identifier:sort_stats; 39, argument_list; 39, 40; 40, identifier:sorting; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:ps; 45, identifier:print_stats; 46, argument_list; 47, with_statement; 47, 48; 47, 58; 48, with_clause; 48, 49; 49, with_item; 49, 50; 50, as_pattern; 50, 51; 50, 56; 51, call; 51, 52; 51, 53; 52, identifier:open; 53, argument_list; 53, 54; 53, 55; 54, identifier:filename; 55, string:"w+"; 56, as_pattern_target; 56, 57; 57, identifier:f; 58, block; 58, 59; 58, 66; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:_logger; 63, identifier:info; 64, argument_list; 64, 65; 65, string:"[calculate_ts_features] Finished profiling of time series feature extraction"; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:f; 70, identifier:write; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:s; 75, identifier:getvalue; 76, argument_list | def end_profiling(profiler, filename, sorting=None):
profiler.disable()
s = six.StringIO()
ps = pstats.Stats(profiler, stream=s).sort_stats(sorting)
ps.print_stats()
with open(filename, "w+") as f:
_logger.info("[calculate_ts_features] Finished profiling of time series feature extraction")
f.write(s.getvalue()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 95; 2, function_name:extract_relevant_features; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 32; 3, 37; 3, 42; 3, 47; 3, 52; 3, 57; 3, 62; 3, 67; 3, 72; 3, 77; 3, 82; 3, 87; 3, 92; 4, identifier:timeseries_container; 5, identifier:y; 6, default_parameter; 6, 7; 6, 8; 7, identifier:X; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:default_fc_parameters; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:kind_to_fc_parameters; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:column_id; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:column_sort; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:column_kind; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:column_value; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:show_warnings; 29, attribute; 29, 30; 29, 31; 30, identifier:defaults; 31, identifier:SHOW_WARNINGS; 32, default_parameter; 32, 33; 32, 34; 33, identifier:disable_progressbar; 34, attribute; 34, 35; 34, 36; 35, identifier:defaults; 36, identifier:DISABLE_PROGRESSBAR; 37, default_parameter; 37, 38; 37, 39; 38, identifier:profile; 39, attribute; 39, 40; 39, 41; 40, identifier:defaults; 41, identifier:PROFILING; 42, default_parameter; 42, 43; 42, 44; 43, identifier:profiling_filename; 44, attribute; 44, 45; 44, 46; 45, identifier:defaults; 46, identifier:PROFILING_FILENAME; 47, default_parameter; 47, 48; 47, 49; 48, identifier:profiling_sorting; 49, attribute; 49, 50; 49, 51; 50, identifier:defaults; 51, identifier:PROFILING_SORTING; 52, default_parameter; 52, 53; 52, 54; 53, identifier:test_for_binary_target_binary_feature; 54, attribute; 54, 55; 54, 56; 55, identifier:defaults; 56, identifier:TEST_FOR_BINARY_TARGET_BINARY_FEATURE; 57, default_parameter; 57, 58; 57, 59; 58, identifier:test_for_binary_target_real_feature; 59, attribute; 59, 60; 59, 61; 60, identifier:defaults; 61, identifier:TEST_FOR_BINARY_TARGET_REAL_FEATURE; 62, default_parameter; 62, 63; 62, 64; 63, identifier:test_for_real_target_binary_feature; 64, attribute; 64, 65; 64, 66; 65, identifier:defaults; 66, identifier:TEST_FOR_REAL_TARGET_BINARY_FEATURE; 67, default_parameter; 67, 68; 67, 69; 68, identifier:test_for_real_target_real_feature; 69, attribute; 69, 70; 69, 71; 70, identifier:defaults; 71, identifier:TEST_FOR_REAL_TARGET_REAL_FEATURE; 72, default_parameter; 72, 73; 72, 74; 73, identifier:fdr_level; 74, attribute; 74, 75; 74, 76; 75, identifier:defaults; 76, identifier:FDR_LEVEL; 77, default_parameter; 77, 78; 77, 79; 78, identifier:hypotheses_independent; 79, attribute; 79, 80; 79, 81; 80, identifier:defaults; 81, identifier:HYPOTHESES_INDEPENDENT; 82, default_parameter; 82, 83; 82, 84; 83, identifier:n_jobs; 84, attribute; 84, 85; 84, 86; 85, identifier:defaults; 86, identifier:N_PROCESSES; 87, default_parameter; 87, 88; 87, 89; 88, identifier:chunksize; 89, attribute; 89, 90; 89, 91; 90, identifier:defaults; 91, identifier:CHUNKSIZE; 92, default_parameter; 92, 93; 92, 94; 93, identifier:ml_task; 94, string:'auto'; 95, block; 95, 96; 95, 113; 95, 124; 95, 140; 95, 152; 95, 161; 95, 214; 95, 260; 95, 295; 95, 325; 96, assert_statement; 96, 97; 96, 104; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:y; 101, attribute; 101, 102; 101, 103; 102, identifier:pd; 103, identifier:Series; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, string:"y needs to be a pandas.Series, received type: {}."; 107, identifier:format; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:type; 111, argument_list; 111, 112; 112, identifier:y; 113, assert_statement; 113, 114; 113, 123; 114, comparison_operator:>; 114, 115; 114, 122; 115, call; 115, 116; 115, 117; 116, identifier:len; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:set; 120, argument_list; 120, 121; 121, identifier:y; 122, integer:1; 123, string:"Feature selection is only possible if more than 1 label/class is provided"; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:X; 127, None; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:timeseries_container; 132, call; 132, 133; 132, 134; 133, identifier:restrict_input_to_index; 134, argument_list; 134, 135; 134, 136; 134, 137; 135, identifier:timeseries_container; 136, identifier:column_id; 137, attribute; 137, 138; 137, 139; 138, identifier:X; 139, identifier:index; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:ids_container; 143, call; 143, 144; 143, 145; 144, identifier:get_ids; 145, argument_list; 145, 146; 145, 149; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:df_or_dict; 148, identifier:timeseries_container; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:column_id; 151, identifier:column_id; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:ids_y; 155, call; 155, 156; 155, 157; 156, identifier:set; 157, argument_list; 157, 158; 158, attribute; 158, 159; 158, 160; 159, identifier:y; 160, identifier:index; 161, if_statement; 161, 162; 161, 165; 162, comparison_operator:!=; 162, 163; 162, 164; 163, identifier:ids_container; 164, identifier:ids_y; 165, block; 165, 166; 165, 190; 166, if_statement; 166, 167; 166, 175; 167, comparison_operator:>; 167, 168; 167, 174; 168, call; 168, 169; 168, 170; 169, identifier:len; 170, argument_list; 170, 171; 171, binary_operator:-; 171, 172; 171, 173; 172, identifier:ids_container; 173, identifier:ids_y; 174, integer:0; 175, block; 175, 176; 176, raise_statement; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:ValueError; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, concatenated_string; 182, 183; 182, 184; 183, string:"The following ids are in the time series container but are missing in y: "; 184, string:"{}"; 185, identifier:format; 186, argument_list; 186, 187; 187, binary_operator:-; 187, 188; 187, 189; 188, identifier:ids_container; 189, identifier:ids_y; 190, if_statement; 190, 191; 190, 199; 191, comparison_operator:>; 191, 192; 191, 198; 192, call; 192, 193; 192, 194; 193, identifier:len; 194, argument_list; 194, 195; 195, binary_operator:-; 195, 196; 195, 197; 196, identifier:ids_y; 197, identifier:ids_container; 198, integer:0; 199, block; 199, 200; 200, raise_statement; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:ValueError; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 210; 205, attribute; 205, 206; 205, 209; 206, concatenated_string; 206, 207; 206, 208; 207, string:"The following ids are in y but are missing inside the time series container: "; 208, string:"{}"; 209, identifier:format; 210, argument_list; 210, 211; 211, binary_operator:-; 211, 212; 211, 213; 212, identifier:ids_y; 213, identifier:ids_container; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:X_ext; 217, call; 217, 218; 217, 219; 218, identifier:extract_features; 219, argument_list; 219, 220; 219, 221; 219, 224; 219, 227; 219, 230; 219, 233; 219, 236; 219, 239; 219, 242; 219, 245; 219, 248; 219, 251; 219, 254; 219, 257; 220, identifier:timeseries_container; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:default_fc_parameters; 223, identifier:default_fc_parameters; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:kind_to_fc_parameters; 226, identifier:kind_to_fc_parameters; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:show_warnings; 229, identifier:show_warnings; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:disable_progressbar; 232, identifier:disable_progressbar; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:profile; 235, identifier:profile; 236, keyword_argument; 236, 237; 236, 238; 237, identifier:profiling_filename; 238, identifier:profiling_filename; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:profiling_sorting; 241, identifier:profiling_sorting; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:n_jobs; 244, identifier:n_jobs; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:column_id; 247, identifier:column_id; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:column_sort; 250, identifier:column_sort; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:column_kind; 253, identifier:column_kind; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:column_value; 256, identifier:column_value; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:impute_function; 259, identifier:impute; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:X_sel; 263, call; 263, 264; 263, 265; 264, identifier:select_features; 265, argument_list; 265, 266; 265, 267; 265, 268; 265, 271; 265, 274; 265, 277; 265, 280; 265, 283; 265, 286; 265, 289; 265, 292; 266, identifier:X_ext; 267, identifier:y; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:test_for_binary_target_binary_feature; 270, identifier:test_for_binary_target_binary_feature; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:test_for_binary_target_real_feature; 273, identifier:test_for_binary_target_real_feature; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:test_for_real_target_binary_feature; 276, identifier:test_for_real_target_binary_feature; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:test_for_real_target_real_feature; 279, identifier:test_for_real_target_real_feature; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:fdr_level; 282, identifier:fdr_level; 283, keyword_argument; 283, 284; 283, 285; 284, identifier:hypotheses_independent; 285, identifier:hypotheses_independent; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:n_jobs; 288, identifier:n_jobs; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:chunksize; 291, identifier:chunksize; 292, keyword_argument; 292, 293; 292, 294; 293, identifier:ml_task; 294, identifier:ml_task; 295, if_statement; 295, 296; 295, 299; 295, 304; 296, comparison_operator:is; 296, 297; 296, 298; 297, identifier:X; 298, None; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:X; 303, identifier:X_sel; 304, else_clause; 304, 305; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:X; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:pd; 312, identifier:merge; 313, argument_list; 313, 314; 313, 315; 313, 316; 313, 319; 313, 322; 314, identifier:X; 315, identifier:X_sel; 316, keyword_argument; 316, 317; 316, 318; 317, identifier:left_index; 318, True; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:right_index; 321, True; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:how; 324, string:"left"; 325, return_statement; 325, 326; 326, identifier:X | def extract_relevant_features(timeseries_container, y, X=None,
default_fc_parameters=None,
kind_to_fc_parameters=None,
column_id=None, column_sort=None, column_kind=None, column_value=None,
show_warnings=defaults.SHOW_WARNINGS,
disable_progressbar=defaults.DISABLE_PROGRESSBAR,
profile=defaults.PROFILING,
profiling_filename=defaults.PROFILING_FILENAME,
profiling_sorting=defaults.PROFILING_SORTING,
test_for_binary_target_binary_feature=defaults.TEST_FOR_BINARY_TARGET_BINARY_FEATURE,
test_for_binary_target_real_feature=defaults.TEST_FOR_BINARY_TARGET_REAL_FEATURE,
test_for_real_target_binary_feature=defaults.TEST_FOR_REAL_TARGET_BINARY_FEATURE,
test_for_real_target_real_feature=defaults.TEST_FOR_REAL_TARGET_REAL_FEATURE,
fdr_level=defaults.FDR_LEVEL,
hypotheses_independent=defaults.HYPOTHESES_INDEPENDENT,
n_jobs=defaults.N_PROCESSES,
chunksize=defaults.CHUNKSIZE,
ml_task='auto'):
assert isinstance(y, pd.Series), "y needs to be a pandas.Series, received type: {}.".format(type(y))
assert len(set(y)) > 1, "Feature selection is only possible if more than 1 label/class is provided"
if X is not None:
timeseries_container = restrict_input_to_index(timeseries_container, column_id, X.index)
ids_container = get_ids(df_or_dict=timeseries_container, column_id=column_id)
ids_y = set(y.index)
if ids_container != ids_y:
if len(ids_container - ids_y) > 0:
raise ValueError("The following ids are in the time series container but are missing in y: "
"{}".format(ids_container - ids_y))
if len(ids_y - ids_container) > 0:
raise ValueError("The following ids are in y but are missing inside the time series container: "
"{}".format(ids_y - ids_container))
X_ext = extract_features(timeseries_container,
default_fc_parameters=default_fc_parameters,
kind_to_fc_parameters=kind_to_fc_parameters,
show_warnings=show_warnings,
disable_progressbar=disable_progressbar,
profile=profile,
profiling_filename=profiling_filename,
profiling_sorting=profiling_sorting,
n_jobs=n_jobs,
column_id=column_id, column_sort=column_sort,
column_kind=column_kind, column_value=column_value,
impute_function=impute)
X_sel = select_features(X_ext, y,
test_for_binary_target_binary_feature=test_for_binary_target_binary_feature,
test_for_binary_target_real_feature=test_for_binary_target_real_feature,
test_for_real_target_binary_feature=test_for_real_target_binary_feature,
test_for_real_target_real_feature=test_for_real_target_real_feature,
fdr_level=fdr_level, hypotheses_independent=hypotheses_independent,
n_jobs=n_jobs,
chunksize=chunksize,
ml_task=ml_task)
if X is None:
X = X_sel
else:
X = pd.merge(X, X_sel, left_index=True, right_index=True, how="left")
return X |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:user_agents; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, parenthesized_expression; 7, 8; 8, call; 8, 9; 8, 58; 9, attribute; 9, 10; 9, 57; 10, call; 10, 11; 10, 44; 11, attribute; 11, 12; 11, 43; 12, call; 12, 13; 12, 37; 13, attribute; 13, 14; 13, 36; 14, call; 14, 15; 14, 22; 15, attribute; 15, 16; 15, 21; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:get_query; 20, argument_list; 21, identifier:select; 22, argument_list; 22, 23; 22, 28; 23, subscript; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:PageView; 26, identifier:headers; 27, string:'User-Agent'; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:fn; 31, identifier:Count; 32, argument_list; 32, 33; 33, attribute; 33, 34; 33, 35; 34, identifier:PageView; 35, identifier:id; 36, identifier:group_by; 37, argument_list; 37, 38; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:PageView; 41, identifier:headers; 42, string:'User-Agent'; 43, identifier:order_by; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 56; 46, attribute; 46, 47; 46, 55; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:fn; 50, identifier:Count; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:PageView; 54, identifier:id; 55, identifier:desc; 56, argument_list; 57, identifier:tuples; 58, argument_list | def user_agents(self):
return (self.get_query()
.select(
PageView.headers['User-Agent'],
fn.Count(PageView.id))
.group_by(PageView.headers['User-Agent'])
.order_by(fn.Count(PageView.id).desc())
.tuples()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:languages; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 31; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:language; 9, subscript; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:PageView; 12, identifier:headers; 13, string:'Accept-Language'; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:first_language; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:fn; 20, identifier:SubStr; 21, argument_list; 21, 22; 21, 23; 21, 24; 22, identifier:language; 23, integer:1; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:fn; 27, identifier:StrPos; 28, argument_list; 28, 29; 28, 30; 29, identifier:language; 30, string:';'; 31, return_statement; 31, 32; 32, parenthesized_expression; 32, 33; 33, call; 33, 34; 33, 75; 34, attribute; 34, 35; 34, 74; 35, call; 35, 36; 35, 61; 36, attribute; 36, 37; 36, 60; 37, call; 37, 38; 37, 58; 38, attribute; 38, 39; 38, 57; 39, call; 39, 40; 39, 47; 40, attribute; 40, 41; 40, 46; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:get_query; 45, argument_list; 46, identifier:select; 47, argument_list; 47, 48; 47, 49; 48, identifier:first_language; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:fn; 52, identifier:Count; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:PageView; 56, identifier:id; 57, identifier:group_by; 58, argument_list; 58, 59; 59, identifier:first_language; 60, identifier:order_by; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 73; 63, attribute; 63, 64; 63, 72; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:fn; 67, identifier:Count; 68, argument_list; 68, 69; 69, attribute; 69, 70; 69, 71; 70, identifier:PageView; 71, identifier:id; 72, identifier:desc; 73, argument_list; 74, identifier:tuples; 75, argument_list | def languages(self):
language = PageView.headers['Accept-Language']
first_language = fn.SubStr(
language,
1,
fn.StrPos(language, ';'))
return (self.get_query()
.select(first_language, fn.Count(PageView.id))
.group_by(first_language)
.order_by(fn.Count(PageView.id).desc())
.tuples()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:error_router; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:original_handler; 6, identifier:e; 7, block; 7, 8; 7, 28; 8, if_statement; 8, 9; 8, 14; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_has_fr_route; 13, argument_list; 14, block; 14, 15; 15, try_statement; 15, 16; 15, 24; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:handle_error; 22, argument_list; 22, 23; 23, identifier:e; 24, except_clause; 24, 25; 24, 26; 25, identifier:Exception; 26, block; 26, 27; 27, pass_statement; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:original_handler; 31, argument_list; 31, 32; 32, identifier:e | def error_router(self, original_handler, e):
if self._has_fr_route():
try:
return self.handle_error(e)
except Exception:
pass
return original_handler(e) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:smooth_knn_dist; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:distances; 5, identifier:k; 6, default_parameter; 6, 7; 6, 8; 7, identifier:n_iter; 8, integer:64; 9, default_parameter; 9, 10; 9, 11; 10, identifier:local_connectivity; 11, float:1.0; 12, default_parameter; 12, 13; 12, 14; 13, identifier:bandwidth; 14, float:1.0; 15, block; 15, 16; 15, 27; 15, 40; 15, 53; 15, 370; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:target; 19, binary_operator:*; 19, 20; 19, 26; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:np; 23, identifier:log2; 24, argument_list; 24, 25; 25, identifier:k; 26, identifier:bandwidth; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:rho; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:np; 33, identifier:zeros; 34, argument_list; 34, 35; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:distances; 38, identifier:shape; 39, integer:0; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:result; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:zeros; 47, argument_list; 47, 48; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:distances; 51, identifier:shape; 52, integer:0; 53, for_statement; 53, 54; 53, 55; 53, 63; 54, identifier:i; 55, call; 55, 56; 55, 57; 56, identifier:range; 57, argument_list; 57, 58; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:distances; 61, identifier:shape; 62, integer:0; 63, block; 63, 64; 63, 68; 63, 72; 63, 76; 63, 82; 63, 90; 63, 186; 63, 301; 63, 307; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:lo; 67, float:0.0; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:hi; 71, identifier:NPY_INFINITY; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:mid; 75, float:1.0; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:ith_distances; 79, subscript; 79, 80; 79, 81; 80, identifier:distances; 81, identifier:i; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:non_zero_dists; 85, subscript; 85, 86; 85, 87; 86, identifier:ith_distances; 87, comparison_operator:>; 87, 88; 87, 89; 88, identifier:ith_distances; 89, float:0.0; 90, if_statement; 90, 91; 90, 98; 90, 166; 91, comparison_operator:>=; 91, 92; 91, 97; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:non_zero_dists; 95, identifier:shape; 96, integer:0; 97, identifier:local_connectivity; 98, block; 98, 99; 98, 111; 98, 117; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:index; 102, call; 102, 103; 102, 104; 103, identifier:int; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:np; 108, identifier:floor; 109, argument_list; 109, 110; 110, identifier:local_connectivity; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:interpolation; 114, binary_operator:-; 114, 115; 114, 116; 115, identifier:local_connectivity; 116, identifier:index; 117, if_statement; 117, 118; 117, 121; 117, 154; 118, comparison_operator:>; 118, 119; 118, 120; 119, identifier:index; 120, integer:0; 121, block; 121, 122; 121, 132; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:rho; 126, identifier:i; 127, subscript; 127, 128; 127, 129; 128, identifier:non_zero_dists; 129, binary_operator:-; 129, 130; 129, 131; 130, identifier:index; 131, integer:1; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:>; 133, 134; 133, 135; 134, identifier:interpolation; 135, identifier:SMOOTH_K_TOLERANCE; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, augmented_assignment:+=; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:rho; 141, identifier:i; 142, binary_operator:*; 142, 143; 142, 144; 143, identifier:interpolation; 144, parenthesized_expression; 144, 145; 145, binary_operator:-; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:non_zero_dists; 148, identifier:index; 149, subscript; 149, 150; 149, 151; 150, identifier:non_zero_dists; 151, binary_operator:-; 151, 152; 151, 153; 152, identifier:index; 153, integer:1; 154, else_clause; 154, 155; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:rho; 160, identifier:i; 161, binary_operator:*; 161, 162; 161, 163; 162, identifier:interpolation; 163, subscript; 163, 164; 163, 165; 164, identifier:non_zero_dists; 165, integer:0; 166, elif_clause; 166, 167; 166, 174; 167, comparison_operator:>; 167, 168; 167, 173; 168, subscript; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:non_zero_dists; 171, identifier:shape; 172, integer:0; 173, integer:0; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:rho; 179, identifier:i; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:np; 183, identifier:max; 184, argument_list; 184, 185; 185, identifier:non_zero_dists; 186, for_statement; 186, 187; 186, 188; 186, 192; 187, identifier:n; 188, call; 188, 189; 188, 190; 189, identifier:range; 190, argument_list; 190, 191; 191, identifier:n_iter; 192, block; 192, 193; 192, 197; 192, 244; 192, 257; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:psum; 196, float:0.0; 197, for_statement; 197, 198; 197, 199; 197, 208; 198, identifier:j; 199, call; 199, 200; 199, 201; 200, identifier:range; 201, argument_list; 201, 202; 201, 203; 202, integer:1; 203, subscript; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:distances; 206, identifier:shape; 207, integer:1; 208, block; 208, 209; 208, 220; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:d; 212, binary_operator:-; 212, 213; 212, 217; 213, subscript; 213, 214; 213, 215; 213, 216; 214, identifier:distances; 215, identifier:i; 216, identifier:j; 217, subscript; 217, 218; 217, 219; 218, identifier:rho; 219, identifier:i; 220, if_statement; 220, 221; 220, 224; 220, 238; 221, comparison_operator:>; 221, 222; 221, 223; 222, identifier:d; 223, integer:0; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, augmented_assignment:+=; 226, 227; 226, 228; 227, identifier:psum; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:np; 231, identifier:exp; 232, argument_list; 232, 233; 233, unary_operator:-; 233, 234; 234, parenthesized_expression; 234, 235; 235, binary_operator:/; 235, 236; 235, 237; 236, identifier:d; 237, identifier:mid; 238, else_clause; 238, 239; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, augmented_assignment:+=; 241, 242; 241, 243; 242, identifier:psum; 243, float:1.0; 244, if_statement; 244, 245; 244, 255; 245, comparison_operator:<; 245, 246; 245, 254; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:np; 249, identifier:fabs; 250, argument_list; 250, 251; 251, binary_operator:-; 251, 252; 251, 253; 252, identifier:psum; 253, identifier:target; 254, identifier:SMOOTH_K_TOLERANCE; 255, block; 255, 256; 256, break_statement; 257, if_statement; 257, 258; 257, 261; 257, 275; 258, comparison_operator:>; 258, 259; 258, 260; 259, identifier:psum; 260, identifier:target; 261, block; 261, 262; 261, 266; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:hi; 265, identifier:mid; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:mid; 269, binary_operator:/; 269, 270; 269, 274; 270, parenthesized_expression; 270, 271; 271, binary_operator:+; 271, 272; 271, 273; 272, identifier:lo; 273, identifier:hi; 274, float:2.0; 275, else_clause; 275, 276; 276, block; 276, 277; 276, 281; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:lo; 280, identifier:mid; 281, if_statement; 281, 282; 281, 285; 281, 290; 282, comparison_operator:==; 282, 283; 282, 284; 283, identifier:hi; 284, identifier:NPY_INFINITY; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, augmented_assignment:*=; 287, 288; 287, 289; 288, identifier:mid; 289, integer:2; 290, else_clause; 290, 291; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:mid; 295, binary_operator:/; 295, 296; 295, 300; 296, parenthesized_expression; 296, 297; 297, binary_operator:+; 297, 298; 297, 299; 298, identifier:lo; 299, identifier:hi; 300, float:2.0; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 306; 303, subscript; 303, 304; 303, 305; 304, identifier:result; 305, identifier:i; 306, identifier:mid; 307, if_statement; 307, 308; 307, 313; 307, 341; 308, comparison_operator:>; 308, 309; 308, 312; 309, subscript; 309, 310; 309, 311; 310, identifier:rho; 311, identifier:i; 312, float:0.0; 313, block; 313, 314; 314, if_statement; 314, 315; 314, 327; 315, comparison_operator:<; 315, 316; 315, 319; 316, subscript; 316, 317; 316, 318; 317, identifier:result; 318, identifier:i; 319, binary_operator:*; 319, 320; 319, 321; 320, identifier:MIN_K_DIST_SCALE; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:np; 324, identifier:mean; 325, argument_list; 325, 326; 326, identifier:ith_distances; 327, block; 327, 328; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 333; 330, subscript; 330, 331; 330, 332; 331, identifier:result; 332, identifier:i; 333, binary_operator:*; 333, 334; 333, 335; 334, identifier:MIN_K_DIST_SCALE; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:np; 338, identifier:mean; 339, argument_list; 339, 340; 340, identifier:ith_distances; 341, else_clause; 341, 342; 342, block; 342, 343; 343, if_statement; 343, 344; 343, 356; 344, comparison_operator:<; 344, 345; 344, 348; 345, subscript; 345, 346; 345, 347; 346, identifier:result; 347, identifier:i; 348, binary_operator:*; 348, 349; 348, 350; 349, identifier:MIN_K_DIST_SCALE; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:np; 353, identifier:mean; 354, argument_list; 354, 355; 355, identifier:distances; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, assignment; 358, 359; 358, 362; 359, subscript; 359, 360; 359, 361; 360, identifier:result; 361, identifier:i; 362, binary_operator:*; 362, 363; 362, 364; 363, identifier:MIN_K_DIST_SCALE; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:np; 367, identifier:mean; 368, argument_list; 368, 369; 369, identifier:distances; 370, return_statement; 370, 371; 371, expression_list; 371, 372; 371, 373; 372, identifier:result; 373, identifier:rho | def smooth_knn_dist(distances, k, n_iter=64, local_connectivity=1.0, bandwidth=1.0):
target = np.log2(k) * bandwidth
rho = np.zeros(distances.shape[0])
result = np.zeros(distances.shape[0])
for i in range(distances.shape[0]):
lo = 0.0
hi = NPY_INFINITY
mid = 1.0
ith_distances = distances[i]
non_zero_dists = ith_distances[ith_distances > 0.0]
if non_zero_dists.shape[0] >= local_connectivity:
index = int(np.floor(local_connectivity))
interpolation = local_connectivity - index
if index > 0:
rho[i] = non_zero_dists[index - 1]
if interpolation > SMOOTH_K_TOLERANCE:
rho[i] += interpolation * (non_zero_dists[index] - non_zero_dists[index - 1])
else:
rho[i] = interpolation * non_zero_dists[0]
elif non_zero_dists.shape[0] > 0:
rho[i] = np.max(non_zero_dists)
for n in range(n_iter):
psum = 0.0
for j in range(1, distances.shape[1]):
d = distances[i, j] - rho[i]
if d > 0:
psum += np.exp(-(d / mid))
else:
psum += 1.0
if np.fabs(psum - target) < SMOOTH_K_TOLERANCE:
break
if psum > target:
hi = mid
mid = (lo + hi) / 2.0
else:
lo = mid
if hi == NPY_INFINITY:
mid *= 2
else:
mid = (lo + hi) / 2.0
result[i] = mid
if rho[i] > 0.0:
if result[i] < MIN_K_DIST_SCALE * np.mean(ith_distances):
result[i] = MIN_K_DIST_SCALE * np.mean(ith_distances)
else:
if result[i] < MIN_K_DIST_SCALE * np.mean(distances):
result[i] = MIN_K_DIST_SCALE * np.mean(distances)
return result, rho |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_visible_units; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 43; 7, identifier:u; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 10, 20; 11, attribute; 11, 12; 11, 19; 12, attribute; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_obs; 17, identifier:observation; 18, identifier:raw_data; 19, identifier:units; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:key; 22, lambda; 22, 23; 22, 25; 23, lambda_parameters; 23, 24; 24, identifier:u; 25, tuple; 25, 26; 25, 31; 25, 36; 25, 40; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:u; 29, identifier:pos; 30, identifier:z; 31, comparison_operator:!=; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:u; 34, identifier:owner; 35, integer:16; 36, unary_operator:-; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:u; 39, identifier:radius; 40, attribute; 40, 41; 40, 42; 41, identifier:u; 42, identifier:tag; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, yield; 45, 46; 46, expression_list; 46, 47; 46, 48; 47, identifier:u; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:point; 52, identifier:Point; 53, identifier:build; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:u; 57, identifier:pos | def _visible_units(self):
for u in sorted(self._obs.observation.raw_data.units,
key=lambda u: (u.pos.z, u.owner != 16, -u.radius, u.tag)):
yield u, point.Point.build(u.pos) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:interp; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:coords; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:method; 10, string:'linear'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:assume_sorted; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:kwargs; 16, dictionary; 17, dictionary_splat_pattern; 17, 18; 18, identifier:coords_kwargs; 19, block; 19, 20; 19, 43; 19, 67; 20, if_statement; 20, 21; 20, 28; 21, comparison_operator:not; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:dtype; 26, identifier:kind; 27, string:'uifc'; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:TypeError; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, concatenated_string; 35, 36; 35, 37; 36, string:'interp only works for a numeric type array. '; 37, string:'Given {}.'; 38, identifier:format; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:dtype; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:ds; 46, call; 46, 47; 46, 54; 47, attribute; 47, 48; 47, 53; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_to_temp_dataset; 52, argument_list; 53, identifier:interp; 54, argument_list; 54, 55; 54, 56; 54, 59; 54, 62; 54, 65; 55, identifier:coords; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:method; 58, identifier:method; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:kwargs; 61, identifier:kwargs; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:assume_sorted; 64, identifier:assume_sorted; 65, dictionary_splat; 65, 66; 66, identifier:coords_kwargs; 67, return_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_from_temp_dataset; 72, argument_list; 72, 73; 73, identifier:ds | def interp(self, coords=None, method='linear', assume_sorted=False,
kwargs={}, **coords_kwargs):
if self.dtype.kind not in 'uifc':
raise TypeError('interp only works for a numeric type array. '
'Given {}.'.format(self.dtype))
ds = self._to_temp_dataset().interp(
coords, method=method, kwargs=kwargs, assume_sorted=assume_sorted,
**coords_kwargs)
return self._from_temp_dataset(ds) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:interp_like; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:other; 6, default_parameter; 6, 7; 6, 8; 7, identifier:method; 8, string:'linear'; 9, default_parameter; 9, 10; 9, 11; 10, identifier:assume_sorted; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:kwargs; 14, dictionary; 15, block; 15, 16; 15, 39; 15, 61; 16, if_statement; 16, 17; 16, 24; 17, comparison_operator:not; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:dtype; 22, identifier:kind; 23, string:'uifc'; 24, block; 24, 25; 25, raise_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:TypeError; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, concatenated_string; 31, 32; 31, 33; 32, string:'interp only works for a numeric type array. '; 33, string:'Given {}.'; 34, identifier:format; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:dtype; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:ds; 42, call; 42, 43; 42, 50; 43, attribute; 43, 44; 43, 49; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_to_temp_dataset; 48, argument_list; 49, identifier:interp_like; 50, argument_list; 50, 51; 50, 52; 50, 55; 50, 58; 51, identifier:other; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:method; 54, identifier:method; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:kwargs; 57, identifier:kwargs; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:assume_sorted; 60, identifier:assume_sorted; 61, return_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_from_temp_dataset; 66, argument_list; 66, 67; 67, identifier:ds | def interp_like(self, other, method='linear', assume_sorted=False,
kwargs={}):
if self.dtype.kind not in 'uifc':
raise TypeError('interp only works for a numeric type array. '
'Given {}.'.format(self.dtype))
ds = self._to_temp_dataset().interp_like(
other, method=method, kwargs=kwargs, assume_sorted=assume_sorted)
return self._from_temp_dataset(ds) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 1, 9; 2, function_name:is_uniform_spaced; 3, parameters; 3, 4; 3, 5; 4, identifier:arr; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, type; 7, 8; 8, identifier:bool; 9, block; 9, 10; 9, 22; 9, 31; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:arr; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:np; 16, identifier:array; 17, argument_list; 17, 18; 17, 19; 18, identifier:arr; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:dtype; 21, identifier:float; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:diffs; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:diff; 29, argument_list; 29, 30; 30, identifier:arr; 31, return_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:bool; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:np; 38, identifier:isclose; 39, argument_list; 39, 40; 39, 45; 39, 50; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:diffs; 43, identifier:min; 44, argument_list; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:diffs; 48, identifier:max; 49, argument_list; 50, dictionary_splat; 50, 51; 51, identifier:kwargs | def is_uniform_spaced(arr, **kwargs) -> bool:
arr = np.array(arr, dtype=float)
diffs = np.diff(arr)
return bool(np.isclose(diffs.min(), diffs.max(), **kwargs)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:broadcast_variables; 3, parameters; 3, 4; 4, list_splat_pattern; 4, 5; 5, identifier:variables; 6, block; 6, 7; 6, 14; 6, 21; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:dims_map; 10, call; 10, 11; 10, 12; 11, identifier:_unified_dims; 12, argument_list; 12, 13; 13, identifier:variables; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:dims_tuple; 17, call; 17, 18; 17, 19; 18, identifier:tuple; 19, argument_list; 19, 20; 20, identifier:dims_map; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:tuple; 24, generator_expression; 24, 25; 24, 38; 25, conditional_expression:if; 25, 26; 25, 32; 25, 37; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:var; 29, identifier:set_dims; 30, argument_list; 30, 31; 31, identifier:dims_map; 32, comparison_operator:!=; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:var; 35, identifier:dims; 36, identifier:dims_tuple; 37, identifier:var; 38, for_in_clause; 38, 39; 38, 40; 39, identifier:var; 40, identifier:variables | def broadcast_variables(*variables):
dims_map = _unified_dims(variables)
dims_tuple = tuple(dims_map)
return tuple(var.set_dims(dims_map) if var.dims != dims_tuple else var
for var in variables) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:interp; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:coords; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:method; 10, string:'linear'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:assume_sorted; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:kwargs; 16, dictionary; 17, dictionary_splat_pattern; 17, 18; 18, identifier:coords_kwargs; 19, block; 19, 20; 19, 25; 19, 34; 19, 46; 19, 62; 19, 93; 19, 133; 19, 139; 19, 229; 19, 243; 19, 267; 19, 284; 19, 291; 19, 320; 19, 332; 19, 339; 19, 346; 19, 366; 20, import_from_statement; 20, 21; 20, 23; 21, relative_import; 21, 22; 22, import_prefix; 23, dotted_name; 23, 24; 24, identifier:missing; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:coords; 28, call; 28, 29; 28, 30; 29, identifier:either_dict_or_kwargs; 30, argument_list; 30, 31; 30, 32; 30, 33; 31, identifier:coords; 32, identifier:coords_kwargs; 33, string:'interp'; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:indexers; 37, call; 37, 38; 37, 39; 38, identifier:OrderedDict; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:_validate_indexers; 44, argument_list; 44, 45; 45, identifier:coords; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:obj; 49, conditional_expression:if; 49, 50; 49, 51; 49, 52; 50, identifier:self; 51, identifier:assume_sorted; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:sortby; 56, argument_list; 56, 57; 57, list_comprehension; 57, 58; 57, 59; 58, identifier:k; 59, for_in_clause; 59, 60; 59, 61; 60, identifier:k; 61, identifier:coords; 62, function_definition; 62, 63; 62, 64; 62, 67; 63, function_name:maybe_variable; 64, parameters; 64, 65; 64, 66; 65, identifier:obj; 66, identifier:k; 67, block; 67, 68; 68, try_statement; 68, 69; 68, 76; 69, block; 69, 70; 70, return_statement; 70, 71; 71, subscript; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:obj; 74, identifier:_variables; 75, identifier:k; 76, except_clause; 76, 77; 76, 78; 77, identifier:KeyError; 78, block; 78, 79; 79, return_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:as_variable; 82, argument_list; 82, 83; 83, tuple; 83, 84; 83, 85; 84, identifier:k; 85, call; 85, 86; 85, 87; 86, identifier:range; 87, argument_list; 87, 88; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:obj; 91, identifier:dims; 92, identifier:k; 93, function_definition; 93, 94; 93, 95; 93, 98; 94, function_name:_validate_interp_indexer; 95, parameters; 95, 96; 95, 97; 96, identifier:x; 97, identifier:new_x; 98, block; 98, 99; 99, if_statement; 99, 100; 99, 111; 99, 127; 100, parenthesized_expression; 100, 101; 101, boolean_operator:and; 101, 102; 101, 106; 102, call; 102, 103; 102, 104; 103, identifier:_contains_datetime_like_objects; 104, argument_list; 104, 105; 105, identifier:x; 106, not_operator; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:_contains_datetime_like_objects; 109, argument_list; 109, 110; 110, identifier:new_x; 111, block; 111, 112; 112, raise_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:TypeError; 115, argument_list; 115, 116; 116, call; 116, 117; 116, 125; 117, attribute; 117, 118; 117, 124; 118, concatenated_string; 118, 119; 118, 120; 118, 121; 118, 122; 118, 123; 119, string:'When interpolating over a datetime-like '; 120, string:'coordinate, the coordinates to '; 121, string:'interpolate to must be either datetime '; 122, string:'strings or datetimes. '; 123, string:'Instead got\n{}'; 124, identifier:format; 125, argument_list; 125, 126; 126, identifier:new_x; 127, else_clause; 127, 128; 128, block; 128, 129; 129, return_statement; 129, 130; 130, tuple; 130, 131; 130, 132; 131, identifier:x; 132, identifier:new_x; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:variables; 136, call; 136, 137; 136, 138; 137, identifier:OrderedDict; 138, argument_list; 139, for_statement; 139, 140; 139, 143; 139, 150; 140, pattern_list; 140, 141; 140, 142; 141, identifier:name; 142, identifier:var; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:obj; 147, identifier:_variables; 148, identifier:items; 149, argument_list; 150, block; 150, 151; 151, if_statement; 151, 152; 151, 155; 152, comparison_operator:not; 152, 153; 152, 154; 153, identifier:name; 154, identifier:indexers; 155, block; 155, 156; 156, if_statement; 156, 157; 156, 164; 156, 210; 157, comparison_operator:in; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:var; 161, identifier:dtype; 162, identifier:kind; 163, string:'uifc'; 164, block; 164, 165; 164, 195; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:var_indexers; 168, dictionary_comprehension; 168, 169; 168, 180; 168, 189; 169, pair; 169, 170; 169, 171; 170, identifier:k; 171, call; 171, 172; 171, 173; 172, identifier:_validate_interp_indexer; 173, argument_list; 173, 174; 173, 179; 174, call; 174, 175; 174, 176; 175, identifier:maybe_variable; 176, argument_list; 176, 177; 176, 178; 177, identifier:obj; 178, identifier:k; 179, identifier:v; 180, for_in_clause; 180, 181; 180, 184; 181, pattern_list; 181, 182; 181, 183; 182, identifier:k; 183, identifier:v; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:indexers; 187, identifier:items; 188, argument_list; 189, if_clause; 189, 190; 190, comparison_operator:in; 190, 191; 190, 192; 191, identifier:k; 192, attribute; 192, 193; 192, 194; 193, identifier:var; 194, identifier:dims; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:variables; 199, identifier:name; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:missing; 203, identifier:interp; 204, argument_list; 204, 205; 204, 206; 204, 207; 204, 208; 205, identifier:var; 206, identifier:var_indexers; 207, identifier:method; 208, dictionary_splat; 208, 209; 209, identifier:kwargs; 210, elif_clause; 210, 211; 210, 222; 211, call; 211, 212; 211, 213; 212, identifier:all; 213, generator_expression; 213, 214; 213, 217; 214, comparison_operator:not; 214, 215; 214, 216; 215, identifier:d; 216, identifier:indexers; 217, for_in_clause; 217, 218; 217, 219; 218, identifier:d; 219, attribute; 219, 220; 219, 221; 220, identifier:var; 221, identifier:dims; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:variables; 227, identifier:name; 228, identifier:var; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:coord_names; 232, call; 232, 233; 232, 239; 233, attribute; 233, 234; 233, 238; 234, call; 234, 235; 234, 236; 235, identifier:set; 236, argument_list; 236, 237; 237, identifier:variables; 238, identifier:intersection; 239, argument_list; 239, 240; 240, attribute; 240, 241; 240, 242; 241, identifier:obj; 242, identifier:_coord_names; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:indexes; 246, call; 246, 247; 246, 248; 247, identifier:OrderedDict; 248, generator_expression; 248, 249; 248, 252; 248, 263; 249, tuple; 249, 250; 249, 251; 250, identifier:k; 251, identifier:v; 252, for_in_clause; 252, 253; 252, 256; 253, pattern_list; 253, 254; 253, 255; 254, identifier:k; 255, identifier:v; 256, call; 256, 257; 256, 262; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:obj; 260, identifier:indexes; 261, identifier:items; 262, argument_list; 263, if_clause; 263, 264; 264, comparison_operator:not; 264, 265; 264, 266; 265, identifier:k; 266, identifier:indexers; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:selected; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:self; 273, identifier:_replace_with_new_dims; 274, argument_list; 274, 275; 274, 280; 274, 281; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:variables; 278, identifier:copy; 279, argument_list; 280, identifier:coord_names; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:indexes; 283, identifier:indexes; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:variables; 288, identifier:update; 289, argument_list; 289, 290; 290, identifier:indexers; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:indexes; 295, identifier:update; 296, generator_expression; 296, 297; 296, 304; 296, 313; 297, tuple; 297, 298; 297, 299; 298, identifier:k; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:v; 302, identifier:to_index; 303, argument_list; 304, for_in_clause; 304, 305; 304, 308; 305, pattern_list; 305, 306; 305, 307; 306, identifier:k; 307, identifier:v; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:indexers; 311, identifier:items; 312, argument_list; 313, if_clause; 313, 314; 314, comparison_operator:==; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:v; 317, identifier:dims; 318, tuple; 318, 319; 319, identifier:k; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 325; 322, pattern_list; 322, 323; 322, 324; 323, identifier:coord_vars; 324, identifier:new_indexes; 325, parenthesized_expression; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:selected; 329, identifier:_get_indexers_coords_and_indexes; 330, argument_list; 330, 331; 331, identifier:coords; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:variables; 336, identifier:update; 337, argument_list; 337, 338; 338, identifier:coord_vars; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:indexes; 343, identifier:update; 344, argument_list; 344, 345; 345, identifier:new_indexes; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 349; 348, identifier:coord_names; 349, parenthesized_expression; 349, 350; 350, call; 350, 351; 350, 364; 351, attribute; 351, 352; 351, 363; 352, call; 352, 353; 352, 359; 353, attribute; 353, 354; 353, 358; 354, call; 354, 355; 354, 356; 355, identifier:set; 356, argument_list; 356, 357; 357, identifier:variables; 358, identifier:intersection; 359, argument_list; 359, 360; 360, attribute; 360, 361; 360, 362; 361, identifier:obj; 362, identifier:_coord_names; 363, identifier:union; 364, argument_list; 364, 365; 365, identifier:coord_vars; 366, return_statement; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:self; 370, identifier:_replace_with_new_dims; 371, argument_list; 371, 372; 371, 373; 371, 374; 372, identifier:variables; 373, identifier:coord_names; 374, keyword_argument; 374, 375; 374, 376; 375, identifier:indexes; 376, identifier:indexes | def interp(self, coords=None, method='linear', assume_sorted=False,
kwargs={}, **coords_kwargs):
from . import missing
coords = either_dict_or_kwargs(coords, coords_kwargs, 'interp')
indexers = OrderedDict(self._validate_indexers(coords))
obj = self if assume_sorted else self.sortby([k for k in coords])
def maybe_variable(obj, k):
try:
return obj._variables[k]
except KeyError:
return as_variable((k, range(obj.dims[k])))
def _validate_interp_indexer(x, new_x):
if (_contains_datetime_like_objects(x) and
not _contains_datetime_like_objects(new_x)):
raise TypeError('When interpolating over a datetime-like '
'coordinate, the coordinates to '
'interpolate to must be either datetime '
'strings or datetimes. '
'Instead got\n{}'.format(new_x))
else:
return (x, new_x)
variables = OrderedDict()
for name, var in obj._variables.items():
if name not in indexers:
if var.dtype.kind in 'uifc':
var_indexers = {
k: _validate_interp_indexer(maybe_variable(obj, k), v)
for k, v in indexers.items()
if k in var.dims
}
variables[name] = missing.interp(
var, var_indexers, method, **kwargs)
elif all(d not in indexers for d in var.dims):
variables[name] = var
coord_names = set(variables).intersection(obj._coord_names)
indexes = OrderedDict(
(k, v) for k, v in obj.indexes.items() if k not in indexers)
selected = self._replace_with_new_dims(
variables.copy(), coord_names, indexes=indexes)
variables.update(indexers)
indexes.update(
(k, v.to_index()) for k, v in indexers.items() if v.dims == (k,)
)
coord_vars, new_indexes = (
selected._get_indexers_coords_and_indexes(coords))
variables.update(coord_vars)
indexes.update(new_indexes)
coord_names = (set(variables)
.intersection(obj._coord_names)
.union(coord_vars))
return self._replace_with_new_dims(
variables, coord_names, indexes=indexes) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:interp_like; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:other; 6, default_parameter; 6, 7; 6, 8; 7, identifier:method; 8, string:'linear'; 9, default_parameter; 9, 10; 9, 11; 10, identifier:assume_sorted; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:kwargs; 14, dictionary; 15, block; 15, 16; 15, 26; 15, 32; 15, 38; 15, 71; 15, 75; 15, 87; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:coords; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:alignment; 22, identifier:reindex_like_indexers; 23, argument_list; 23, 24; 23, 25; 24, identifier:self; 25, identifier:other; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:numeric_coords; 29, call; 29, 30; 29, 31; 30, identifier:OrderedDict; 31, argument_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:object_coords; 35, call; 35, 36; 35, 37; 36, identifier:OrderedDict; 37, argument_list; 38, for_statement; 38, 39; 38, 42; 38, 47; 39, pattern_list; 39, 40; 39, 41; 40, identifier:k; 41, identifier:v; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:coords; 45, identifier:items; 46, argument_list; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 56; 48, 63; 49, comparison_operator:in; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:v; 53, identifier:dtype; 54, identifier:kind; 55, string:'uifcMm'; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, subscript; 59, 60; 59, 61; 60, identifier:numeric_coords; 61, identifier:k; 62, identifier:v; 63, else_clause; 63, 64; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:object_coords; 69, identifier:k; 70, identifier:v; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:ds; 74, identifier:self; 75, if_statement; 75, 76; 75, 77; 76, identifier:object_coords; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:ds; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:reindex; 85, argument_list; 85, 86; 86, identifier:object_coords; 87, return_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:ds; 91, identifier:interp; 92, argument_list; 92, 93; 92, 94; 92, 95; 92, 96; 93, identifier:numeric_coords; 94, identifier:method; 95, identifier:assume_sorted; 96, identifier:kwargs | def interp_like(self, other, method='linear', assume_sorted=False,
kwargs={}):
coords = alignment.reindex_like_indexers(self, other)
numeric_coords = OrderedDict()
object_coords = OrderedDict()
for k, v in coords.items():
if v.dtype.kind in 'uifcMm':
numeric_coords[k] = v
else:
object_coords[k] = v
ds = self
if object_coords:
ds = self.reindex(object_coords)
return ds.interp(numeric_coords, method, assume_sorted, kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:transpose; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:dims; 7, block; 7, 8; 7, 40; 7, 48; 7, 90; 8, if_statement; 8, 9; 8, 10; 9, identifier:dims; 10, block; 10, 11; 11, if_statement; 11, 12; 11, 23; 12, binary_operator:^; 12, 13; 12, 17; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 15, 16; 16, identifier:dims; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:dims; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:ValueError; 27, argument_list; 27, 28; 28, binary_operator:%; 28, 29; 28, 32; 29, concatenated_string; 29, 30; 29, 31; 30, string:'arguments to transpose (%s) must be '; 31, string:'permuted dataset dimensions (%s)'; 32, tuple; 32, 33; 32, 34; 33, identifier:dims; 34, call; 34, 35; 34, 36; 35, identifier:tuple; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:dims; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ds; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:copy; 47, argument_list; 48, for_statement; 48, 49; 48, 52; 48, 59; 49, pattern_list; 49, 50; 49, 51; 50, identifier:name; 51, identifier:var; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_variables; 57, identifier:items; 58, argument_list; 59, block; 59, 60; 59, 76; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:var_dims; 63, call; 63, 64; 63, 65; 64, identifier:tuple; 65, generator_expression; 65, 66; 65, 67; 65, 70; 66, identifier:dim; 67, for_in_clause; 67, 68; 67, 69; 68, identifier:dim; 69, identifier:dims; 70, if_clause; 70, 71; 71, comparison_operator:in; 71, 72; 71, 73; 72, identifier:dim; 73, attribute; 73, 74; 73, 75; 74, identifier:var; 75, identifier:dims; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 83; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:ds; 81, identifier:_variables; 82, identifier:name; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:var; 86, identifier:transpose; 87, argument_list; 87, 88; 88, list_splat; 88, 89; 89, identifier:var_dims; 90, return_statement; 90, 91; 91, identifier:ds | def transpose(self, *dims):
if dims:
if set(dims) ^ set(self.dims):
raise ValueError('arguments to transpose (%s) must be '
'permuted dataset dimensions (%s)'
% (dims, tuple(self.dims)))
ds = self.copy()
for name, var in self._variables.items():
var_dims = tuple(dim for dim in dims if dim in var.dims)
ds._variables[name] = var.transpose(*var_dims)
return ds |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:to_dask_dataframe; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:dim_order; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:set_index; 10, False; 11, block; 11, 12; 11, 18; 11, 24; 11, 69; 11, 85; 11, 92; 11, 110; 11, 119; 11, 123; 11, 233; 11, 245; 11, 281; 12, import_statement; 12, 13; 13, aliased_import; 13, 14; 13, 17; 14, dotted_name; 14, 15; 14, 16; 15, identifier:dask; 16, identifier:array; 17, identifier:da; 18, import_statement; 18, 19; 19, aliased_import; 19, 20; 19, 23; 20, dotted_name; 20, 21; 20, 22; 21, identifier:dask; 22, identifier:dataframe; 23, identifier:dd; 24, if_statement; 24, 25; 24, 28; 24, 38; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:dim_order; 27, None; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:dim_order; 32, call; 32, 33; 32, 34; 33, identifier:list; 34, argument_list; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:dims; 38, elif_clause; 38, 39; 38, 50; 39, comparison_operator:!=; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:set; 42, argument_list; 42, 43; 43, identifier:dim_order; 44, call; 44, 45; 44, 46; 45, identifier:set; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:dims; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:ValueError; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, concatenated_string; 57, 58; 57, 59; 58, string:'dim_order {} does not match the set of dimensions on this '; 59, string:'Dataset: {}'; 60, identifier:format; 61, argument_list; 61, 62; 61, 63; 62, identifier:dim_order; 63, call; 63, 64; 63, 65; 64, identifier:list; 65, argument_list; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:dims; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:ordered_dims; 72, call; 72, 73; 72, 74; 73, identifier:OrderedDict; 74, generator_expression; 74, 75; 74, 82; 75, tuple; 75, 76; 75, 77; 76, identifier:k; 77, subscript; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:dims; 81, identifier:k; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:k; 84, identifier:dim_order; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:columns; 88, call; 88, 89; 88, 90; 89, identifier:list; 90, argument_list; 90, 91; 91, identifier:ordered_dims; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:columns; 96, identifier:extend; 97, generator_expression; 97, 98; 97, 99; 97, 104; 98, identifier:k; 99, for_in_clause; 99, 100; 99, 101; 100, identifier:k; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:coords; 104, if_clause; 104, 105; 105, comparison_operator:not; 105, 106; 105, 107; 106, identifier:k; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:dims; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:columns; 114, identifier:extend; 115, argument_list; 115, 116; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:data_vars; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:series_list; 122, list:[]; 123, for_statement; 123, 124; 123, 125; 123, 126; 124, identifier:name; 125, identifier:columns; 126, block; 126, 127; 126, 174; 126, 189; 126, 207; 126, 226; 127, try_statement; 127, 128; 127, 137; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:var; 132, subscript; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:variables; 136, identifier:name; 137, except_clause; 137, 138; 137, 139; 138, identifier:KeyError; 139, block; 139, 140; 139, 148; 139, 165; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:size; 143, subscript; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:dims; 147, identifier:name; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:data; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:da; 154, identifier:arange; 155, argument_list; 155, 156; 155, 157; 155, 160; 156, identifier:size; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:chunks; 159, identifier:size; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:dtype; 162, attribute; 162, 163; 162, 164; 163, identifier:np; 164, identifier:int64; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:var; 168, call; 168, 169; 168, 170; 169, identifier:Variable; 170, argument_list; 170, 171; 170, 173; 171, tuple; 171, 172; 172, identifier:name; 173, identifier:data; 174, if_statement; 174, 175; 174, 180; 175, call; 175, 176; 175, 177; 176, identifier:isinstance; 177, argument_list; 177, 178; 177, 179; 178, identifier:var; 179, identifier:IndexVariable; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:var; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:var; 187, identifier:to_base_variable; 188, argument_list; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:dask_array; 192, attribute; 192, 193; 192, 206; 193, call; 193, 194; 193, 202; 194, attribute; 194, 195; 194, 201; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:var; 198, identifier:set_dims; 199, argument_list; 199, 200; 200, identifier:ordered_dims; 201, identifier:chunk; 202, argument_list; 202, 203; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:chunks; 206, identifier:data; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:series; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:dd; 213, identifier:from_array; 214, argument_list; 214, 215; 214, 222; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:dask_array; 218, identifier:reshape; 219, argument_list; 219, 220; 220, unary_operator:-; 220, 221; 221, integer:1; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:columns; 224, list:[name]; 224, 225; 225, identifier:name; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:series_list; 230, identifier:append; 231, argument_list; 231, 232; 232, identifier:series; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:df; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:dd; 239, identifier:concat; 240, argument_list; 240, 241; 240, 242; 241, identifier:series_list; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:axis; 244, integer:1; 245, if_statement; 245, 246; 245, 247; 246, identifier:set_index; 247, block; 247, 248; 248, if_statement; 248, 249; 248, 255; 248, 270; 249, comparison_operator:==; 249, 250; 249, 254; 250, call; 250, 251; 250, 252; 251, identifier:len; 252, argument_list; 252, 253; 253, identifier:dim_order; 254, integer:1; 255, block; 255, 256; 255, 261; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 260; 258, tuple_pattern; 258, 259; 259, identifier:dim; 260, identifier:dim_order; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:df; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:df; 267, identifier:set_index; 268, argument_list; 268, 269; 269, identifier:dim; 270, else_clause; 270, 271; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:df; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:df; 278, identifier:set_index; 279, argument_list; 279, 280; 280, identifier:dim_order; 281, return_statement; 281, 282; 282, identifier:df | def to_dask_dataframe(self, dim_order=None, set_index=False):
import dask.array as da
import dask.dataframe as dd
if dim_order is None:
dim_order = list(self.dims)
elif set(dim_order) != set(self.dims):
raise ValueError(
'dim_order {} does not match the set of dimensions on this '
'Dataset: {}'.format(dim_order, list(self.dims)))
ordered_dims = OrderedDict((k, self.dims[k]) for k in dim_order)
columns = list(ordered_dims)
columns.extend(k for k in self.coords if k not in self.dims)
columns.extend(self.data_vars)
series_list = []
for name in columns:
try:
var = self.variables[name]
except KeyError:
size = self.dims[name]
data = da.arange(size, chunks=size, dtype=np.int64)
var = Variable((name,), data)
if isinstance(var, IndexVariable):
var = var.to_base_variable()
dask_array = var.set_dims(ordered_dims).chunk(self.chunks).data
series = dd.from_array(dask_array.reshape(-1), columns=[name])
series_list.append(series)
df = dd.concat(series_list, axis=1)
if set_index:
if len(dim_order) == 1:
(dim,) = dim_order
df = df.set_index(dim)
else:
df = df.set_index(dim_order)
return df |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:interp; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:var; 5, identifier:indexes_coords; 6, identifier:method; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 20; 9, 37; 9, 49; 9, 56; 9, 72; 9, 80; 9, 94; 9, 100; 9, 113; 9, 132; 9, 145; 9, 151; 9, 184; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:indexes_coords; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:var; 18, identifier:copy; 19, argument_list; 20, if_statement; 20, 21; 20, 26; 21, comparison_operator:in; 21, 22; 21, 23; 22, identifier:method; 23, list:['linear', 'nearest']; 23, 24; 23, 25; 24, string:'linear'; 25, string:'nearest'; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, pattern_list; 29, 30; 29, 31; 30, identifier:var; 31, identifier:indexes_coords; 32, call; 32, 33; 32, 34; 33, identifier:_localize; 34, argument_list; 34, 35; 34, 36; 35, identifier:var; 36, identifier:indexes_coords; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:kwargs; 41, string:'bounds_error'; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:kwargs; 45, identifier:get; 46, argument_list; 46, 47; 46, 48; 47, string:'bounds_error'; 48, False; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:dims; 52, call; 52, 53; 52, 54; 53, identifier:list; 54, argument_list; 54, 55; 55, identifier:indexes_coords; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, pattern_list; 58, 59; 58, 60; 59, identifier:x; 60, identifier:new_x; 61, call; 61, 62; 61, 63; 62, identifier:zip; 63, argument_list; 63, 64; 64, list_splat; 64, 65; 65, list_comprehension; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:indexes_coords; 68, identifier:d; 69, for_in_clause; 69, 70; 69, 71; 70, identifier:d; 71, identifier:dims; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:destination; 75, call; 75, 76; 75, 77; 76, identifier:broadcast_variables; 77, argument_list; 77, 78; 78, list_splat; 78, 79; 79, identifier:new_x; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:broadcast_dims; 83, list_comprehension; 83, 84; 83, 85; 83, 90; 84, identifier:d; 85, for_in_clause; 85, 86; 85, 87; 86, identifier:d; 87, attribute; 87, 88; 87, 89; 88, identifier:var; 89, identifier:dims; 90, if_clause; 90, 91; 91, comparison_operator:not; 91, 92; 91, 93; 92, identifier:d; 93, identifier:dims; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:original_dims; 97, binary_operator:+; 97, 98; 97, 99; 98, identifier:broadcast_dims; 99, identifier:dims; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:new_dims; 103, binary_operator:+; 103, 104; 103, 105; 104, identifier:broadcast_dims; 105, call; 105, 106; 105, 107; 106, identifier:list; 107, argument_list; 107, 108; 108, attribute; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:destination; 111, integer:0; 112, identifier:dims; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:interped; 116, call; 116, 117; 116, 118; 117, identifier:interp_func; 118, argument_list; 118, 119; 118, 128; 118, 129; 118, 130; 118, 131; 119, attribute; 119, 120; 119, 127; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:var; 123, identifier:transpose; 124, argument_list; 124, 125; 125, list_splat; 125, 126; 126, identifier:original_dims; 127, identifier:data; 128, identifier:x; 129, identifier:destination; 130, identifier:method; 131, identifier:kwargs; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:result; 135, call; 135, 136; 135, 137; 136, identifier:Variable; 137, argument_list; 137, 138; 137, 139; 137, 140; 138, identifier:new_dims; 139, identifier:interped; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:attrs; 142, attribute; 142, 143; 142, 144; 143, identifier:var; 144, identifier:attrs; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:out_dims; 148, call; 148, 149; 148, 150; 149, identifier:OrderedSet; 150, argument_list; 151, for_statement; 151, 152; 151, 153; 151, 156; 152, identifier:d; 153, attribute; 153, 154; 153, 155; 154, identifier:var; 155, identifier:dims; 156, block; 156, 157; 157, if_statement; 157, 158; 157, 161; 157, 175; 158, comparison_operator:in; 158, 159; 158, 160; 159, identifier:d; 160, identifier:dims; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:out_dims; 166, identifier:update; 167, argument_list; 167, 168; 168, attribute; 168, 169; 168, 174; 169, subscript; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:indexes_coords; 172, identifier:d; 173, integer:1; 174, identifier:dims; 175, else_clause; 175, 176; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:out_dims; 181, identifier:add; 182, argument_list; 182, 183; 183, identifier:d; 184, return_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:result; 188, identifier:transpose; 189, argument_list; 189, 190; 190, list_splat; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:tuple; 193, argument_list; 193, 194; 194, identifier:out_dims | def interp(var, indexes_coords, method, **kwargs):
if not indexes_coords:
return var.copy()
if method in ['linear', 'nearest']:
var, indexes_coords = _localize(var, indexes_coords)
kwargs['bounds_error'] = kwargs.get('bounds_error', False)
dims = list(indexes_coords)
x, new_x = zip(*[indexes_coords[d] for d in dims])
destination = broadcast_variables(*new_x)
broadcast_dims = [d for d in var.dims if d not in dims]
original_dims = broadcast_dims + dims
new_dims = broadcast_dims + list(destination[0].dims)
interped = interp_func(var.transpose(*original_dims).data,
x, destination, method, kwargs)
result = Variable(new_dims, interped, attrs=var.attrs)
out_dims = OrderedSet()
for d in var.dims:
if d in dims:
out_dims.update(indexes_coords[d][1].dims)
else:
out_dims.add(d)
return result.transpose(*tuple(out_dims)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:coerce_pandas_values; 3, parameters; 3, 4; 4, identifier:objects; 5, block; 5, 6; 5, 13; 5, 20; 5, 24; 5, 102; 6, import_from_statement; 6, 7; 6, 11; 7, relative_import; 7, 8; 7, 9; 8, import_prefix; 9, dotted_name; 9, 10; 10, identifier:dataset; 11, dotted_name; 11, 12; 12, identifier:Dataset; 13, import_from_statement; 13, 14; 13, 18; 14, relative_import; 14, 15; 14, 16; 15, import_prefix; 16, dotted_name; 16, 17; 17, identifier:dataarray; 18, dotted_name; 18, 19; 19, identifier:DataArray; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:out; 23, list:[]; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:obj; 26, identifier:objects; 27, block; 27, 28; 27, 95; 28, if_statement; 28, 29; 28, 34; 28, 39; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:obj; 33, identifier:Dataset; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:variables; 38, identifier:obj; 39, else_clause; 39, 40; 40, block; 40, 41; 40, 47; 40, 65; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:variables; 44, call; 44, 45; 44, 46; 45, identifier:OrderedDict; 46, argument_list; 47, if_statement; 47, 48; 47, 53; 48, call; 48, 49; 48, 50; 49, identifier:isinstance; 50, argument_list; 50, 51; 50, 52; 51, identifier:obj; 52, identifier:PANDAS_TYPES; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:obj; 57, call; 57, 58; 57, 59; 58, identifier:OrderedDict; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:obj; 63, identifier:iteritems; 64, argument_list; 65, for_statement; 65, 66; 65, 69; 65, 74; 66, pattern_list; 66, 67; 66, 68; 67, identifier:k; 68, identifier:v; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:obj; 72, identifier:items; 73, argument_list; 74, block; 74, 75; 74, 89; 75, if_statement; 75, 76; 75, 81; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:v; 80, identifier:PANDAS_TYPES; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:v; 85, call; 85, 86; 85, 87; 86, identifier:DataArray; 87, argument_list; 87, 88; 88, identifier:v; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:variables; 93, identifier:k; 94, identifier:v; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:out; 99, identifier:append; 100, argument_list; 100, 101; 101, identifier:variables; 102, return_statement; 102, 103; 103, identifier:out | def coerce_pandas_values(objects):
from .dataset import Dataset
from .dataarray import DataArray
out = []
for obj in objects:
if isinstance(obj, Dataset):
variables = obj
else:
variables = OrderedDict()
if isinstance(obj, PANDAS_TYPES):
obj = OrderedDict(obj.iteritems())
for k, v in obj.items():
if isinstance(v, PANDAS_TYPES):
v = DataArray(v)
variables[k] = v
out.append(variables)
return out |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:unique_value_groups; 3, parameters; 3, 4; 3, 5; 4, identifier:ar; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, True; 8, block; 8, 9; 8, 23; 8, 37; 8, 60; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, pattern_list; 11, 12; 11, 13; 12, identifier:inverse; 13, identifier:values; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:pd; 17, identifier:factorize; 18, argument_list; 18, 19; 18, 20; 19, identifier:ar; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:sort; 22, identifier:sort; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:groups; 26, list_comprehension; 26, 27; 26, 28; 27, list:[]; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:_; 30, call; 30, 31; 30, 32; 31, identifier:range; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, identifier:values; 37, for_statement; 37, 38; 37, 41; 37, 45; 38, pattern_list; 38, 39; 38, 40; 39, identifier:n; 40, identifier:g; 41, call; 41, 42; 41, 43; 42, identifier:enumerate; 43, argument_list; 43, 44; 44, identifier:inverse; 45, block; 45, 46; 46, if_statement; 46, 47; 46, 50; 47, comparison_operator:>=; 47, 48; 47, 49; 48, identifier:g; 49, integer:0; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:groups; 56, identifier:g; 57, identifier:append; 58, argument_list; 58, 59; 59, identifier:n; 60, return_statement; 60, 61; 61, expression_list; 61, 62; 61, 63; 62, identifier:values; 63, identifier:groups | def unique_value_groups(ar, sort=True):
inverse, values = pd.factorize(ar, sort=sort)
groups = [[] for _ in range(len(values))]
for n, g in enumerate(inverse):
if g >= 0:
groups[g].append(n)
return values, groups |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:order; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 46; 6, if_statement; 6, 7; 6, 10; 6, 36; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:stage; 10, block; 10, 11; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:st; 13, identifier:STAGES; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 21; 16, comparison_operator:in; 16, 17; 16, 18; 17, identifier:st; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:stage; 21, block; 21, 22; 21, 35; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:stage; 25, tuple; 25, 26; 25, 32; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:STAGES; 29, identifier:index; 30, argument_list; 30, 31; 31, identifier:st; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:stage; 35, break_statement; 36, else_clause; 36, 37; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:stage; 41, tuple; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:STAGES; 46, return_statement; 46, 47; 47, binary_operator:+; 47, 48; 47, 67; 48, tuple; 48, 49; 48, 55; 48, 61; 49, call; 49, 50; 49, 51; 50, identifier:int; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:major; 55, call; 55, 56; 55, 57; 56, identifier:int; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:minor; 61, call; 61, 62; 61, 63; 62, identifier:int; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:patch; 67, identifier:stage | def order(self):
if self.stage:
for st in STAGES:
if st in self.stage:
stage = (STAGES.index(st), self.stage)
break
else:
stage = (len(STAGES),)
return (int(self.major), int(self.minor), int(self.patch)) + stage |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:zadd; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:self; 5, identifier:name; 6, identifier:mapping; 7, default_parameter; 7, 8; 7, 9; 8, identifier:nx; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:xx; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:ch; 15, False; 16, default_parameter; 16, 17; 16, 18; 17, identifier:incr; 18, False; 19, block; 19, 20; 19, 29; 19, 39; 19, 56; 19, 60; 19, 64; 19, 79; 19, 94; 19, 109; 19, 130; 19, 155; 20, if_statement; 20, 21; 20, 23; 21, not_operator; 21, 22; 22, identifier:mapping; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:DataError; 27, argument_list; 27, 28; 28, string:"ZADD requires at least one element/score pair"; 29, if_statement; 29, 30; 29, 33; 30, boolean_operator:and; 30, 31; 30, 32; 31, identifier:nx; 32, identifier:xx; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:DataError; 37, argument_list; 37, 38; 38, string:"ZADD allows either 'nx' or 'xx', not both"; 39, if_statement; 39, 40; 39, 48; 40, boolean_operator:and; 40, 41; 40, 42; 41, identifier:incr; 42, comparison_operator:!=; 42, 43; 42, 47; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, identifier:mapping; 47, integer:1; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:DataError; 52, argument_list; 52, 53; 53, concatenated_string; 53, 54; 53, 55; 54, string:"ZADD option 'incr' only works when passing a "; 55, string:"single element/score pair"; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:pieces; 59, list:[]; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:options; 63, dictionary; 64, if_statement; 64, 65; 64, 66; 65, identifier:nx; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:pieces; 71, identifier:append; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:Token; 76, identifier:get_token; 77, argument_list; 77, 78; 78, string:'NX'; 79, if_statement; 79, 80; 79, 81; 80, identifier:xx; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:pieces; 86, identifier:append; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:Token; 91, identifier:get_token; 92, argument_list; 92, 93; 93, string:'XX'; 94, if_statement; 94, 95; 94, 96; 95, identifier:ch; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:pieces; 101, identifier:append; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:Token; 106, identifier:get_token; 107, argument_list; 107, 108; 108, string:'CH'; 109, if_statement; 109, 110; 109, 111; 110, identifier:incr; 111, block; 111, 112; 111, 124; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:pieces; 116, identifier:append; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:Token; 121, identifier:get_token; 122, argument_list; 122, 123; 123, string:'INCR'; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:options; 128, string:'as_score'; 129, True; 130, for_statement; 130, 131; 130, 132; 130, 136; 131, identifier:pair; 132, call; 132, 133; 132, 134; 133, identifier:iteritems; 134, argument_list; 134, 135; 135, identifier:mapping; 136, block; 136, 137; 136, 146; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:pieces; 141, identifier:append; 142, argument_list; 142, 143; 143, subscript; 143, 144; 143, 145; 144, identifier:pair; 145, integer:1; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:pieces; 150, identifier:append; 151, argument_list; 151, 152; 152, subscript; 152, 153; 152, 154; 153, identifier:pair; 154, integer:0; 155, return_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:execute_command; 160, argument_list; 160, 161; 160, 162; 160, 163; 160, 165; 161, string:'ZADD'; 162, identifier:name; 163, list_splat; 163, 164; 164, identifier:pieces; 165, dictionary_splat; 165, 166; 166, identifier:options | def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False):
if not mapping:
raise DataError("ZADD requires at least one element/score pair")
if nx and xx:
raise DataError("ZADD allows either 'nx' or 'xx', not both")
if incr and len(mapping) != 1:
raise DataError("ZADD option 'incr' only works when passing a "
"single element/score pair")
pieces = []
options = {}
if nx:
pieces.append(Token.get_token('NX'))
if xx:
pieces.append(Token.get_token('XX'))
if ch:
pieces.append(Token.get_token('CH'))
if incr:
pieces.append(Token.get_token('INCR'))
options['as_score'] = True
for pair in iteritems(mapping):
pieces.append(pair[1])
pieces.append(pair[0])
return self.execute_command('ZADD', name, *pieces, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zincrby; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:amount; 7, identifier:value; 8, block; 8, 9; 8, 11; 9, expression_statement; 9, 10; 10, string:"Increment the score of ``value`` in sorted set ``name`` by ``amount``"; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:execute_command; 16, argument_list; 16, 17; 16, 18; 16, 19; 16, 20; 17, string:'ZINCRBY'; 18, identifier:name; 19, identifier:amount; 20, identifier:value | def zincrby(self, name, amount, value):
"Increment the score of ``value`` in sorted set ``name`` by ``amount``"
return self.execute_command('ZINCRBY', name, amount, value) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:zinterstore; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:dest; 6, identifier:keys; 7, default_parameter; 7, 8; 7, 9; 8, identifier:aggregate; 9, None; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_zaggregate; 16, argument_list; 16, 17; 16, 18; 16, 19; 16, 20; 17, string:'ZINTERSTORE'; 18, identifier:dest; 19, identifier:keys; 20, identifier:aggregate | def zinterstore(self, dest, keys, aggregate=None):
return self._zaggregate('ZINTERSTORE', dest, keys, aggregate) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zlexcount; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:min; 7, identifier:max; 8, block; 8, 9; 9, return_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:execute_command; 14, argument_list; 14, 15; 14, 16; 14, 17; 14, 18; 15, string:'ZLEXCOUNT'; 16, identifier:name; 17, identifier:min; 18, identifier:max | def zlexcount(self, name, min, max):
return self.execute_command('ZLEXCOUNT', name, min, max) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:zpopmax; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:count; 8, None; 9, block; 9, 10; 9, 22; 9, 29; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:args; 13, boolean_operator:or; 13, 14; 13, 21; 14, boolean_operator:and; 14, 15; 14, 19; 15, parenthesized_expression; 15, 16; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:count; 18, None; 19, list:[count]; 19, 20; 20, identifier:count; 21, list:[]; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:options; 25, dictionary; 25, 26; 26, pair; 26, 27; 26, 28; 27, string:'withscores'; 28, True; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:execute_command; 34, argument_list; 34, 35; 34, 36; 34, 37; 34, 39; 35, string:'ZPOPMAX'; 36, identifier:name; 37, list_splat; 37, 38; 38, identifier:args; 39, dictionary_splat; 39, 40; 40, identifier:options | def zpopmax(self, name, count=None):
args = (count is not None) and [count] or []
options = {
'withscores': True
}
return self.execute_command('ZPOPMAX', name, *args, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:zpopmin; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:count; 8, None; 9, block; 9, 10; 9, 22; 9, 29; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:args; 13, boolean_operator:or; 13, 14; 13, 21; 14, boolean_operator:and; 14, 15; 14, 19; 15, parenthesized_expression; 15, 16; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:count; 18, None; 19, list:[count]; 19, 20; 20, identifier:count; 21, list:[]; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:options; 25, dictionary; 25, 26; 26, pair; 26, 27; 26, 28; 27, string:'withscores'; 28, True; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:execute_command; 34, argument_list; 34, 35; 34, 36; 34, 37; 34, 39; 35, string:'ZPOPMIN'; 36, identifier:name; 37, list_splat; 37, 38; 38, identifier:args; 39, dictionary_splat; 39, 40; 40, identifier:options | def zpopmin(self, name, count=None):
args = (count is not None) and [count] or []
options = {
'withscores': True
}
return self.execute_command('ZPOPMIN', name, *args, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:bzpopmax; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:keys; 6, default_parameter; 6, 7; 6, 8; 7, identifier:timeout; 8, integer:0; 9, block; 9, 10; 9, 19; 9, 27; 9, 34; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:timeout; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:timeout; 18, integer:0; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:keys; 22, call; 22, 23; 22, 24; 23, identifier:list_or_args; 24, argument_list; 24, 25; 24, 26; 25, identifier:keys; 26, None; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:keys; 31, identifier:append; 32, argument_list; 32, 33; 33, identifier:timeout; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:execute_command; 39, argument_list; 39, 40; 39, 41; 40, string:'BZPOPMAX'; 41, list_splat; 41, 42; 42, identifier:keys | def bzpopmax(self, keys, timeout=0):
if timeout is None:
timeout = 0
keys = list_or_args(keys, None)
keys.append(timeout)
return self.execute_command('BZPOPMAX', *keys) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:bzpopmin; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:keys; 6, default_parameter; 6, 7; 6, 8; 7, identifier:timeout; 8, integer:0; 9, block; 9, 10; 9, 19; 9, 27; 9, 34; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:timeout; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:timeout; 18, integer:0; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:keys; 22, call; 22, 23; 22, 24; 23, identifier:list_or_args; 24, argument_list; 24, 25; 24, 26; 25, identifier:keys; 26, None; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:keys; 31, identifier:append; 32, argument_list; 32, 33; 33, identifier:timeout; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:execute_command; 39, argument_list; 39, 40; 39, 41; 40, string:'BZPOPMIN'; 41, list_splat; 41, 42; 42, identifier:keys | def bzpopmin(self, keys, timeout=0):
if timeout is None:
timeout = 0
keys = list_or_args(keys, None)
keys.append(timeout)
return self.execute_command('BZPOPMIN', *keys) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zremrangebylex; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:min; 7, identifier:max; 8, block; 8, 9; 9, return_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:execute_command; 14, argument_list; 14, 15; 14, 16; 14, 17; 14, 18; 15, string:'ZREMRANGEBYLEX'; 16, identifier:name; 17, identifier:min; 18, identifier:max | def zremrangebylex(self, name, min, max):
return self.execute_command('ZREMRANGEBYLEX', name, min, max) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zremrangebyrank; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:min; 7, identifier:max; 8, block; 8, 9; 9, return_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:execute_command; 14, argument_list; 14, 15; 14, 16; 14, 17; 14, 18; 15, string:'ZREMRANGEBYRANK'; 16, identifier:name; 17, identifier:min; 18, identifier:max | def zremrangebyrank(self, name, min, max):
return self.execute_command('ZREMRANGEBYRANK', name, min, max) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:argsort_k_smallest; 3, parameters; 3, 4; 3, 5; 4, identifier:x; 5, identifier:k; 6, block; 6, 7; 6, 24; 6, 43; 6, 57; 6, 63; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:==; 8, 9; 8, 10; 9, identifier:k; 10, integer:0; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:np; 16, identifier:array; 17, argument_list; 17, 18; 17, 19; 18, list:[]; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:dtype; 21, attribute; 21, 22; 21, 23; 22, identifier:np; 23, identifier:intp; 24, if_statement; 24, 25; 24, 35; 25, boolean_operator:or; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:k; 28, None; 29, comparison_operator:>=; 29, 30; 29, 31; 30, identifier:k; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:x; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:np; 40, identifier:argsort; 41, argument_list; 41, 42; 42, identifier:x; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:indices; 46, subscript; 46, 47; 46, 54; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:np; 50, identifier:argpartition; 51, argument_list; 51, 52; 51, 53; 52, identifier:x; 53, identifier:k; 54, slice; 54, 55; 54, 56; 55, colon; 56, identifier:k; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:values; 60, subscript; 60, 61; 60, 62; 61, identifier:x; 62, identifier:indices; 63, return_statement; 63, 64; 64, subscript; 64, 65; 64, 66; 65, identifier:indices; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:np; 69, identifier:argsort; 70, argument_list; 70, 71; 71, identifier:values | def argsort_k_smallest(x, k):
if k == 0:
return np.array([], dtype=np.intp)
if k is None or k >= len(x):
return np.argsort(x)
indices = np.argpartition(x, k)[:k]
values = x[indices]
return indices[np.argsort(values)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:lookup; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:source_id; 6, type; 6, 7; 7, identifier:str; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:schema_id; 10, type; 10, 11; 11, identifier:str; 12, block; 12, 13; 13, try_statement; 13, 14; 13, 157; 14, block; 14, 15; 14, 25; 14, 62; 14, 74; 14, 86; 14, 103; 14, 112; 14, 125; 14, 133; 14, 141; 14, 149; 14, 155; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:schema; 18, call; 18, 19; 18, 20; 19, identifier:Schema; 20, argument_list; 20, 21; 20, 22; 20, 23; 20, 24; 21, identifier:source_id; 22, string:''; 23, string:''; 24, list:[]; 25, if_statement; 25, 26; 25, 34; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:hasattr; 29, argument_list; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:Schema; 32, identifier:lookup; 33, string:"cb"; 34, block; 34, 35; 34, 44; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:schema; 40, identifier:logger; 41, identifier:debug; 42, argument_list; 42, 43; 43, string:"vcx_schema_get_attributes: Creating callback"; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:Schema; 49, identifier:lookup; 50, identifier:cb; 51, call; 51, 52; 51, 53; 52, identifier:create_cb; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:CFUNCTYPE; 56, argument_list; 56, 57; 56, 58; 56, 59; 56, 60; 56, 61; 57, None; 58, identifier:c_uint32; 59, identifier:c_uint32; 60, identifier:c_uint32; 61, identifier:c_char_p; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:c_source_id; 65, call; 65, 66; 65, 67; 66, identifier:c_char_p; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:source_id; 71, identifier:encode; 72, argument_list; 72, 73; 73, string:'utf-8'; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:c_schema_id; 77, call; 77, 78; 77, 79; 78, identifier:c_char_p; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:schema_id; 83, identifier:encode; 84, argument_list; 84, 85; 85, string:'utf-8'; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, pattern_list; 88, 89; 88, 90; 89, identifier:handle; 90, identifier:data; 91, await; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:do_call; 94, argument_list; 94, 95; 94, 96; 94, 97; 94, 98; 95, string:'vcx_schema_get_attributes'; 96, identifier:c_source_id; 97, identifier:c_schema_id; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:Schema; 101, identifier:lookup; 102, identifier:cb; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:schema; 108, identifier:logger; 109, identifier:debug; 110, argument_list; 110, 111; 111, string:"created schema object"; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:schema_result; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:json; 118, identifier:loads; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:data; 123, identifier:decode; 124, argument_list; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:schema; 129, identifier:attrs; 130, subscript; 130, 131; 130, 132; 131, identifier:schema_result; 132, string:'data'; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:schema; 137, identifier:name; 138, subscript; 138, 139; 138, 140; 139, identifier:schema_result; 140, string:'name'; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:schema; 145, identifier:version; 146, subscript; 146, 147; 146, 148; 147, identifier:schema_result; 148, string:'version'; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:schema; 153, identifier:handle; 154, identifier:handle; 155, return_statement; 155, 156; 156, identifier:schema; 157, except_clause; 157, 158; 157, 159; 158, identifier:KeyError; 159, block; 159, 160; 160, raise_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:VcxError; 163, argument_list; 163, 164; 164, attribute; 164, 165; 164, 166; 165, identifier:ErrorCode; 166, identifier:InvalidSchema | async def lookup(source_id: str, schema_id: str):
try:
schema = Schema(source_id, '', '', [])
if not hasattr(Schema.lookup, "cb"):
schema.logger.debug("vcx_schema_get_attributes: Creating callback")
Schema.lookup.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p))
c_source_id = c_char_p(source_id.encode('utf-8'))
c_schema_id = c_char_p(schema_id.encode('utf-8'))
handle, data = await do_call('vcx_schema_get_attributes',
c_source_id,
c_schema_id,
Schema.lookup.cb)
schema.logger.debug("created schema object")
schema_result = json.loads(data.decode())
schema.attrs = schema_result['data']
schema.name = schema_result['name']
schema.version = schema_result['version']
schema.handle = handle
return schema
except KeyError:
raise VcxError(ErrorCode.InvalidSchema) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:interleave_keys; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, identifier:b; 6, block; 6, 7; 6, 30; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:interleave; 9, parameters; 9, 10; 10, identifier:args; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, string:''; 16, identifier:join; 17, argument_list; 17, 18; 18, list_comprehension; 18, 19; 18, 20; 18, 27; 19, identifier:x; 20, for_in_clause; 20, 21; 20, 22; 21, identifier:t; 22, call; 22, 23; 22, 24; 23, identifier:zip; 24, argument_list; 24, 25; 25, list_splat; 25, 26; 26, identifier:args; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:x; 29, identifier:t; 30, return_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:int; 33, argument_list; 33, 34; 33, 52; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, string:''; 37, identifier:join; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:interleave; 41, generator_expression; 41, 42; 41, 47; 42, call; 42, 43; 42, 44; 43, identifier:format; 44, argument_list; 44, 45; 44, 46; 45, identifier:x; 46, string:'016b'; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:x; 49, tuple; 49, 50; 49, 51; 50, identifier:a; 51, identifier:b; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:base; 54, integer:2 | def interleave_keys(a, b):
def interleave(args):
return ''.join([x for t in zip(*args) for x in t])
return int(''.join(interleave(format(x, '016b') for x in (a, b))), base=2) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:pool; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 15; 3, 18; 3, 21; 4, identifier:data; 5, identifier:batch_size; 6, identifier:key; 7, default_parameter; 7, 8; 7, 9; 8, identifier:batch_size_fn; 9, lambda; 9, 10; 9, 14; 10, lambda_parameters; 10, 11; 10, 12; 10, 13; 11, identifier:new; 12, identifier:count; 13, identifier:sofar; 14, identifier:count; 15, default_parameter; 15, 16; 15, 17; 16, identifier:random_shuffler; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:shuffle; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:sort_within_batch; 23, False; 24, block; 24, 25; 24, 36; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:random_shuffler; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:random_shuffler; 33, attribute; 33, 34; 33, 35; 34, identifier:random; 35, identifier:shuffle; 36, for_statement; 36, 37; 36, 38; 36, 46; 37, identifier:p; 38, call; 38, 39; 38, 40; 39, identifier:batch; 40, argument_list; 40, 41; 40, 42; 40, 45; 41, identifier:data; 42, binary_operator:*; 42, 43; 42, 44; 43, identifier:batch_size; 44, integer:100; 45, identifier:batch_size_fn; 46, block; 46, 47; 46, 72; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:p_batch; 50, conditional_expression:if; 50, 51; 50, 63; 50, 64; 50, 65; 50, 66; 51, call; 51, 52; 51, 53; 52, identifier:batch; 53, argument_list; 53, 54; 53, 61; 53, 62; 54, call; 54, 55; 54, 56; 55, identifier:sorted; 56, argument_list; 56, 57; 56, 58; 57, identifier:p; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:key; 60, identifier:key; 61, identifier:batch_size; 62, identifier:batch_size_fn; 63, line_continuation:\; 64, identifier:sort_within_batch; 65, line_continuation:\; 66, call; 66, 67; 66, 68; 67, identifier:batch; 68, argument_list; 68, 69; 68, 70; 68, 71; 69, identifier:p; 70, identifier:batch_size; 71, identifier:batch_size_fn; 72, if_statement; 72, 73; 72, 74; 72, 88; 73, identifier:shuffle; 74, block; 74, 75; 75, for_statement; 75, 76; 75, 77; 75, 84; 76, identifier:b; 77, call; 77, 78; 77, 79; 78, identifier:random_shuffler; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:list; 82, argument_list; 82, 83; 83, identifier:p_batch; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, yield; 86, 87; 87, identifier:b; 88, else_clause; 88, 89; 89, block; 89, 90; 90, for_statement; 90, 91; 90, 92; 90, 96; 91, identifier:b; 92, call; 92, 93; 92, 94; 93, identifier:list; 94, argument_list; 94, 95; 95, identifier:p_batch; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, yield; 98, 99; 99, identifier:b | def pool(data, batch_size, key, batch_size_fn=lambda new, count, sofar: count,
random_shuffler=None, shuffle=False, sort_within_batch=False):
if random_shuffler is None:
random_shuffler = random.shuffle
for p in batch(data, batch_size * 100, batch_size_fn):
p_batch = batch(sorted(p, key=key), batch_size, batch_size_fn) \
if sort_within_batch \
else batch(p, batch_size, batch_size_fn)
if shuffle:
for b in random_shuffler(list(p_batch)):
yield b
else:
for b in list(p_batch):
yield b |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:data; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 63; 6, if_statement; 6, 7; 6, 10; 6, 25; 6, 55; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:sort; 10, block; 10, 11; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:xs; 14, call; 14, 15; 14, 16; 15, identifier:sorted; 16, argument_list; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:dataset; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:key; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:sort_key; 25, elif_clause; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:shuffle; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:xs; 33, list_comprehension; 33, 34; 33, 39; 34, subscript; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:dataset; 38, identifier:i; 39, for_in_clause; 39, 40; 39, 41; 40, identifier:i; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:random_shuffler; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:range; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:len; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:dataset; 55, else_clause; 55, 56; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:xs; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:dataset; 63, return_statement; 63, 64; 64, identifier:xs | def data(self):
if self.sort:
xs = sorted(self.dataset, key=self.sort_key)
elif self.shuffle:
xs = [self.dataset[i] for i in self.random_shuffler(range(len(self.dataset)))]
else:
xs = self.dataset
return xs |
0, module; 0, 1; 0, 302; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:color_table; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:color; 5, default_parameter; 5, 6; 5, 7; 6, identifier:N; 7, integer:1; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort_values; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:inline; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:as_html; 19, False; 20, block; 20, 21; 20, 181; 20, 243; 20, 251; 21, if_statement; 21, 22; 21, 27; 21, 52; 21, 141; 22, call; 22, 23; 22, 24; 23, identifier:isinstance; 24, argument_list; 24, 25; 24, 26; 25, identifier:color; 26, identifier:list; 27, block; 27, 28; 27, 32; 27, 43; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:c_; 31, string:''; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:rgb_tup; 35, list_comprehension; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:normalize; 38, argument_list; 38, 39; 39, identifier:c; 40, for_in_clause; 40, 41; 40, 42; 41, identifier:c; 42, identifier:color; 43, if_statement; 43, 44; 43, 45; 44, identifier:sort; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:rgb_tup; 50, identifier:sort; 51, argument_list; 52, elif_clause; 52, 53; 52, 58; 53, call; 53, 54; 53, 55; 54, identifier:isinstance; 55, argument_list; 55, 56; 55, 57; 56, identifier:color; 57, identifier:dict; 58, block; 58, 59; 58, 63; 58, 92; 58, 128; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:c_; 62, string:''; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:items; 66, list_comprehension; 66, 67; 66, 80; 67, tuple; 67, 68; 67, 69; 67, 73; 68, identifier:k; 69, call; 69, 70; 69, 71; 70, identifier:normalize; 71, argument_list; 71, 72; 72, identifier:v; 73, call; 73, 74; 73, 75; 74, identifier:hex_to_hsv; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:normalize; 78, argument_list; 78, 79; 79, identifier:v; 80, for_in_clause; 80, 81; 80, 84; 81, pattern_list; 81, 82; 81, 83; 82, identifier:k; 83, identifier:v; 84, call; 84, 85; 84, 86; 85, identifier:list; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:color; 90, identifier:items; 91, argument_list; 92, if_statement; 92, 93; 92, 94; 92, 110; 93, identifier:sort_values; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:items; 98, call; 98, 99; 98, 100; 99, identifier:sorted; 100, argument_list; 100, 101; 100, 102; 101, identifier:items; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:key; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:operator; 107, identifier:itemgetter; 108, argument_list; 108, 109; 109, integer:2; 110, elif_clause; 110, 111; 110, 112; 111, identifier:sort; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:items; 116, call; 116, 117; 116, 118; 117, identifier:sorted; 118, argument_list; 118, 119; 118, 120; 119, identifier:items; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:key; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:operator; 125, identifier:itemgetter; 126, argument_list; 126, 127; 127, integer:0; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:rgb_tup; 131, list_comprehension; 131, 132; 131, 135; 132, tuple; 132, 133; 132, 134; 133, identifier:k; 134, identifier:v; 135, for_in_clause; 135, 136; 135, 140; 136, pattern_list; 136, 137; 136, 138; 136, 139; 137, identifier:k; 138, identifier:v; 139, identifier:_; 140, identifier:items; 141, else_clause; 141, 142; 142, block; 142, 143; 142, 150; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:c_; 146, call; 146, 147; 146, 148; 147, identifier:normalize; 148, argument_list; 148, 149; 149, identifier:color; 150, if_statement; 150, 151; 150, 154; 150, 174; 151, comparison_operator:>; 151, 152; 151, 153; 152, identifier:N; 153, integer:1; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:rgb_tup; 158, subscript; 158, 159; 158, 169; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:np; 162, identifier:array; 163, argument_list; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:color_range; 166, argument_list; 166, 167; 166, 168; 167, identifier:c_; 168, identifier:N; 169, slice; 169, 170; 169, 171; 169, 172; 170, colon; 171, colon; 172, unary_operator:-; 172, 173; 173, integer:1; 174, else_clause; 174, 175; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:rgb_tup; 179, list:[c_]; 179, 180; 180, identifier:c_; 181, function_definition; 181, 182; 181, 183; 181, 185; 182, function_name:_color; 183, parameters; 183, 184; 184, identifier:c; 185, block; 185, 186; 185, 216; 185, 238; 186, if_statement; 186, 187; 186, 195; 186, 207; 187, comparison_operator:<; 187, 188; 187, 194; 188, subscript; 188, 189; 188, 193; 189, call; 189, 190; 189, 191; 190, identifier:hex_to_hsv; 191, argument_list; 191, 192; 192, identifier:c; 193, integer:2; 194, float:.5; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 197, 200; 198, identifier:color; 199, ERROR; 200, assignment; 200, 201; 200, 202; 200, 206; 201, identifier:shadow; 202, ERROR; 202, 203; 202, 204; 202, 205; 203, integer:0; 204, integer:1; 205, identifier:px; 206, integer:0; 207, else_clause; 207, 208; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 210, 213; 211, identifier:color; 212, ERROR; 213, assignment; 213, 214; 213, 215; 214, identifier:shadow; 215, string:'0 1px 0 rgba(255,255,255,0.6)'; 216, if_statement; 216, 217; 216, 220; 216, 232; 217, comparison_operator:==; 217, 218; 217, 219; 218, identifier:c; 219, identifier:c_; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 222, 225; 223, identifier:border; 224, ERROR; 225, assignment; 225, 226; 225, 227; 225, 230; 226, identifier:border; 227, ERROR; 227, 228; 227, 229; 228, integer:1; 229, identifier:px; 230, type; 230, 231; 231, identifier:solid; 232, else_clause; 232, 233; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:border; 237, string:''; 238, return_statement; 238, 239; 239, expression_list; 239, 240; 239, 241; 239, 242; 240, identifier:color; 241, identifier:shadow; 242, identifier:border; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:s; 246, conditional_expression:if; 246, 247; 246, 248; 246, 250; 247, string:'<ul style="list-style-type: none;">'; 248, not_operator; 248, 249; 249, identifier:inline; 250, string:''; 251, for_statement; 251, 252; 251, 253; 251, 254; 252, identifier:c; 253, identifier:rgb_tup; 254, block; 254, 255; 254, 278; 255, if_statement; 255, 256; 255, 261; 255, 272; 256, call; 256, 257; 256, 258; 257, identifier:isinstance; 258, argument_list; 258, 259; 258, 260; 259, identifier:c; 260, identifier:tuple; 261, block; 261, 262; 261, 268; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 267; 264, pattern_list; 264, 265; 264, 266; 265, identifier:k; 266, identifier:c; 267, identifier:c; 268, expression_statement; 268, 269; 269, augmented_assignment:+=; 269, 270; 269, 271; 270, identifier:k; 271, string:' : '; 272, else_clause; 272, 273; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:k; 277, string:''; 278, if_statement; 278, 279; 278, 280; 278, 290; 279, identifier:inline; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, augmented_assignment:+=; 282, 283; 282, 284; 283, identifier:s; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, string:'<div style="background-color:{0};height:20px;width:20px;display:inline-block;"></div>'; 287, identifier:format; 288, argument_list; 288, 289; 289, identifier:c; 290, else_clause; 290, 291; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 298; 294, pattern_list; 294, 295; 294, 296; 294, 297; 295, identifier:color; 296, identifier:shadow; 297, identifier:border; 298, call; 298, 299; 298, 300; 299, identifier:_color; 300, argument_list; 300, 301; 301, identifier:c; 302, ERROR; 302, 303; 302, 304; 302, 327; 302, 328; 303, identifier:s; 304, binary_operator:+; 304, 305; 304, 325; 304, 326; 305, binary_operator:+; 305, 306; 305, 320; 306, binary_operator:+; 306, 307; 306, 319; 307, binary_operator:+; 307, 308; 307, 318; 308, binary_operator:+; 308, 309; 308, 317; 309, binary_operator:+; 309, 310; 309, 316; 310, binary_operator:+; 310, 311; 310, 315; 311, binary_operator:+; 311, 312; 311, 314; 312, unary_operator:+; 312, 313; 313, identifier:border; 314, comment; 315, identifier:c; 316, comment; 317, identifier:color; 318, comment; 319, identifier:k; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:c; 323, identifier:upper; 324, argument_list; 325, ERROR; 326, identifier:span; 327, ERROR; 328, identifier:li | def color_table(color, N=1, sort=False, sort_values=False, inline=False, as_html=False):
if isinstance(color, list):
c_ = ''
rgb_tup = [normalize(c) for c in color]
if sort:
rgb_tup.sort()
elif isinstance(color, dict):
c_ = ''
items = [(k, normalize(v), hex_to_hsv(normalize(v)))
for k, v in list(color.items())]
if sort_values:
items = sorted(items, key=operator.itemgetter(2))
elif sort:
items = sorted(items, key=operator.itemgetter(0))
rgb_tup = [(k, v) for k, v, _ in items]
else:
c_ = normalize(color)
if N > 1:
rgb_tup = np.array(color_range(c_, N))[::-1]
else:
rgb_tup = [c_]
def _color(c):
if hex_to_hsv(c)[2] < .5:
color = "
shadow = '0 1px 0
else:
color = "
shadow = '0 1px 0 rgba(255,255,255,0.6)'
if c == c_:
border = " border: 1px solid
else:
border = ''
return color, shadow, border
s = '<ul style="list-style-type: none;">' if not inline else ''
for c in rgb_tup:
if isinstance(c, tuple):
k, c = c
k += ' : '
else:
k = ''
if inline:
s += '<div style="background-color:{0};height:20px;width:20px;display:inline-block;"></div>'.format(
c)
else:
color, shadow, border = _color(c)
s += + border + """line-height:30px;background-color:""" + c + """;">
<span style=" text-shadow:; color:""" + color + """;">""" + k + c.upper() + """</span>
</li> |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_nearest_edge; 3, parameters; 3, 4; 3, 5; 4, identifier:G; 5, identifier:point; 6, block; 6, 7; 6, 15; 6, 28; 6, 43; 6, 69; 6, 84; 6, 92; 6, 99; 6, 119; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:start_time; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:time; 13, identifier:time; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:gdf; 18, call; 18, 19; 18, 20; 19, identifier:graph_to_gdfs; 20, argument_list; 20, 21; 20, 22; 20, 25; 21, identifier:G; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:nodes; 24, False; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:fill_edge_geometry; 27, True; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:graph_edges; 31, call; 31, 32; 31, 42; 32, attribute; 32, 33; 32, 41; 33, attribute; 33, 34; 33, 40; 34, subscript; 34, 35; 34, 36; 35, identifier:gdf; 36, list:["geometry", "u", "v"]; 36, 37; 36, 38; 36, 39; 37, string:"geometry"; 38, string:"u"; 39, string:"v"; 40, identifier:values; 41, identifier:tolist; 42, argument_list; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:edges_with_distances; 46, list_comprehension; 46, 47; 46, 66; 47, tuple; 47, 48; 47, 49; 48, identifier:graph_edge; 49, call; 49, 50; 49, 62; 50, attribute; 50, 51; 50, 61; 51, call; 51, 52; 51, 53; 52, identifier:Point; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:tuple; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:reversed; 59, argument_list; 59, 60; 60, identifier:point; 61, identifier:distance; 62, argument_list; 62, 63; 63, subscript; 63, 64; 63, 65; 64, identifier:graph_edge; 65, integer:0; 66, for_in_clause; 66, 67; 66, 68; 67, identifier:graph_edge; 68, identifier:graph_edges; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:edges_with_distances; 72, call; 72, 73; 72, 74; 73, identifier:sorted; 74, argument_list; 74, 75; 74, 76; 75, identifier:edges_with_distances; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:key; 78, lambda; 78, 79; 78, 81; 79, lambda_parameters; 79, 80; 80, identifier:x; 81, subscript; 81, 82; 81, 83; 82, identifier:x; 83, integer:1; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:closest_edge_to_point; 87, subscript; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:edges_with_distances; 90, integer:0; 91, integer:0; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 98; 94, pattern_list; 94, 95; 94, 96; 94, 97; 95, identifier:geometry; 96, identifier:u; 97, identifier:v; 98, identifier:closest_edge_to_point; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:log; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, string:'Found nearest edge ({}) to point {} in {:,.2f} seconds'; 106, identifier:format; 107, argument_list; 107, 108; 107, 111; 107, 112; 108, tuple; 108, 109; 108, 110; 109, identifier:u; 110, identifier:v; 111, identifier:point; 112, binary_operator:-; 112, 113; 112, 118; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:time; 116, identifier:time; 117, argument_list; 118, identifier:start_time; 119, return_statement; 119, 120; 120, expression_list; 120, 121; 120, 122; 120, 123; 121, identifier:geometry; 122, identifier:u; 123, identifier:v | def get_nearest_edge(G, point):
start_time = time.time()
gdf = graph_to_gdfs(G, nodes=False, fill_edge_geometry=True)
graph_edges = gdf[["geometry", "u", "v"]].values.tolist()
edges_with_distances = [
(
graph_edge,
Point(tuple(reversed(point))).distance(graph_edge[0])
)
for graph_edge in graph_edges
]
edges_with_distances = sorted(edges_with_distances, key=lambda x: x[1])
closest_edge_to_point = edges_with_distances[0][0]
geometry, u, v = closest_edge_to_point
log('Found nearest edge ({}) to point {} in {:,.2f} seconds'.format((u, v), point, time.time() - start_time))
return geometry, u, v |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:get_http_headers; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:user_agent; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:referer; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:accept_language; 12, None; 13, block; 13, 14; 13, 25; 13, 36; 13, 47; 13, 57; 13, 73; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:is; 15, 16; 15, 17; 16, identifier:user_agent; 17, None; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:user_agent; 22, attribute; 22, 23; 22, 24; 23, identifier:settings; 24, identifier:default_user_agent; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:referer; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:referer; 33, attribute; 33, 34; 33, 35; 34, identifier:settings; 35, identifier:default_referer; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:accept_language; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:accept_language; 44, attribute; 44, 45; 44, 46; 45, identifier:settings; 46, identifier:default_accept_language; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:headers; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:requests; 54, identifier:utils; 55, identifier:default_headers; 56, argument_list; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:headers; 61, identifier:update; 62, argument_list; 62, 63; 63, dictionary; 63, 64; 63, 67; 63, 70; 64, pair; 64, 65; 64, 66; 65, string:'User-Agent'; 66, identifier:user_agent; 67, pair; 67, 68; 67, 69; 68, string:'referer'; 69, identifier:referer; 70, pair; 70, 71; 70, 72; 71, string:'Accept-Language'; 72, identifier:accept_language; 73, return_statement; 73, 74; 74, identifier:headers | def get_http_headers(user_agent=None, referer=None, accept_language=None):
if user_agent is None:
user_agent = settings.default_user_agent
if referer is None:
referer = settings.default_referer
if accept_language is None:
accept_language = settings.default_accept_language
headers = requests.utils.default_headers()
headers.update({'User-Agent': user_agent, 'referer': referer, 'Accept-Language': accept_language})
return headers |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_has_sorted_sa_indices; 3, parameters; 3, 4; 3, 5; 4, identifier:s_indices; 5, identifier:a_indices; 6, block; 6, 7; 6, 14; 6, 60; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:L; 10, call; 10, 11; 10, 12; 11, identifier:len; 12, argument_list; 12, 13; 13, identifier:s_indices; 14, for_statement; 14, 15; 14, 16; 14, 22; 15, identifier:i; 16, call; 16, 17; 16, 18; 17, identifier:range; 18, argument_list; 18, 19; 19, binary_operator:-; 19, 20; 19, 21; 20, identifier:L; 21, integer:1; 22, block; 22, 23; 22, 36; 23, if_statement; 23, 24; 23, 33; 24, comparison_operator:>; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:s_indices; 27, identifier:i; 28, subscript; 28, 29; 28, 30; 29, identifier:s_indices; 30, binary_operator:+; 30, 31; 30, 32; 31, identifier:i; 32, integer:1; 33, block; 33, 34; 34, return_statement; 34, 35; 35, False; 36, if_statement; 36, 37; 36, 46; 37, comparison_operator:==; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:s_indices; 40, identifier:i; 41, subscript; 41, 42; 41, 43; 42, identifier:s_indices; 43, binary_operator:+; 43, 44; 43, 45; 44, identifier:i; 45, integer:1; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 57; 48, comparison_operator:>=; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:a_indices; 51, identifier:i; 52, subscript; 52, 53; 52, 54; 53, identifier:a_indices; 54, binary_operator:+; 54, 55; 54, 56; 55, identifier:i; 56, integer:1; 57, block; 57, 58; 58, return_statement; 58, 59; 59, False; 60, return_statement; 60, 61; 61, True | def _has_sorted_sa_indices(s_indices, a_indices):
L = len(s_indices)
for i in range(L-1):
if s_indices[i] > s_indices[i+1]:
return False
if s_indices[i] == s_indices[i+1]:
if a_indices[i] >= a_indices[i+1]:
return False
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_generate_a_indptr; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:num_states; 5, identifier:s_indices; 6, identifier:out; 7, block; 7, 8; 7, 12; 7, 18; 7, 47; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:idx; 11, integer:0; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 17; 14, subscript; 14, 15; 14, 16; 15, identifier:out; 16, integer:0; 17, integer:0; 18, for_statement; 18, 19; 18, 20; 18, 26; 19, identifier:s; 20, call; 20, 21; 20, 22; 21, identifier:range; 22, argument_list; 22, 23; 23, binary_operator:-; 23, 24; 23, 25; 24, identifier:num_states; 25, integer:1; 26, block; 26, 27; 26, 39; 27, while_statement; 27, 28; 27, 34; 28, parenthesized_expression; 28, 29; 29, comparison_operator:==; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:s_indices; 32, identifier:idx; 33, identifier:s; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, augmented_assignment:+=; 36, 37; 36, 38; 37, identifier:idx; 38, integer:1; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 46; 41, subscript; 41, 42; 41, 43; 42, identifier:out; 43, binary_operator:+; 43, 44; 43, 45; 44, identifier:s; 45, integer:1; 46, identifier:idx; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:out; 51, identifier:num_states; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:s_indices | def _generate_a_indptr(num_states, s_indices, out):
idx = 0
out[0] = 0
for s in range(num_states-1):
while(s_indices[idx] == s):
idx += 1
out[s+1] = idx
out[num_states] = len(s_indices) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_topologically; 3, parameters; 3, 4; 4, identifier:dag; 5, block; 5, 6; 5, 15; 5, 19; 5, 29; 5, 86; 5, 106; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:dag; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:copy; 12, identifier:deepcopy; 13, argument_list; 13, 14; 14, identifier:dag; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:sorted_nodes; 18, list:[]; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:independent_nodes; 22, call; 22, 23; 22, 24; 23, identifier:deque; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:get_independent_nodes; 27, argument_list; 27, 28; 28, identifier:dag; 29, while_statement; 29, 30; 29, 31; 30, identifier:independent_nodes; 31, block; 31, 32; 31, 40; 31, 47; 31, 53; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:node; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:independent_nodes; 38, identifier:popleft; 39, argument_list; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:sorted_nodes; 44, identifier:append; 45, argument_list; 45, 46; 46, identifier:node; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:downstream_nodes; 50, subscript; 50, 51; 50, 52; 51, identifier:dag; 52, identifier:node; 53, while_statement; 53, 54; 53, 55; 54, identifier:downstream_nodes; 55, block; 55, 56; 55, 65; 55, 71; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:downstream_node; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:downstream_nodes; 62, identifier:pop; 63, argument_list; 63, 64; 64, integer:0; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:not; 66, 67; 66, 68; 67, identifier:downstream_node; 68, identifier:dag; 69, block; 69, 70; 70, continue_statement; 71, if_statement; 71, 72; 71, 78; 72, not_operator; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:has_dependencies; 75, argument_list; 75, 76; 75, 77; 76, identifier:downstream_node; 77, identifier:dag; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:independent_nodes; 83, identifier:append; 84, argument_list; 84, 85; 85, identifier:downstream_node; 86, if_statement; 86, 87; 86, 100; 87, comparison_operator:!=; 87, 88; 87, 92; 88, call; 88, 89; 88, 90; 89, identifier:len; 90, argument_list; 90, 91; 91, identifier:sorted_nodes; 92, call; 92, 93; 92, 94; 93, identifier:len; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:dag; 98, identifier:keys; 99, argument_list; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:ValueError; 104, argument_list; 104, 105; 105, string:'graph is not acyclic'; 106, return_statement; 106, 107; 107, identifier:sorted_nodes | def sort_topologically(dag):
dag = copy.deepcopy(dag)
sorted_nodes = []
independent_nodes = deque(get_independent_nodes(dag))
while independent_nodes:
node = independent_nodes.popleft()
sorted_nodes.append(node)
downstream_nodes = dag[node]
while downstream_nodes:
downstream_node = downstream_nodes.pop(0)
if downstream_node not in dag:
continue
if not has_dependencies(downstream_node, dag):
independent_nodes.append(downstream_node)
if len(sorted_nodes) != len(dag.keys()):
raise ValueError('graph is not acyclic')
return sorted_nodes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:set_topological_dag_upstreams; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:dag; 5, identifier:ops; 6, identifier:op_runs; 7, identifier:runs_by_ops; 8, block; 8, 9; 8, 20; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sorted_ops; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:dags; 15, identifier:sort_topologically; 16, argument_list; 16, 17; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:dag; 19, identifier:dag; 20, for_statement; 20, 21; 20, 22; 20, 23; 21, identifier:op_id; 22, identifier:sorted_ops; 23, block; 23, 24; 23, 30; 23, 36; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:op_run_id; 27, subscript; 27, 28; 27, 29; 28, identifier:runs_by_ops; 29, identifier:op_id; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:op_run; 33, subscript; 33, 34; 33, 35; 34, identifier:op_runs; 35, identifier:op_run_id; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:set_op_upstreams; 39, argument_list; 39, 40; 39, 43; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:op_run; 42, identifier:op_run; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:op; 45, subscript; 45, 46; 45, 47; 46, identifier:ops; 47, identifier:op_id | def set_topological_dag_upstreams(dag, ops, op_runs, runs_by_ops):
sorted_ops = dags.sort_topologically(dag=dag)
for op_id in sorted_ops:
op_run_id = runs_by_ops[op_id]
op_run = op_runs[op_run_id]
set_op_upstreams(op_run=op_run, op=ops[op_id]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:generate_from_text; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:text; 6, block; 6, 7; 6, 16; 6, 23; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:words; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:process_text; 14, argument_list; 14, 15; 15, identifier:text; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:generate_from_frequencies; 21, argument_list; 21, 22; 22, identifier:words; 23, return_statement; 23, 24; 24, identifier:self | def generate_from_text(self, text):
words = self.process_text(text)
self.generate_from_frequencies(words)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_update_pods_metrics; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:instance; 6, identifier:pods; 7, block; 7, 8; 7, 15; 7, 101; 7, 111; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:tags_map; 11, call; 11, 12; 11, 13; 12, identifier:defaultdict; 13, argument_list; 13, 14; 14, identifier:int; 15, for_statement; 15, 16; 15, 17; 15, 20; 16, identifier:pod; 17, subscript; 17, 18; 17, 19; 18, identifier:pods; 19, string:'items'; 20, block; 20, 21; 20, 31; 20, 45; 20, 56; 20, 76; 20, 92; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:pod_meta; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:pod; 27, identifier:get; 28, argument_list; 28, 29; 28, 30; 29, string:'metadata'; 30, dictionary; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:pod_tags; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:kubeutil; 39, identifier:get_pod_creator_tags; 40, argument_list; 40, 41; 40, 42; 41, identifier:pod_meta; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:legacy_rep_controller_tag; 44, True; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:services; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:kubeutil; 53, identifier:match_services_for_pod; 54, argument_list; 54, 55; 55, identifier:pod_meta; 56, if_statement; 56, 57; 56, 62; 57, call; 57, 58; 57, 59; 58, identifier:isinstance; 59, argument_list; 59, 60; 59, 61; 60, identifier:services; 61, identifier:list; 62, block; 62, 63; 63, for_statement; 63, 64; 63, 65; 63, 66; 64, identifier:service; 65, identifier:services; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:pod_tags; 71, identifier:append; 72, argument_list; 72, 73; 73, binary_operator:%; 73, 74; 73, 75; 74, string:'kube_service:%s'; 75, identifier:service; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:in; 77, 78; 77, 79; 78, string:'namespace'; 79, identifier:pod_meta; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:pod_tags; 85, identifier:append; 86, argument_list; 86, 87; 87, binary_operator:%; 87, 88; 87, 89; 88, string:'kube_namespace:%s'; 89, subscript; 89, 90; 89, 91; 90, identifier:pod_meta; 91, string:'namespace'; 92, expression_statement; 92, 93; 93, augmented_assignment:+=; 93, 94; 93, 100; 94, subscript; 94, 95; 94, 96; 95, identifier:tags_map; 96, call; 96, 97; 96, 98; 97, identifier:frozenset; 98, argument_list; 98, 99; 99, identifier:pod_tags; 100, integer:1; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:commmon_tags; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:instance; 107, identifier:get; 108, argument_list; 108, 109; 108, 110; 109, string:'tags'; 110, list:[]; 111, for_statement; 111, 112; 111, 115; 111, 120; 112, pattern_list; 112, 113; 112, 114; 113, identifier:pod_tags; 114, identifier:pod_count; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:tags_map; 118, identifier:iteritems; 119, argument_list; 120, block; 120, 121; 120, 128; 120, 135; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:tags; 124, call; 124, 125; 124, 126; 125, identifier:list; 126, argument_list; 126, 127; 127, identifier:pod_tags; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:tags; 132, identifier:extend; 133, argument_list; 133, 134; 134, identifier:commmon_tags; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:publish_gauge; 140, argument_list; 140, 141; 140, 142; 140, 145; 140, 146; 141, identifier:self; 142, binary_operator:+; 142, 143; 142, 144; 143, identifier:NAMESPACE; 144, string:'.pods.running'; 145, identifier:pod_count; 146, identifier:tags | def _update_pods_metrics(self, instance, pods):
tags_map = defaultdict(int)
for pod in pods['items']:
pod_meta = pod.get('metadata', {})
pod_tags = self.kubeutil.get_pod_creator_tags(pod_meta, legacy_rep_controller_tag=True)
services = self.kubeutil.match_services_for_pod(pod_meta)
if isinstance(services, list):
for service in services:
pod_tags.append('kube_service:%s' % service)
if 'namespace' in pod_meta:
pod_tags.append('kube_namespace:%s' % pod_meta['namespace'])
tags_map[frozenset(pod_tags)] += 1
commmon_tags = instance.get('tags', [])
for pod_tags, pod_count in tags_map.iteritems():
tags = list(pod_tags)
tags.extend(commmon_tags)
self.publish_gauge(self, NAMESPACE + '.pods.running', pod_count, tags) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_agent_tags; 3, parameters; 3, 4; 3, 5; 4, identifier:since; 5, identifier:to; 6, block; 6, 7; 6, 23; 6, 42; 6, 49; 6, 62; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:agent_tags; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, generator_expression; 12, 13; 12, 17; 13, call; 13, 14; 13, 15; 14, identifier:parse_version_info; 15, argument_list; 15, 16; 16, identifier:t; 17, for_in_clause; 17, 18; 17, 19; 18, identifier:t; 19, call; 19, 20; 19, 21; 20, identifier:git_tag_list; 21, argument_list; 21, 22; 22, string:r'^\d+\.\d+\.\d+$'; 23, if_statement; 23, 24; 23, 25; 23, 33; 24, identifier:to; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:to; 29, call; 29, 30; 29, 31; 30, identifier:parse_version_info; 31, argument_list; 31, 32; 32, identifier:to; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:to; 38, subscript; 38, 39; 38, 40; 39, identifier:agent_tags; 40, unary_operator:-; 40, 41; 41, integer:1; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:since; 45, call; 45, 46; 45, 47; 46, identifier:parse_version_info; 47, argument_list; 47, 48; 48, identifier:since; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:agent_tags; 52, list_comprehension; 52, 53; 52, 54; 52, 57; 53, identifier:t; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:t; 56, identifier:agent_tags; 57, if_clause; 57, 58; 58, comparison_operator:<=; 58, 59; 58, 60; 58, 61; 59, identifier:since; 60, identifier:t; 61, identifier:to; 62, return_statement; 62, 63; 63, list_comprehension; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:str; 66, argument_list; 66, 67; 67, identifier:t; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:t; 70, call; 70, 71; 70, 72; 71, identifier:reversed; 72, argument_list; 72, 73; 73, identifier:agent_tags | def get_agent_tags(since, to):
agent_tags = sorted(parse_version_info(t) for t in git_tag_list(r'^\d+\.\d+\.\d+$'))
if to:
to = parse_version_info(to)
else:
to = agent_tags[-1]
since = parse_version_info(since)
agent_tags = [t for t in agent_tags if since <= t <= to]
return [str(t) for t in reversed(agent_tags)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key_or_list; 6, default_parameter; 6, 7; 6, 8; 7, identifier:direction; 8, None; 9, block; 9, 10; 9, 16; 9, 26; 9, 37; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:__check_okay_to_chain; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:keys; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:helpers; 22, identifier:_index_list; 23, argument_list; 23, 24; 23, 25; 24, identifier:key_or_list; 25, identifier:direction; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:__ordering; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:helpers; 34, identifier:_index_document; 35, argument_list; 35, 36; 36, identifier:keys; 37, return_statement; 37, 38; 38, identifier:self | def sort(self, key_or_list, direction=None):
self.__check_okay_to_chain()
keys = helpers._index_list(key_or_list, direction)
self.__ordering = helpers._index_document(keys)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:find_one_and_replace; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 21; 4, identifier:self; 5, identifier:filter; 6, identifier:replacement; 7, default_parameter; 7, 8; 7, 9; 8, identifier:projection; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sort; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:upsert; 15, False; 16, default_parameter; 16, 17; 16, 18; 17, identifier:return_document; 18, attribute; 18, 19; 18, 20; 19, identifier:ReturnDocument; 20, identifier:BEFORE; 21, dictionary_splat_pattern; 21, 22; 22, identifier:kwargs; 23, block; 23, 24; 23, 31; 23, 37; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:common; 28, identifier:validate_ok_for_replace; 29, argument_list; 29, 30; 30, identifier:replacement; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:kwargs; 35, string:'update'; 36, identifier:replacement; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:__find_and_modify; 42, argument_list; 42, 43; 42, 44; 42, 45; 42, 46; 42, 47; 42, 48; 43, identifier:filter; 44, identifier:projection; 45, identifier:sort; 46, identifier:upsert; 47, identifier:return_document; 48, dictionary_splat; 48, 49; 49, identifier:kwargs | def find_one_and_replace(self, filter, replacement,
projection=None, sort=None, upsert=False,
return_document=ReturnDocument.BEFORE, **kwargs):
common.validate_ok_for_replace(replacement)
kwargs['update'] = replacement
return self.__find_and_modify(filter, projection,
sort, upsert, return_document, **kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:find_one_and_update; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 21; 4, identifier:self; 5, identifier:filter; 6, identifier:update; 7, default_parameter; 7, 8; 7, 9; 8, identifier:projection; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sort; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:upsert; 15, False; 16, default_parameter; 16, 17; 16, 18; 17, identifier:return_document; 18, attribute; 18, 19; 18, 20; 19, identifier:ReturnDocument; 20, identifier:BEFORE; 21, dictionary_splat_pattern; 21, 22; 22, identifier:kwargs; 23, block; 23, 24; 23, 31; 23, 37; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:common; 28, identifier:validate_ok_for_update; 29, argument_list; 29, 30; 30, identifier:update; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:kwargs; 35, string:'update'; 36, identifier:update; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:__find_and_modify; 42, argument_list; 42, 43; 42, 44; 42, 45; 42, 46; 42, 47; 42, 48; 43, identifier:filter; 44, identifier:projection; 45, identifier:sort; 46, identifier:upsert; 47, identifier:return_document; 48, dictionary_splat; 48, 49; 49, identifier:kwargs | def find_one_and_update(self, filter, update,
projection=None, sort=None, upsert=False,
return_document=ReturnDocument.BEFORE, **kwargs):
common.validate_ok_for_update(update)
kwargs['update'] = update
return self.__find_and_modify(filter, projection,
sort, upsert, return_document, **kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:feature_correlation; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 4, identifier:X; 5, identifier:y; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ax; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:method; 11, string:'pearson'; 12, default_parameter; 12, 13; 12, 14; 13, identifier:labels; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:sort; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:feature_index; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:feature_names; 23, None; 24, dictionary_splat_pattern; 24, 25; 25, identifier:kwargs; 26, block; 26, 27; 26, 41; 26, 51; 26, 57; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:viz; 30, call; 30, 31; 30, 32; 31, identifier:FeatureCorrelation; 32, argument_list; 32, 33; 32, 34; 32, 35; 32, 36; 32, 37; 32, 38; 32, 39; 33, identifier:ax; 34, identifier:method; 35, identifier:labels; 36, identifier:sort; 37, identifier:feature_index; 38, identifier:feature_names; 39, dictionary_splat; 39, 40; 40, identifier:kwargs; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:viz; 45, identifier:fit; 46, argument_list; 46, 47; 46, 48; 46, 49; 47, identifier:X; 48, identifier:y; 49, dictionary_splat; 49, 50; 50, identifier:kwargs; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:viz; 55, identifier:finalize; 56, argument_list; 57, return_statement; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:viz; 60, identifier:ax | def feature_correlation(X, y, ax=None, method='pearson',
labels=None, sort=False, feature_index=None,
feature_names=None, **kwargs):
viz = FeatureCorrelation(ax, method, labels, sort,
feature_index, feature_names, **kwargs)
viz.fit(X, y, **kwargs)
viz.finalize()
return viz.ax |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:dispersion; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:words; 5, identifier:corpus; 6, default_parameter; 6, 7; 6, 8; 7, identifier:y; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:ax; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:colors; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:colormap; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:labels; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:annotate_docs; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:ignore_case; 26, False; 27, dictionary_splat_pattern; 27, 28; 28, identifier:kwargs; 29, block; 29, 30; 29, 57; 29, 67; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:visualizer; 33, call; 33, 34; 33, 35; 34, identifier:DispersionPlot; 35, argument_list; 35, 36; 35, 37; 35, 40; 35, 43; 35, 46; 35, 49; 35, 52; 35, 55; 36, identifier:words; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:ax; 39, identifier:ax; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:colors; 42, identifier:colors; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:colormap; 45, identifier:colormap; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:ignore_case; 48, identifier:ignore_case; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:labels; 51, identifier:labels; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:annotate_docs; 54, identifier:annotate_docs; 55, dictionary_splat; 55, 56; 56, identifier:kwargs; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:visualizer; 61, identifier:fit; 62, argument_list; 62, 63; 62, 64; 62, 65; 63, identifier:corpus; 64, identifier:y; 65, dictionary_splat; 65, 66; 66, identifier:kwargs; 67, return_statement; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:visualizer; 70, identifier:ax | def dispersion(words, corpus, y=None, ax=None, colors=None, colormap=None,
labels=None, annotate_docs=False, ignore_case=False, **kwargs):
visualizer = DispersionPlot(
words, ax=ax, colors=colors, colormap=colormap,
ignore_case=ignore_case, labels=labels,
annotate_docs=annotate_docs, **kwargs
)
visualizer.fit(corpus, y, **kwargs)
return visualizer.ax |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted_product_set; 3, parameters; 3, 4; 3, 5; 4, identifier:array_a; 5, identifier:array_b; 6, block; 6, 7; 7, return_statement; 7, 8; 8, subscript; 8, 9; 8, 37; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:np; 12, identifier:sort; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:np; 17, identifier:concatenate; 18, argument_list; 18, 19; 18, 34; 19, list_comprehension; 19, 20; 19, 25; 20, binary_operator:*; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:array_a; 23, identifier:i; 24, identifier:array_b; 25, for_in_clause; 25, 26; 25, 27; 26, identifier:i; 27, call; 27, 28; 27, 29; 28, identifier:xrange; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:len; 32, argument_list; 32, 33; 33, identifier:array_a; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:axis; 36, integer:0; 37, slice; 37, 38; 37, 39; 37, 40; 38, colon; 39, colon; 40, unary_operator:-; 40, 41; 41, integer:1 | def sorted_product_set(array_a, array_b):
return np.sort(
np.concatenate(
[array_a[i] * array_b for i in xrange(len(array_a))], axis=0)
)[::-1] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_sorted_inputs; 3, parameters; 3, 4; 4, identifier:filename; 5, block; 5, 6; 5, 59; 5, 81; 5, 99; 5, 103; 5, 107; 5, 133; 6, with_statement; 6, 7; 6, 20; 7, with_clause; 7, 8; 8, with_item; 8, 9; 9, as_pattern; 9, 10; 9, 18; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:tf; 14, identifier:gfile; 15, identifier:Open; 16, argument_list; 16, 17; 17, identifier:filename; 18, as_pattern_target; 18, 19; 19, identifier:f; 20, block; 20, 21; 20, 34; 20, 46; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:records; 24, call; 24, 25; 24, 32; 25, attribute; 25, 26; 25, 31; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:f; 29, identifier:read; 30, argument_list; 31, identifier:split; 32, argument_list; 32, 33; 33, string:"\n"; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:inputs; 37, list_comprehension; 37, 38; 37, 43; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:record; 41, identifier:strip; 42, argument_list; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:record; 45, identifier:records; 46, if_statement; 46, 47; 46, 52; 47, not_operator; 47, 48; 48, subscript; 48, 49; 48, 50; 49, identifier:inputs; 50, unary_operator:-; 50, 51; 51, integer:1; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:inputs; 57, identifier:pop; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:input_lens; 62, list_comprehension; 62, 63; 62, 73; 63, tuple; 63, 64; 63, 65; 64, identifier:i; 65, call; 65, 66; 65, 67; 66, identifier:len; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:line; 71, identifier:split; 72, argument_list; 73, for_in_clause; 73, 74; 73, 77; 74, pattern_list; 74, 75; 74, 76; 75, identifier:i; 76, identifier:line; 77, call; 77, 78; 77, 79; 78, identifier:enumerate; 79, argument_list; 79, 80; 80, identifier:inputs; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:sorted_input_lens; 84, call; 84, 85; 84, 86; 85, identifier:sorted; 86, argument_list; 86, 87; 86, 88; 86, 96; 87, identifier:input_lens; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:key; 90, lambda; 90, 91; 90, 93; 91, lambda_parameters; 91, 92; 92, identifier:x; 93, subscript; 93, 94; 93, 95; 94, identifier:x; 95, integer:1; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:reverse; 98, True; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:sorted_inputs; 102, list:[]; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:sorted_keys; 106, dictionary; 107, for_statement; 107, 108; 107, 113; 107, 117; 108, pattern_list; 108, 109; 108, 110; 109, identifier:i; 110, tuple_pattern; 110, 111; 110, 112; 111, identifier:index; 112, identifier:_; 113, call; 113, 114; 113, 115; 114, identifier:enumerate; 115, argument_list; 115, 116; 116, identifier:sorted_input_lens; 117, block; 117, 118; 117, 127; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:sorted_inputs; 122, identifier:append; 123, argument_list; 123, 124; 124, subscript; 124, 125; 124, 126; 125, identifier:inputs; 126, identifier:index; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:sorted_keys; 131, identifier:index; 132, identifier:i; 133, return_statement; 133, 134; 134, expression_list; 134, 135; 134, 136; 135, identifier:sorted_inputs; 136, identifier:sorted_keys | def _get_sorted_inputs(filename):
with tf.gfile.Open(filename) as f:
records = f.read().split("\n")
inputs = [record.strip() for record in records]
if not inputs[-1]:
inputs.pop()
input_lens = [(i, len(line.split())) for i, line in enumerate(inputs)]
sorted_input_lens = sorted(input_lens, key=lambda x: x[1], reverse=True)
sorted_inputs = []
sorted_keys = {}
for i, (index, _) in enumerate(sorted_input_lens):
sorted_inputs.append(inputs[index])
sorted_keys[index] = i
return sorted_inputs, sorted_keys |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:games_by_time; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:start_game; 6, identifier:end_game; 7, block; 7, 8; 7, 12; 7, 44; 7, 88; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:move_count; 11, string:b'move_count'; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:rows; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:bt_table; 20, identifier:read_rows; 21, argument_list; 21, 22; 21, 28; 21, 34; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:ROWCOUNT_PREFIX; 25, identifier:format; 26, argument_list; 26, 27; 27, identifier:start_game; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:ROWCOUNT_PREFIX; 31, identifier:format; 32, argument_list; 32, 33; 33, identifier:end_game; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:filter_; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:bigtable_row_filters; 39, identifier:ColumnRangeFilter; 40, argument_list; 40, 41; 40, 42; 40, 43; 41, identifier:METADATA; 42, identifier:move_count; 43, identifier:move_count; 44, function_definition; 44, 45; 44, 46; 44, 48; 45, function_name:parse; 46, parameters; 46, 47; 47, identifier:r; 48, block; 48, 49; 48, 59; 48, 74; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:rk; 52, call; 52, 53; 52, 54; 53, identifier:str; 54, argument_list; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:r; 57, identifier:row_key; 58, string:'utf-8'; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:game; 62, subscript; 62, 63; 62, 73; 63, call; 63, 64; 63, 72; 64, attribute; 64, 65; 64, 71; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:_game_from_counter; 68, identifier:match; 69, argument_list; 69, 70; 70, identifier:rk; 71, identifier:groups; 72, argument_list; 73, integer:0; 74, return_statement; 74, 75; 75, tuple; 75, 76; 75, 87; 76, attribute; 76, 77; 76, 86; 77, subscript; 77, 78; 77, 85; 78, subscript; 78, 79; 78, 84; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:r; 82, identifier:cells; 83, identifier:METADATA; 84, identifier:move_count; 85, integer:0; 86, identifier:timestamp; 87, identifier:game; 88, return_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:sorted; 91, argument_list; 91, 92; 91, 100; 92, list_comprehension; 92, 93; 92, 97; 93, call; 93, 94; 93, 95; 94, identifier:parse; 95, argument_list; 95, 96; 96, identifier:r; 97, for_in_clause; 97, 98; 97, 99; 98, identifier:r; 99, identifier:rows; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:key; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:operator; 105, identifier:itemgetter; 106, argument_list; 106, 107; 107, integer:0 | def games_by_time(self, start_game, end_game):
move_count = b'move_count'
rows = self.bt_table.read_rows(
ROWCOUNT_PREFIX.format(start_game),
ROWCOUNT_PREFIX.format(end_game),
filter_=bigtable_row_filters.ColumnRangeFilter(
METADATA, move_count, move_count))
def parse(r):
rk = str(r.row_key, 'utf-8')
game = _game_from_counter.match(rk).groups()[0]
return (r.cells[METADATA][move_count][0].timestamp, game)
return sorted([parse(r) for r in rows], key=operator.itemgetter(0)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:bleakest_moves; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:start_game; 6, identifier:end_game; 7, block; 7, 8; 7, 12; 7, 44; 7, 98; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:bleak; 11, string:b'bleakest_q'; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:rows; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:bt_table; 20, identifier:read_rows; 21, argument_list; 21, 22; 21, 28; 21, 34; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:ROW_PREFIX; 25, identifier:format; 26, argument_list; 26, 27; 27, identifier:start_game; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:ROW_PREFIX; 31, identifier:format; 32, argument_list; 32, 33; 33, identifier:end_game; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:filter_; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:bigtable_row_filters; 39, identifier:ColumnRangeFilter; 40, argument_list; 40, 41; 40, 42; 40, 43; 41, identifier:METADATA; 42, identifier:bleak; 43, identifier:bleak; 44, function_definition; 44, 45; 44, 46; 44, 48; 45, function_name:parse; 46, parameters; 46, 47; 47, identifier:r; 48, block; 48, 49; 48, 59; 48, 74; 48, 84; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:rk; 52, call; 52, 53; 52, 54; 53, identifier:str; 54, argument_list; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:r; 57, identifier:row_key; 58, string:'utf-8'; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, pattern_list; 61, 62; 61, 63; 62, identifier:g; 63, identifier:m; 64, call; 64, 65; 64, 73; 65, attribute; 65, 66; 65, 72; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:_game_row_key; 69, identifier:match; 70, argument_list; 70, 71; 71, identifier:rk; 72, identifier:groups; 73, argument_list; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:q; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:r; 80, identifier:cell_value; 81, argument_list; 81, 82; 81, 83; 82, identifier:METADATA; 83, identifier:bleak; 84, return_statement; 84, 85; 85, expression_list; 85, 86; 85, 90; 85, 94; 86, call; 86, 87; 86, 88; 87, identifier:int; 88, argument_list; 88, 89; 89, identifier:g; 90, call; 90, 91; 90, 92; 91, identifier:int; 92, argument_list; 92, 93; 93, identifier:m; 94, call; 94, 95; 94, 96; 95, identifier:float; 96, argument_list; 96, 97; 97, identifier:q; 98, return_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:sorted; 101, argument_list; 101, 102; 101, 110; 102, list_comprehension; 102, 103; 102, 107; 103, call; 103, 104; 103, 105; 104, identifier:parse; 105, argument_list; 105, 106; 106, identifier:r; 107, for_in_clause; 107, 108; 107, 109; 108, identifier:r; 109, identifier:rows; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:key; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:operator; 115, identifier:itemgetter; 116, argument_list; 116, 117; 117, integer:2 | def bleakest_moves(self, start_game, end_game):
bleak = b'bleakest_q'
rows = self.bt_table.read_rows(
ROW_PREFIX.format(start_game),
ROW_PREFIX.format(end_game),
filter_=bigtable_row_filters.ColumnRangeFilter(
METADATA, bleak, bleak))
def parse(r):
rk = str(r.row_key, 'utf-8')
g, m = _game_row_key.match(rk).groups()
q = r.cell_value(METADATA, bleak)
return int(g), int(m), float(q)
return sorted([parse(r) for r in rows], key=operator.itemgetter(2)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_generate_subtokens; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:token_counts; 5, identifier:alphabet; 6, identifier:min_count; 7, default_parameter; 7, 8; 7, 9; 8, identifier:num_iterations; 9, integer:4; 10, default_parameter; 10, 11; 10, 12; 11, identifier:reserved_tokens; 12, None; 13, block; 13, 14; 13, 23; 13, 32; 13, 36; 13, 97; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:is; 15, 16; 15, 17; 16, identifier:reserved_tokens; 17, None; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:reserved_tokens; 22, identifier:RESERVED_TOKENS; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:subtoken_list; 26, binary_operator:+; 26, 27; 26, 28; 27, identifier:reserved_tokens; 28, call; 28, 29; 28, 30; 29, identifier:list; 30, argument_list; 30, 31; 31, identifier:alphabet; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:max_subtoken_length; 35, integer:1; 36, for_statement; 36, 37; 36, 38; 36, 42; 37, identifier:i; 38, call; 38, 39; 38, 40; 39, identifier:xrange; 40, argument_list; 40, 41; 41, identifier:num_iterations; 42, block; 42, 43; 42, 54; 42, 61; 42, 71; 42, 83; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:tf; 48, identifier:logging; 49, identifier:info; 50, argument_list; 50, 51; 51, binary_operator:%; 51, 52; 51, 53; 52, string:"\tGenerating subtokens: iteration %d"; 53, identifier:i; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:subtoken_dict; 57, call; 57, 58; 57, 59; 58, identifier:_list_to_index_dict; 59, argument_list; 59, 60; 60, identifier:subtoken_list; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:subtoken_counts; 64, call; 64, 65; 64, 66; 65, identifier:_count_and_gen_subtokens; 66, argument_list; 66, 67; 66, 68; 66, 69; 66, 70; 67, identifier:token_counts; 68, identifier:alphabet; 69, identifier:subtoken_dict; 70, identifier:max_subtoken_length; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, pattern_list; 73, 74; 73, 75; 74, identifier:subtoken_list; 75, identifier:max_subtoken_length; 76, call; 76, 77; 76, 78; 77, identifier:_gen_new_subtoken_list; 78, argument_list; 78, 79; 78, 80; 78, 81; 78, 82; 79, identifier:subtoken_counts; 80, identifier:min_count; 81, identifier:alphabet; 82, identifier:reserved_tokens; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:tf; 88, identifier:logging; 89, identifier:info; 90, argument_list; 90, 91; 91, binary_operator:%; 91, 92; 91, 93; 92, string:"\tVocab size: %d"; 93, call; 93, 94; 93, 95; 94, identifier:len; 95, argument_list; 95, 96; 96, identifier:subtoken_list; 97, return_statement; 97, 98; 98, identifier:subtoken_list | def _generate_subtokens(
token_counts, alphabet, min_count, num_iterations=4,
reserved_tokens=None):
if reserved_tokens is None:
reserved_tokens = RESERVED_TOKENS
subtoken_list = reserved_tokens + list(alphabet)
max_subtoken_length = 1
for i in xrange(num_iterations):
tf.logging.info("\tGenerating subtokens: iteration %d" % i)
subtoken_dict = _list_to_index_dict(subtoken_list)
subtoken_counts = _count_and_gen_subtokens(
token_counts, alphabet, subtoken_dict, max_subtoken_length)
subtoken_list, max_subtoken_length = _gen_new_subtoken_list(
subtoken_counts, min_count, alphabet, reserved_tokens)
tf.logging.info("\tVocab size: %d" % len(subtoken_list))
return subtoken_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sparse_svd; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:sparse_matrix; 5, identifier:num_values; 6, identifier:max_iter; 7, block; 7, 8; 7, 20; 7, 36; 7, 55; 7, 76; 8, if_statement; 8, 9; 8, 12; 9, comparison_operator:<=; 9, 10; 9, 11; 10, identifier:num_values; 11, integer:0; 12, block; 12, 13; 13, raise_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:ValueError; 16, argument_list; 16, 17; 17, binary_operator:%; 17, 18; 17, 19; 18, string:"num_values should be > 0 but instead is %d."; 19, identifier:num_values; 20, if_statement; 20, 21; 20, 28; 21, boolean_operator:and; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:max_iter; 24, None; 25, comparison_operator:<; 25, 26; 25, 27; 26, identifier:max_iter; 27, integer:0; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:ValueError; 32, argument_list; 32, 33; 33, binary_operator:%; 33, 34; 33, 35; 34, string:"max_iter should be >= 0 but instead is %d."; 35, identifier:max_iter; 36, if_statement; 36, 37; 36, 40; 36, 47; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:max_iter; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:max_iter; 44, attribute; 44, 45; 44, 46; 45, identifier:FLAGS; 46, identifier:max_iter_sparse_svd; 47, elif_clause; 47, 48; 47, 50; 48, not_operator; 48, 49; 49, identifier:max_iter; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:max_iter; 54, None; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 61; 57, pattern_list; 57, 58; 57, 59; 57, 60; 58, identifier:u; 59, identifier:s; 60, identifier:v; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:linalg; 64, identifier:svds; 65, argument_list; 65, 66; 65, 67; 65, 70; 65, 73; 66, identifier:sparse_matrix; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:k; 69, identifier:num_values; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:maxiter; 72, identifier:max_iter; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:return_singular_vectors; 75, True; 76, return_statement; 76, 77; 77, tuple; 77, 78; 77, 79; 77, 80; 78, identifier:u; 79, identifier:s; 80, identifier:v | def sparse_svd(sparse_matrix, num_values, max_iter):
if num_values <= 0:
raise ValueError("num_values should be > 0 but instead is %d." % num_values)
if max_iter is not None and max_iter < 0:
raise ValueError("max_iter should be >= 0 but instead is %d." % max_iter)
if max_iter is None:
max_iter = FLAGS.max_iter_sparse_svd
elif not max_iter:
max_iter = None
u, s, v = linalg.svds(
sparse_matrix, k=num_values, maxiter=max_iter,
return_singular_vectors=True)
return (u, s, v) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:build_collate_fn; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:batch_first; 6, False; 7, default_parameter; 7, 8; 7, 9; 8, identifier:parallel; 9, True; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sort; 12, False; 13, block; 13, 14; 13, 109; 13, 181; 13, 241; 14, function_definition; 14, 15; 14, 16; 14, 18; 15, function_name:collate_seq; 16, parameters; 16, 17; 17, identifier:seq; 18, block; 18, 19; 18, 30; 18, 37; 18, 46; 18, 63; 18, 94; 18, 105; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:lengths; 22, list_comprehension; 22, 23; 22, 27; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:s; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:s; 29, identifier:seq; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:batch_length; 33, call; 33, 34; 33, 35; 34, identifier:max; 35, argument_list; 35, 36; 36, identifier:lengths; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:shape; 40, tuple; 40, 41; 40, 42; 41, identifier:batch_length; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:seq; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:seq_tensor; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:torch; 52, identifier:full; 53, argument_list; 53, 54; 53, 55; 53, 58; 54, identifier:shape; 55, attribute; 55, 56; 55, 57; 56, identifier:config; 57, identifier:PAD; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:dtype; 60, attribute; 60, 61; 60, 62; 61, identifier:torch; 62, identifier:int64; 63, for_statement; 63, 64; 63, 67; 63, 71; 64, pattern_list; 64, 65; 64, 66; 65, identifier:i; 66, identifier:s; 67, call; 67, 68; 67, 69; 68, identifier:enumerate; 69, argument_list; 69, 70; 70, identifier:seq; 71, block; 71, 72; 71, 78; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:end_seq; 75, subscript; 75, 76; 75, 77; 76, identifier:lengths; 77, identifier:i; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 88; 80, attribute; 80, 81; 80, 87; 81, subscript; 81, 82; 81, 83; 81, 86; 82, identifier:seq_tensor; 83, slice; 83, 84; 83, 85; 84, colon; 85, identifier:end_seq; 86, identifier:i; 87, identifier:copy_; 88, argument_list; 88, 89; 89, subscript; 89, 90; 89, 91; 90, identifier:s; 91, slice; 91, 92; 91, 93; 92, colon; 93, identifier:end_seq; 94, if_statement; 94, 95; 94, 96; 95, identifier:batch_first; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:seq_tensor; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:seq_tensor; 103, identifier:t; 104, argument_list; 105, return_statement; 105, 106; 106, tuple; 106, 107; 106, 108; 107, identifier:seq_tensor; 108, identifier:lengths; 109, function_definition; 109, 110; 109, 111; 109, 113; 110, function_name:parallel_collate; 111, parameters; 111, 112; 112, identifier:seqs; 113, block; 113, 114; 113, 124; 113, 167; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, pattern_list; 116, 117; 116, 118; 117, identifier:src_seqs; 118, identifier:tgt_seqs; 119, call; 119, 120; 119, 121; 120, identifier:zip; 121, argument_list; 121, 122; 122, list_splat; 122, 123; 123, identifier:seqs; 124, if_statement; 124, 125; 124, 126; 125, identifier:sort; 126, block; 126, 127; 126, 157; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, pattern_list; 129, 130; 129, 131; 130, identifier:indices; 131, identifier:src_seqs; 132, call; 132, 133; 132, 134; 133, identifier:zip; 134, argument_list; 134, 135; 135, list_splat; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:sorted; 138, argument_list; 138, 139; 138, 143; 138, 154; 139, call; 139, 140; 139, 141; 140, identifier:enumerate; 141, argument_list; 141, 142; 142, identifier:src_seqs; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:key; 145, lambda; 145, 146; 145, 148; 146, lambda_parameters; 146, 147; 147, identifier:item; 148, call; 148, 149; 148, 150; 149, identifier:len; 150, argument_list; 150, 151; 151, subscript; 151, 152; 151, 153; 152, identifier:item; 153, integer:1; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:reverse; 156, True; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:tgt_seqs; 160, list_comprehension; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:tgt_seqs; 163, identifier:idx; 164, for_in_clause; 164, 165; 164, 166; 165, identifier:idx; 166, identifier:indices; 167, return_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:tuple; 170, argument_list; 170, 171; 171, list_comprehension; 171, 172; 171, 176; 172, call; 172, 173; 172, 174; 173, identifier:collate_seq; 174, argument_list; 174, 175; 175, identifier:s; 176, for_in_clause; 176, 177; 176, 178; 177, identifier:s; 178, list:[src_seqs, tgt_seqs]; 178, 179; 178, 180; 179, identifier:src_seqs; 180, identifier:tgt_seqs; 181, function_definition; 181, 182; 181, 183; 181, 185; 182, function_name:single_collate; 183, parameters; 183, 184; 184, identifier:src_seqs; 185, block; 185, 186; 185, 231; 186, if_statement; 186, 187; 186, 188; 186, 219; 187, identifier:sort; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, pattern_list; 191, 192; 191, 193; 192, identifier:indices; 193, identifier:src_seqs; 194, call; 194, 195; 194, 196; 195, identifier:zip; 196, argument_list; 196, 197; 197, list_splat; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:sorted; 200, argument_list; 200, 201; 200, 205; 200, 216; 201, call; 201, 202; 201, 203; 202, identifier:enumerate; 203, argument_list; 203, 204; 204, identifier:src_seqs; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:key; 207, lambda; 207, 208; 207, 210; 208, lambda_parameters; 208, 209; 209, identifier:item; 210, call; 210, 211; 210, 212; 211, identifier:len; 212, argument_list; 212, 213; 213, subscript; 213, 214; 213, 215; 214, identifier:item; 215, integer:1; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:reverse; 218, True; 219, else_clause; 219, 220; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:indices; 224, call; 224, 225; 224, 226; 225, identifier:range; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 229; 228, identifier:len; 229, argument_list; 229, 230; 230, identifier:src_seqs; 231, return_statement; 231, 232; 232, expression_list; 232, 233; 232, 237; 233, call; 233, 234; 233, 235; 234, identifier:collate_seq; 235, argument_list; 235, 236; 236, identifier:src_seqs; 237, call; 237, 238; 237, 239; 238, identifier:tuple; 239, argument_list; 239, 240; 240, identifier:indices; 241, if_statement; 241, 242; 241, 243; 241, 246; 242, identifier:parallel; 243, block; 243, 244; 244, return_statement; 244, 245; 245, identifier:parallel_collate; 246, else_clause; 246, 247; 247, block; 247, 248; 248, return_statement; 248, 249; 249, identifier:single_collate | def build_collate_fn(batch_first=False, parallel=True, sort=False):
def collate_seq(seq):
lengths = [len(s) for s in seq]
batch_length = max(lengths)
shape = (batch_length, len(seq))
seq_tensor = torch.full(shape, config.PAD, dtype=torch.int64)
for i, s in enumerate(seq):
end_seq = lengths[i]
seq_tensor[:end_seq, i].copy_(s[:end_seq])
if batch_first:
seq_tensor = seq_tensor.t()
return (seq_tensor, lengths)
def parallel_collate(seqs):
src_seqs, tgt_seqs = zip(*seqs)
if sort:
indices, src_seqs = zip(*sorted(enumerate(src_seqs),
key=lambda item: len(item[1]),
reverse=True))
tgt_seqs = [tgt_seqs[idx] for idx in indices]
return tuple([collate_seq(s) for s in [src_seqs, tgt_seqs]])
def single_collate(src_seqs):
if sort:
indices, src_seqs = zip(*sorted(enumerate(src_seqs),
key=lambda item: len(item[1]),
reverse=True))
else:
indices = range(len(src_seqs))
return collate_seq(src_seqs), tuple(indices)
if parallel:
return parallel_collate
else:
return single_collate |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_golden_chunk_records; 3, parameters; 4, block; 4, 5; 4, 21; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:pattern; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:os; 12, identifier:path; 13, identifier:join; 14, argument_list; 14, 15; 14, 20; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:fsdb; 18, identifier:golden_chunk_dir; 19, argument_list; 20, string:'*.zz'; 21, return_statement; 21, 22; 22, subscript; 22, 23; 22, 37; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 25, 34; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:tf; 30, identifier:gfile; 31, identifier:Glob; 32, argument_list; 32, 33; 33, identifier:pattern; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:reverse; 36, True; 37, slice; 37, 38; 37, 39; 38, colon; 39, attribute; 39, 40; 39, 41; 40, identifier:FLAGS; 41, identifier:window_size | def get_golden_chunk_records():
pattern = os.path.join(fsdb.golden_chunk_dir(), '*.zz')
return sorted(tf.gfile.Glob(pattern), reverse=True)[:FLAGS.window_size] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_sorted_results; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:results_dicts; 6, block; 6, 7; 6, 13; 6, 28; 6, 32; 6, 45; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:print; 10, argument_list; 10, 11; 10, 12; 11, string:'results dicts:'; 12, identifier:results_dicts; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:sorted_dict; 16, call; 16, 17; 16, 18; 17, identifier:sorted; 18, argument_list; 18, 19; 18, 20; 19, identifier:results_dicts; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:key; 22, lambda; 22, 23; 22, 25; 23, lambda_parameters; 23, 24; 24, identifier:k; 25, subscript; 25, 26; 25, 27; 26, identifier:k; 27, string:'start_time'; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:results; 31, list:[]; 32, for_statement; 32, 33; 32, 34; 32, 35; 33, identifier:entry; 34, identifier:sorted_dict; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:results; 40, identifier:append; 41, argument_list; 41, 42; 42, subscript; 42, 43; 42, 44; 43, identifier:entry; 44, string:'dt'; 45, return_statement; 45, 46; 46, identifier:results | def _sorted_results(self, results_dicts):
print('results dicts:', results_dicts)
sorted_dict = sorted(results_dicts, key=lambda k: k['start_time'])
results = []
for entry in sorted_dict:
results.append(entry['dt'])
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_models; 3, parameters; 4, block; 4, 5; 4, 24; 4, 39; 4, 62; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:all_models; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:gfile; 11, identifier:Glob; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:os; 17, identifier:path; 18, identifier:join; 19, argument_list; 19, 20; 19, 23; 20, call; 20, 21; 20, 22; 21, identifier:models_dir; 22, argument_list; 23, string:'*.meta'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:model_filenames; 27, list_comprehension; 27, 28; 27, 36; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:os; 32, identifier:path; 33, identifier:basename; 34, argument_list; 34, 35; 35, identifier:m; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:m; 38, identifier:all_models; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:model_numbers_names; 42, call; 42, 43; 42, 44; 43, identifier:sorted; 44, argument_list; 44, 45; 45, list_comprehension; 45, 46; 45, 59; 46, tuple; 46, 47; 46, 53; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:shipname; 50, identifier:detect_model_num; 51, argument_list; 51, 52; 52, identifier:m; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:shipname; 56, identifier:detect_model_name; 57, argument_list; 57, 58; 58, identifier:m; 59, for_in_clause; 59, 60; 59, 61; 60, identifier:m; 61, identifier:model_filenames; 62, return_statement; 62, 63; 63, identifier:model_numbers_names | def get_models():
all_models = gfile.Glob(os.path.join(models_dir(), '*.meta'))
model_filenames = [os.path.basename(m) for m in all_models]
model_numbers_names = sorted([
(shipname.detect_model_num(m), shipname.detect_model_name(m))
for m in model_filenames])
return model_numbers_names |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 1, 19; 2, function_name:sorted_by; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:key; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Callable; 9, type_parameter; 9, 10; 9, 15; 10, type; 10, 11; 11, list:[raw_types.Qid]; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:raw_types; 14, identifier:Qid; 15, type; 15, 16; 16, identifier:Any; 17, type; 17, 18; 18, string:'QubitOrder'; 19, block; 19, 20; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:QubitOrder; 23, argument_list; 23, 24; 24, lambda; 24, 25; 24, 27; 25, lambda_parameters; 25, 26; 26, identifier:qubits; 27, call; 27, 28; 27, 29; 28, identifier:tuple; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:sorted; 32, argument_list; 32, 33; 32, 34; 33, identifier:qubits; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:key; 36, identifier:key | def sorted_by(key: Callable[[raw_types.Qid], Any]) -> 'QubitOrder':
return QubitOrder(lambda qubits: tuple(sorted(qubits, key=key))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 1, 36; 2, function_name:diagonalize_real_symmetric_and_sorted_diagonal_matrices; 3, parameters; 3, 4; 3, 10; 3, 16; 3, 17; 3, 22; 3, 27; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:symmetric_matrix; 6, type; 6, 7; 7, attribute; 7, 8; 7, 9; 8, identifier:np; 9, identifier:ndarray; 10, typed_parameter; 10, 11; 10, 12; 11, identifier:diagonal_matrix; 12, type; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:ndarray; 16, keyword_separator; 17, typed_default_parameter; 17, 18; 17, 19; 17, 21; 18, identifier:rtol; 19, type; 19, 20; 20, identifier:float; 21, float:1e-5; 22, typed_default_parameter; 22, 23; 22, 24; 22, 26; 23, identifier:atol; 24, type; 24, 25; 25, identifier:float; 26, float:1e-8; 27, typed_default_parameter; 27, 28; 27, 29; 27, 31; 28, identifier:check_preconditions; 29, type; 29, 30; 30, identifier:bool; 31, True; 32, type; 32, 33; 33, attribute; 33, 34; 33, 35; 34, identifier:np; 35, identifier:ndarray; 36, block; 36, 37; 36, 149; 36, 172; 36, 184; 36, 200; 36, 241; 37, if_statement; 37, 38; 37, 39; 38, identifier:check_preconditions; 39, block; 39, 40; 39, 73; 39, 128; 40, if_statement; 40, 41; 40, 67; 41, parenthesized_expression; 41, 42; 42, boolean_operator:or; 42, 43; 42, 54; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:any; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:np; 51, identifier:imag; 52, argument_list; 52, 53; 53, identifier:symmetric_matrix; 54, not_operator; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:predicates; 58, identifier:is_hermitian; 59, argument_list; 59, 60; 59, 61; 59, 64; 60, identifier:symmetric_matrix; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:rtol; 63, identifier:rtol; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:atol; 66, identifier:atol; 67, block; 67, 68; 68, raise_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:ValueError; 71, argument_list; 71, 72; 72, string:'symmetric_matrix must be real symmetric.'; 73, if_statement; 73, 74; 73, 122; 74, parenthesized_expression; 74, 75; 75, boolean_operator:or; 75, 76; 75, 98; 76, boolean_operator:or; 76, 77; 76, 87; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:predicates; 81, identifier:is_diagonal; 82, argument_list; 82, 83; 82, 84; 83, identifier:diagonal_matrix; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:atol; 86, identifier:atol; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:np; 90, identifier:any; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:np; 95, identifier:imag; 96, argument_list; 96, 97; 97, identifier:diagonal_matrix; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:np; 101, identifier:any; 102, argument_list; 102, 103; 103, comparison_operator:<; 103, 104; 103, 114; 104, subscript; 104, 105; 104, 106; 104, 110; 105, identifier:diagonal_matrix; 106, slice; 106, 107; 106, 108; 107, colon; 108, unary_operator:-; 108, 109; 109, integer:1; 110, slice; 110, 111; 110, 112; 111, colon; 112, unary_operator:-; 112, 113; 113, integer:1; 114, subscript; 114, 115; 114, 116; 114, 119; 115, identifier:diagonal_matrix; 116, slice; 116, 117; 116, 118; 117, integer:1; 118, colon; 119, slice; 119, 120; 119, 121; 120, integer:1; 121, colon; 122, block; 122, 123; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:ValueError; 126, argument_list; 126, 127; 127, string:'diagonal_matrix must be real diagonal descending.'; 128, if_statement; 128, 129; 128, 143; 129, not_operator; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:predicates; 133, identifier:commutes; 134, argument_list; 134, 135; 134, 136; 134, 137; 134, 140; 135, identifier:diagonal_matrix; 136, identifier:symmetric_matrix; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:rtol; 139, identifier:rtol; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:atol; 142, identifier:atol; 143, block; 143, 144; 144, raise_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:ValueError; 147, argument_list; 147, 148; 148, string:'Given matrices must commute.'; 149, function_definition; 149, 150; 149, 151; 149, 154; 150, function_name:similar_singular; 151, parameters; 151, 152; 151, 153; 152, identifier:i; 153, identifier:j; 154, block; 154, 155; 155, return_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:np; 159, identifier:allclose; 160, argument_list; 160, 161; 160, 165; 160, 169; 161, subscript; 161, 162; 161, 163; 161, 164; 162, identifier:diagonal_matrix; 163, identifier:i; 164, identifier:i; 165, subscript; 165, 166; 165, 167; 165, 168; 166, identifier:diagonal_matrix; 167, identifier:j; 168, identifier:j; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:rtol; 171, identifier:rtol; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:ranges; 175, call; 175, 176; 175, 177; 176, identifier:_contiguous_groups; 177, argument_list; 177, 178; 177, 183; 178, subscript; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:diagonal_matrix; 181, identifier:shape; 182, integer:0; 183, identifier:similar_singular; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:p; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:np; 190, identifier:zeros; 191, argument_list; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:symmetric_matrix; 194, identifier:shape; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:dtype; 197, attribute; 197, 198; 197, 199; 198, identifier:np; 199, identifier:float64; 200, for_statement; 200, 201; 200, 204; 200, 205; 201, pattern_list; 201, 202; 201, 203; 202, identifier:start; 203, identifier:end; 204, identifier:ranges; 205, block; 205, 206; 205, 219; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:block; 209, subscript; 209, 210; 209, 211; 209, 215; 210, identifier:symmetric_matrix; 211, slice; 211, 212; 211, 213; 211, 214; 212, identifier:start; 213, colon; 214, identifier:end; 215, slice; 215, 216; 215, 217; 215, 218; 216, identifier:start; 217, colon; 218, identifier:end; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 231; 221, subscript; 221, 222; 221, 223; 221, 227; 222, identifier:p; 223, slice; 223, 224; 223, 225; 223, 226; 224, identifier:start; 225, colon; 226, identifier:end; 227, slice; 227, 228; 227, 229; 227, 230; 228, identifier:start; 229, colon; 230, identifier:end; 231, call; 231, 232; 231, 233; 232, identifier:diagonalize_real_symmetric_matrix; 233, argument_list; 233, 234; 233, 235; 233, 238; 234, identifier:block; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:rtol; 237, identifier:rtol; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:atol; 240, identifier:atol; 241, return_statement; 241, 242; 242, identifier:p | def diagonalize_real_symmetric_and_sorted_diagonal_matrices(
symmetric_matrix: np.ndarray,
diagonal_matrix: np.ndarray,
*,
rtol: float = 1e-5,
atol: float = 1e-8,
check_preconditions: bool = True) -> np.ndarray:
if check_preconditions:
if (np.any(np.imag(symmetric_matrix)) or
not predicates.is_hermitian(symmetric_matrix,
rtol=rtol,
atol=atol)):
raise ValueError('symmetric_matrix must be real symmetric.')
if (not predicates.is_diagonal(diagonal_matrix, atol=atol) or
np.any(np.imag(diagonal_matrix)) or
np.any(diagonal_matrix[:-1, :-1] < diagonal_matrix[1:, 1:])):
raise ValueError(
'diagonal_matrix must be real diagonal descending.')
if not predicates.commutes(diagonal_matrix,
symmetric_matrix,
rtol=rtol,
atol=atol):
raise ValueError('Given matrices must commute.')
def similar_singular(i, j):
return np.allclose(diagonal_matrix[i, i],
diagonal_matrix[j, j], rtol=rtol)
ranges = _contiguous_groups(diagonal_matrix.shape[0], similar_singular)
p = np.zeros(symmetric_matrix.shape, dtype=np.float64)
for start, end in ranges:
block = symmetric_matrix[start:end, start:end]
p[start:end, start:end] = diagonalize_real_symmetric_matrix(
block, rtol=rtol, atol=atol)
return p |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 34; 1, 48; 2, function_name:findall_operations_between; 3, parameters; 3, 4; 3, 5; 3, 17; 3, 29; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:start_frontier; 7, type; 7, 8; 8, generic_type; 8, 9; 8, 10; 9, identifier:Dict; 10, type_parameter; 10, 11; 10, 15; 11, type; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:ops; 14, identifier:Qid; 15, type; 15, 16; 16, identifier:int; 17, typed_parameter; 17, 18; 17, 19; 18, identifier:end_frontier; 19, type; 19, 20; 20, generic_type; 20, 21; 20, 22; 21, identifier:Dict; 22, type_parameter; 22, 23; 22, 27; 23, type; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:ops; 26, identifier:Qid; 27, type; 27, 28; 28, identifier:int; 29, typed_default_parameter; 29, 30; 29, 31; 29, 33; 30, identifier:omit_crossing_operations; 31, type; 31, 32; 32, identifier:bool; 33, False; 34, type; 34, 35; 35, generic_type; 35, 36; 35, 37; 36, identifier:List; 37, type_parameter; 37, 38; 38, type; 38, 39; 39, generic_type; 39, 40; 39, 41; 40, identifier:Tuple; 41, type_parameter; 41, 42; 41, 44; 42, type; 42, 43; 43, identifier:int; 44, type; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:ops; 47, identifier:Operation; 48, block; 48, 49; 48, 62; 48, 82; 48, 151; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:result; 52, call; 52, 53; 52, 58; 53, subscript; 53, 54; 53, 55; 54, identifier:BucketPriorityQueue; 55, attribute; 55, 56; 55, 57; 56, identifier:ops; 57, identifier:Operation; 58, argument_list; 58, 59; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:drop_duplicate_entries; 61, True; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:involved_qubits; 65, binary_operator:|; 65, 66; 65, 74; 66, call; 66, 67; 66, 68; 67, identifier:set; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:start_frontier; 72, identifier:keys; 73, argument_list; 74, call; 74, 75; 74, 76; 75, identifier:set; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:end_frontier; 80, identifier:keys; 81, argument_list; 82, for_statement; 82, 83; 82, 84; 82, 88; 83, identifier:q; 84, call; 84, 85; 84, 86; 85, identifier:sorted; 86, argument_list; 86, 87; 87, identifier:involved_qubits; 88, block; 88, 89; 89, for_statement; 89, 90; 89, 91; 89, 111; 90, identifier:i; 91, call; 91, 92; 91, 93; 92, identifier:range; 93, argument_list; 93, 94; 93, 101; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:start_frontier; 97, identifier:get; 98, argument_list; 98, 99; 98, 100; 99, identifier:q; 100, integer:0; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:end_frontier; 104, identifier:get; 105, argument_list; 105, 106; 105, 107; 106, identifier:q; 107, call; 107, 108; 107, 109; 108, identifier:len; 109, argument_list; 109, 110; 110, identifier:self; 111, block; 111, 112; 111, 122; 111, 128; 111, 143; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:op; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:operation_at; 119, argument_list; 119, 120; 119, 121; 120, identifier:q; 121, identifier:i; 122, if_statement; 122, 123; 122, 126; 123, comparison_operator:is; 123, 124; 123, 125; 124, identifier:op; 125, None; 126, block; 126, 127; 127, continue_statement; 128, if_statement; 128, 129; 128, 141; 129, parenthesized_expression; 129, 130; 130, boolean_operator:and; 130, 131; 130, 132; 131, identifier:omit_crossing_operations; 132, not_operator; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:involved_qubits; 136, identifier:issuperset; 137, argument_list; 137, 138; 138, attribute; 138, 139; 138, 140; 139, identifier:op; 140, identifier:qubits; 141, block; 141, 142; 142, continue_statement; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:result; 147, identifier:enqueue; 148, argument_list; 148, 149; 148, 150; 149, identifier:i; 150, identifier:op; 151, return_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:list; 154, argument_list; 154, 155; 155, identifier:result | def findall_operations_between(self,
start_frontier: Dict[ops.Qid, int],
end_frontier: Dict[ops.Qid, int],
omit_crossing_operations: bool = False
) -> List[Tuple[int, ops.Operation]]:
result = BucketPriorityQueue[ops.Operation](
drop_duplicate_entries=True)
involved_qubits = set(start_frontier.keys()) | set(end_frontier.keys())
for q in sorted(involved_qubits):
for i in range(start_frontier.get(q, 0),
end_frontier.get(q, len(self))):
op = self.operation_at(q, i)
if op is None:
continue
if (omit_crossing_operations and
not involved_qubits.issuperset(op.qubits)):
continue
result.enqueue(i, op)
return list(result) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_GetUnsortedNotifications; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:queue_shard; 6, default_parameter; 6, 7; 6, 8; 7, identifier:notifications_by_session_id; 8, None; 9, block; 9, 10; 9, 19; 9, 33; 9, 121; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:notifications_by_session_id; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:notifications_by_session_id; 18, dictionary; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:end_time; 22, boolean_operator:or; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:frozen_timestamp; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:rdfvalue; 30, identifier:RDFDatetime; 31, identifier:Now; 32, argument_list; 33, for_statement; 33, 34; 33, 35; 33, 44; 34, identifier:notification; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:data_store; 40, identifier:GetNotifications; 41, argument_list; 41, 42; 41, 43; 42, identifier:queue_shard; 43, identifier:end_time; 44, block; 44, 45; 44, 56; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:existing; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:notifications_by_session_id; 51, identifier:get; 52, argument_list; 52, 53; 53, attribute; 53, 54; 53, 55; 54, identifier:notification; 55, identifier:session_id; 56, if_statement; 56, 57; 56, 58; 56, 111; 57, identifier:existing; 58, block; 58, 59; 59, if_statement; 59, 60; 59, 67; 59, 76; 60, comparison_operator:>; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:notification; 63, identifier:first_queued; 64, attribute; 64, 65; 64, 66; 65, identifier:existing; 66, identifier:first_queued; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 72; 71, identifier:notifications_by_session_id; 72, attribute; 72, 73; 72, 74; 73, identifier:notification; 74, identifier:session_id; 75, identifier:notification; 76, elif_clause; 76, 77; 76, 93; 77, boolean_operator:and; 77, 78; 77, 85; 78, comparison_operator:==; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:notification; 81, identifier:first_queued; 82, attribute; 82, 83; 82, 84; 83, identifier:existing; 84, identifier:first_queued; 85, parenthesized_expression; 85, 86; 86, comparison_operator:>; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:notification; 89, identifier:last_status; 90, attribute; 90, 91; 90, 92; 91, identifier:existing; 92, identifier:last_status; 93, block; 93, 94; 93, 103; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:logging; 98, identifier:warning; 99, argument_list; 99, 100; 99, 101; 99, 102; 100, string:"Notifications with equal first_queued fields detected: %s %s"; 101, identifier:notification; 102, identifier:existing; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 110; 105, subscript; 105, 106; 105, 107; 106, identifier:notifications_by_session_id; 107, attribute; 107, 108; 107, 109; 108, identifier:notification; 109, identifier:session_id; 110, identifier:notification; 111, else_clause; 111, 112; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 117; 116, identifier:notifications_by_session_id; 117, attribute; 117, 118; 117, 119; 118, identifier:notification; 119, identifier:session_id; 120, identifier:notification; 121, return_statement; 121, 122; 122, identifier:notifications_by_session_id | def _GetUnsortedNotifications(self,
queue_shard,
notifications_by_session_id=None):
if notifications_by_session_id is None:
notifications_by_session_id = {}
end_time = self.frozen_timestamp or rdfvalue.RDFDatetime.Now()
for notification in self.data_store.GetNotifications(queue_shard, end_time):
existing = notifications_by_session_id.get(notification.session_id)
if existing:
if notification.first_queued > existing.first_queued:
notifications_by_session_id[notification.session_id] = notification
elif notification.first_queued == existing.first_queued and (
notification.last_status > existing.last_status):
logging.warning(
"Notifications with equal first_queued fields detected: %s %s",
notification, existing)
notifications_by_session_id[notification.session_id] = notification
else:
notifications_by_session_id[notification.session_id] = notification
return notifications_by_session_id |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:Dump; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:obj; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_keys; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:encoder; 10, None; 11, block; 11, 12; 11, 36; 11, 56; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:text; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:json; 18, identifier:dumps; 19, argument_list; 19, 20; 19, 21; 19, 24; 19, 27; 19, 30; 19, 33; 20, identifier:obj; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:indent; 23, integer:2; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:sort_keys; 26, identifier:sort_keys; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:ensure_ascii; 29, False; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:cls; 32, identifier:encoder; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:separators; 35, identifier:_SEPARATORS; 36, if_statement; 36, 37; 36, 46; 37, boolean_operator:and; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:compatibility; 40, identifier:PY2; 41, call; 41, 42; 41, 43; 42, identifier:isinstance; 43, argument_list; 43, 44; 43, 45; 44, identifier:text; 45, identifier:bytes; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:text; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:text; 53, identifier:decode; 54, argument_list; 54, 55; 55, string:"utf-8"; 56, return_statement; 56, 57; 57, identifier:text | def Dump(obj,
sort_keys = False,
encoder = None):
text = json.dumps(
obj,
indent=2,
sort_keys=sort_keys,
ensure_ascii=False,
cls=encoder,
separators=_SEPARATORS)
if compatibility.PY2 and isinstance(text, bytes):
text = text.decode("utf-8")
return text |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:NamedPlaceholders; 3, parameters; 3, 4; 4, identifier:iterable; 5, block; 5, 6; 5, 26; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:placeholders; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, string:", "; 12, identifier:join; 13, generator_expression; 13, 14; 13, 20; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, string:"%({})s"; 17, identifier:format; 18, argument_list; 18, 19; 19, identifier:key; 20, for_in_clause; 20, 21; 20, 22; 21, identifier:key; 22, call; 22, 23; 22, 24; 23, identifier:sorted; 24, argument_list; 24, 25; 25, identifier:iterable; 26, return_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:"({})"; 30, identifier:format; 31, argument_list; 31, 32; 32, identifier:placeholders | def NamedPlaceholders(iterable):
placeholders = ", ".join("%({})s".format(key) for key in sorted(iterable))
return "({})".format(placeholders) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:Columns; 3, parameters; 3, 4; 4, identifier:iterable; 5, block; 5, 6; 5, 13; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:columns; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12, identifier:iterable; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, string:"({})"; 17, identifier:format; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, string:", "; 22, identifier:join; 23, generator_expression; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, string:"`{}`"; 27, identifier:format; 28, argument_list; 28, 29; 29, identifier:col; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:col; 32, identifier:columns | def Columns(iterable):
columns = sorted(iterable)
return "({})".format(", ".join("`{}`".format(col) for col in columns)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:GetArtifactsForCollection; 3, parameters; 3, 4; 3, 5; 4, identifier:os_name; 5, identifier:artifact_list; 6, block; 6, 7; 6, 15; 6, 23; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:artifact_arranger; 10, call; 10, 11; 10, 12; 11, identifier:ArtifactArranger; 12, argument_list; 12, 13; 12, 14; 13, identifier:os_name; 14, identifier:artifact_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:artifact_names; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:artifact_arranger; 21, identifier:GetArtifactsInProperOrder; 22, argument_list; 23, return_statement; 23, 24; 24, identifier:artifact_names | def GetArtifactsForCollection(os_name, artifact_list):
artifact_arranger = ArtifactArranger(os_name, artifact_list)
artifact_names = artifact_arranger.GetArtifactsInProperOrder()
return artifact_names |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_FilterOutPathInfoDuplicates; 3, parameters; 3, 4; 4, identifier:path_infos; 5, block; 5, 6; 5, 10; 5, 39; 5, 66; 5, 94; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:pi_dict; 9, dictionary; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:pi; 12, identifier:path_infos; 13, block; 13, 14; 13, 26; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:path_key; 17, tuple; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:pi; 20, identifier:path_type; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:pi; 24, identifier:GetPathID; 25, argument_list; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 37; 28, attribute; 28, 29; 28, 36; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:pi_dict; 32, identifier:setdefault; 33, argument_list; 33, 34; 33, 35; 34, identifier:path_key; 35, list:[]; 36, identifier:append; 37, argument_list; 37, 38; 38, identifier:pi; 39, function_definition; 39, 40; 39, 41; 39, 43; 40, function_name:_SortKey; 41, parameters; 41, 42; 42, identifier:pi; 43, block; 43, 44; 44, return_statement; 44, 45; 45, tuple; 45, 46; 45, 51; 45, 56; 45, 61; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:pi; 49, identifier:stat_entry; 50, identifier:st_ctime; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:pi; 54, identifier:stat_entry; 55, identifier:st_mtime; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:pi; 59, identifier:stat_entry; 60, identifier:st_atime; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:pi; 64, identifier:stat_entry; 65, identifier:st_ino; 66, for_statement; 66, 67; 66, 68; 66, 73; 67, identifier:pi_values; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:pi_dict; 71, identifier:values; 72, argument_list; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 81; 75, comparison_operator:>; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:pi_values; 80, integer:1; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:pi_values; 86, identifier:sort; 87, argument_list; 87, 88; 87, 91; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:key; 90, identifier:_SortKey; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:reverse; 93, True; 94, return_statement; 94, 95; 95, list_comprehension; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:v; 98, integer:0; 99, for_in_clause; 99, 100; 99, 101; 100, identifier:v; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:pi_dict; 104, identifier:values; 105, argument_list | def _FilterOutPathInfoDuplicates(path_infos):
pi_dict = {}
for pi in path_infos:
path_key = (pi.path_type, pi.GetPathID())
pi_dict.setdefault(path_key, []).append(pi)
def _SortKey(pi):
return (
pi.stat_entry.st_ctime,
pi.stat_entry.st_mtime,
pi.stat_entry.st_atime,
pi.stat_entry.st_ino,
)
for pi_values in pi_dict.values():
if len(pi_values) > 1:
pi_values.sort(key=_SortKey, reverse=True)
return [v[0] for v in pi_dict.values()] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:DrainTaskSchedulerQueueForClient; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:client; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_count; 8, None; 9, block; 9, 10; 9, 21; 9, 28; 9, 37; 9, 45; 9, 230; 9, 245; 9, 267; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:max_count; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:max_count; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:max_queue_size; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:<=; 22, 23; 22, 24; 23, identifier:max_count; 24, integer:0; 25, block; 25, 26; 26, return_statement; 26, 27; 27, list:[]; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:client; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:rdf_client; 34, identifier:ClientURN; 35, argument_list; 35, 36; 36, identifier:client; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:start_time; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:time; 43, identifier:time; 44, argument_list; 45, if_statement; 45, 46; 45, 51; 45, 95; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:data_store; 49, identifier:RelationalDBEnabled; 50, argument_list; 51, block; 51, 52; 51, 82; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:action_requests; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:data_store; 59, identifier:REL_DB; 60, identifier:LeaseClientActionRequests; 61, argument_list; 61, 62; 61, 67; 61, 79; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:client; 65, identifier:Basename; 66, argument_list; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:lease_time; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:rdfvalue; 73, identifier:Duration; 74, identifier:FromSeconds; 75, argument_list; 75, 76; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:message_expiry_time; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:limit; 81, identifier:max_count; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:result; 85, list_comprehension; 85, 86; 85, 92; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:rdf_flow_objects; 89, identifier:GRRMessageFromClientActionRequest; 90, argument_list; 90, 91; 91, identifier:r; 92, for_in_clause; 92, 93; 92, 94; 93, identifier:r; 94, identifier:action_requests; 95, else_clause; 95, 96; 96, block; 96, 97; 96, 129; 96, 139; 96, 143; 96, 147; 96, 176; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:new_tasks; 100, call; 100, 101; 100, 113; 101, attribute; 101, 102; 101, 112; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:queue_manager; 105, identifier:QueueManager; 106, argument_list; 106, 107; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:token; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:token; 112, identifier:QueryAndOwn; 113, argument_list; 113, 114; 113, 121; 113, 124; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:queue; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:client; 119, identifier:Queue; 120, argument_list; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:limit; 123, identifier:max_count; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:lease_seconds; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:message_expiry_time; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:initial_ttl; 132, attribute; 132, 133; 132, 138; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:rdf_flows; 136, identifier:GrrMessage; 137, argument_list; 138, identifier:task_ttl; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:check_before_sending; 142, list:[]; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:result; 146, list:[]; 147, for_statement; 147, 148; 147, 149; 147, 150; 148, identifier:task; 149, identifier:new_tasks; 150, block; 150, 151; 151, if_statement; 151, 152; 151, 159; 151, 167; 152, comparison_operator:<; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:task; 155, identifier:task_ttl; 156, binary_operator:-; 156, 157; 156, 158; 157, identifier:initial_ttl; 158, integer:1; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:check_before_sending; 164, identifier:append; 165, argument_list; 165, 166; 166, identifier:task; 167, else_clause; 167, 168; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:result; 173, identifier:append; 174, argument_list; 174, 175; 175, identifier:task; 176, if_statement; 176, 177; 176, 178; 177, identifier:check_before_sending; 178, block; 178, 179; 179, with_statement; 179, 180; 179, 195; 180, with_clause; 180, 181; 181, with_item; 181, 182; 182, as_pattern; 182, 183; 182, 193; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:queue_manager; 186, identifier:QueueManager; 187, argument_list; 187, 188; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:token; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:token; 193, as_pattern_target; 193, 194; 194, identifier:manager; 195, block; 195, 196; 195, 205; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:status_found; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:manager; 202, identifier:MultiCheckStatus; 203, argument_list; 203, 204; 204, identifier:check_before_sending; 205, for_statement; 205, 206; 205, 207; 205, 208; 206, identifier:task; 207, identifier:check_before_sending; 208, block; 208, 209; 209, if_statement; 209, 210; 209, 213; 209, 221; 210, comparison_operator:not; 210, 211; 210, 212; 211, identifier:task; 212, identifier:status_found; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:result; 218, identifier:append; 219, argument_list; 219, 220; 220, identifier:task; 221, else_clause; 221, 222; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:manager; 227, identifier:DeQueueClientRequest; 228, argument_list; 228, 229; 229, identifier:task; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 239; 232, attribute; 232, 233; 232, 238; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:stats_collector_instance; 236, identifier:Get; 237, argument_list; 238, identifier:IncrementCounter; 239, argument_list; 239, 240; 239, 241; 240, string:"grr_messages_sent"; 241, call; 241, 242; 241, 243; 242, identifier:len; 243, argument_list; 243, 244; 244, identifier:result; 245, if_statement; 245, 246; 245, 247; 246, identifier:result; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:logging; 252, identifier:debug; 253, argument_list; 253, 254; 253, 255; 253, 259; 253, 260; 254, string:"Drained %d messages for %s in %s seconds."; 255, call; 255, 256; 255, 257; 256, identifier:len; 257, argument_list; 257, 258; 258, identifier:result; 259, identifier:client; 260, binary_operator:-; 260, 261; 260, 266; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:time; 264, identifier:time; 265, argument_list; 266, identifier:start_time; 267, return_statement; 267, 268; 268, identifier:result | def DrainTaskSchedulerQueueForClient(self, client, max_count=None):
if max_count is None:
max_count = self.max_queue_size
if max_count <= 0:
return []
client = rdf_client.ClientURN(client)
start_time = time.time()
if data_store.RelationalDBEnabled():
action_requests = data_store.REL_DB.LeaseClientActionRequests(
client.Basename(),
lease_time=rdfvalue.Duration.FromSeconds(self.message_expiry_time),
limit=max_count)
result = [
rdf_flow_objects.GRRMessageFromClientActionRequest(r)
for r in action_requests
]
else:
new_tasks = queue_manager.QueueManager(token=self.token).QueryAndOwn(
queue=client.Queue(),
limit=max_count,
lease_seconds=self.message_expiry_time)
initial_ttl = rdf_flows.GrrMessage().task_ttl
check_before_sending = []
result = []
for task in new_tasks:
if task.task_ttl < initial_ttl - 1:
check_before_sending.append(task)
else:
result.append(task)
if check_before_sending:
with queue_manager.QueueManager(token=self.token) as manager:
status_found = manager.MultiCheckStatus(check_before_sending)
for task in check_before_sending:
if task not in status_found:
result.append(task)
else:
manager.DeQueueClientRequest(task)
stats_collector_instance.Get().IncrementCounter("grr_messages_sent",
len(result))
if result:
logging.debug("Drained %d messages for %s in %s seconds.", len(result),
client,
time.time() - start_time)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 71; 2, function_name:federated_query; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 3, 42; 3, 45; 3, 48; 3, 51; 3, 54; 3, 57; 3, 60; 3, 63; 3, 66; 3, 69; 4, identifier:self; 5, identifier:environment_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:filter; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:query; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:natural_language_query; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:passages; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:aggregation; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:count; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:return_fields; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:offset; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:sort; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:highlight; 35, None; 36, default_parameter; 36, 37; 36, 38; 37, identifier:passages_fields; 38, None; 39, default_parameter; 39, 40; 39, 41; 40, identifier:passages_count; 41, None; 42, default_parameter; 42, 43; 42, 44; 43, identifier:passages_characters; 44, None; 45, default_parameter; 45, 46; 45, 47; 46, identifier:deduplicate; 47, None; 48, default_parameter; 48, 49; 48, 50; 49, identifier:deduplicate_field; 50, None; 51, default_parameter; 51, 52; 51, 53; 52, identifier:collection_ids; 53, None; 54, default_parameter; 54, 55; 54, 56; 55, identifier:similar; 56, None; 57, default_parameter; 57, 58; 57, 59; 58, identifier:similar_document_ids; 59, None; 60, default_parameter; 60, 61; 60, 62; 61, identifier:similar_fields; 62, None; 63, default_parameter; 63, 64; 63, 65; 64, identifier:bias; 65, None; 66, default_parameter; 66, 67; 66, 68; 67, identifier:logging_opt_out; 68, None; 69, dictionary_splat_pattern; 69, 70; 70, identifier:kwargs; 71, block; 71, 72; 71, 82; 71, 89; 71, 106; 71, 115; 71, 122; 71, 131; 71, 195; 71, 210; 71, 236; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:is; 73, 74; 73, 75; 74, identifier:environment_id; 75, None; 76, block; 76, 77; 77, raise_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:ValueError; 80, argument_list; 80, 81; 81, string:'environment_id must be provided'; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:headers; 85, dictionary; 85, 86; 86, pair; 86, 87; 86, 88; 87, string:'X-Watson-Logging-Opt-Out'; 88, identifier:logging_opt_out; 89, if_statement; 89, 90; 89, 93; 90, comparison_operator:in; 90, 91; 90, 92; 91, string:'headers'; 92, identifier:kwargs; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:headers; 98, identifier:update; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:kwargs; 103, identifier:get; 104, argument_list; 104, 105; 105, string:'headers'; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:sdk_headers; 109, call; 109, 110; 109, 111; 110, identifier:get_sdk_headers; 111, argument_list; 111, 112; 111, 113; 111, 114; 112, string:'discovery'; 113, string:'V1'; 114, string:'federated_query'; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:headers; 119, identifier:update; 120, argument_list; 120, 121; 121, identifier:sdk_headers; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:params; 125, dictionary; 125, 126; 126, pair; 126, 127; 126, 128; 127, string:'version'; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:version; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:data; 134, dictionary; 134, 135; 134, 138; 134, 141; 134, 144; 134, 147; 134, 150; 134, 153; 134, 156; 134, 159; 134, 162; 134, 165; 134, 168; 134, 171; 134, 174; 134, 177; 134, 180; 134, 183; 134, 186; 134, 189; 134, 192; 135, pair; 135, 136; 135, 137; 136, string:'filter'; 137, identifier:filter; 138, pair; 138, 139; 138, 140; 139, string:'query'; 140, identifier:query; 141, pair; 141, 142; 141, 143; 142, string:'natural_language_query'; 143, identifier:natural_language_query; 144, pair; 144, 145; 144, 146; 145, string:'passages'; 146, identifier:passages; 147, pair; 147, 148; 147, 149; 148, string:'aggregation'; 149, identifier:aggregation; 150, pair; 150, 151; 150, 152; 151, string:'count'; 152, identifier:count; 153, pair; 153, 154; 153, 155; 154, string:'return'; 155, identifier:return_fields; 156, pair; 156, 157; 156, 158; 157, string:'offset'; 158, identifier:offset; 159, pair; 159, 160; 159, 161; 160, string:'sort'; 161, identifier:sort; 162, pair; 162, 163; 162, 164; 163, string:'highlight'; 164, identifier:highlight; 165, pair; 165, 166; 165, 167; 166, string:'passages.fields'; 167, identifier:passages_fields; 168, pair; 168, 169; 168, 170; 169, string:'passages.count'; 170, identifier:passages_count; 171, pair; 171, 172; 171, 173; 172, string:'passages.characters'; 173, identifier:passages_characters; 174, pair; 174, 175; 174, 176; 175, string:'deduplicate'; 176, identifier:deduplicate; 177, pair; 177, 178; 177, 179; 178, string:'deduplicate.field'; 179, identifier:deduplicate_field; 180, pair; 180, 181; 180, 182; 181, string:'collection_ids'; 182, identifier:collection_ids; 183, pair; 183, 184; 183, 185; 184, string:'similar'; 185, identifier:similar; 186, pair; 186, 187; 186, 188; 187, string:'similar.document_ids'; 188, identifier:similar_document_ids; 189, pair; 189, 190; 189, 191; 190, string:'similar.fields'; 191, identifier:similar_fields; 192, pair; 192, 193; 192, 194; 193, string:'bias'; 194, identifier:bias; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:url; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, string:'/v1/environments/{0}/query'; 201, identifier:format; 202, argument_list; 202, 203; 203, list_splat; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:_encode_path_vars; 208, argument_list; 208, 209; 209, identifier:environment_id; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:response; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:request; 217, argument_list; 217, 218; 217, 221; 217, 224; 217, 227; 217, 230; 217, 233; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:method; 220, string:'POST'; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:url; 223, identifier:url; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:headers; 226, identifier:headers; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:params; 229, identifier:params; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:json; 232, identifier:data; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:accept_json; 235, True; 236, return_statement; 236, 237; 237, identifier:response | def federated_query(self,
environment_id,
filter=None,
query=None,
natural_language_query=None,
passages=None,
aggregation=None,
count=None,
return_fields=None,
offset=None,
sort=None,
highlight=None,
passages_fields=None,
passages_count=None,
passages_characters=None,
deduplicate=None,
deduplicate_field=None,
collection_ids=None,
similar=None,
similar_document_ids=None,
similar_fields=None,
bias=None,
logging_opt_out=None,
**kwargs):
if environment_id is None:
raise ValueError('environment_id must be provided')
headers = {'X-Watson-Logging-Opt-Out': logging_opt_out}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
sdk_headers = get_sdk_headers('discovery', 'V1', 'federated_query')
headers.update(sdk_headers)
params = {'version': self.version}
data = {
'filter': filter,
'query': query,
'natural_language_query': natural_language_query,
'passages': passages,
'aggregation': aggregation,
'count': count,
'return': return_fields,
'offset': offset,
'sort': sort,
'highlight': highlight,
'passages.fields': passages_fields,
'passages.count': passages_count,
'passages.characters': passages_characters,
'deduplicate': deduplicate,
'deduplicate.field': deduplicate_field,
'collection_ids': collection_ids,
'similar': similar,
'similar.document_ids': similar_document_ids,
'similar.fields': similar_fields,
'bias': bias
}
url = '/v1/environments/{0}/query'.format(
*self._encode_path_vars(environment_id))
response = self.request(
method='POST',
url=url,
headers=headers,
params=params,
json=data,
accept_json=True)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:query_relations; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, identifier:self; 5, identifier:environment_id; 6, identifier:collection_id; 7, default_parameter; 7, 8; 7, 9; 8, identifier:entities; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:context; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:sort; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:filter; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:count; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:evidence_count; 24, None; 25, dictionary_splat_pattern; 25, 26; 26, identifier:kwargs; 27, block; 27, 28; 27, 38; 27, 48; 27, 67; 27, 82; 27, 97; 27, 101; 27, 118; 27, 127; 27, 134; 27, 143; 27, 165; 27, 181; 27, 207; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:environment_id; 31, None; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:ValueError; 36, argument_list; 36, 37; 37, string:'environment_id must be provided'; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:collection_id; 41, None; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:ValueError; 46, argument_list; 46, 47; 47, string:'collection_id must be provided'; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:entities; 51, None; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:entities; 56, list_comprehension; 56, 57; 56, 64; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_convert_model; 61, argument_list; 61, 62; 61, 63; 62, identifier:x; 63, identifier:QueryRelationsEntity; 64, for_in_clause; 64, 65; 64, 66; 65, identifier:x; 66, identifier:entities; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:context; 70, None; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:context; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:_convert_model; 79, argument_list; 79, 80; 79, 81; 80, identifier:context; 81, identifier:QueryEntitiesContext; 82, if_statement; 82, 83; 82, 86; 83, comparison_operator:is; 83, 84; 83, 85; 84, identifier:filter; 85, None; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:filter; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:_convert_model; 94, argument_list; 94, 95; 94, 96; 95, identifier:filter; 96, identifier:QueryRelationsFilter; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:headers; 100, dictionary; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:in; 102, 103; 102, 104; 103, string:'headers'; 104, identifier:kwargs; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:headers; 110, identifier:update; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:kwargs; 115, identifier:get; 116, argument_list; 116, 117; 117, string:'headers'; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:sdk_headers; 121, call; 121, 122; 121, 123; 122, identifier:get_sdk_headers; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, string:'discovery'; 125, string:'V1'; 126, string:'query_relations'; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:headers; 131, identifier:update; 132, argument_list; 132, 133; 133, identifier:sdk_headers; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:params; 137, dictionary; 137, 138; 138, pair; 138, 139; 138, 140; 139, string:'version'; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:version; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:data; 146, dictionary; 146, 147; 146, 150; 146, 153; 146, 156; 146, 159; 146, 162; 147, pair; 147, 148; 147, 149; 148, string:'entities'; 149, identifier:entities; 150, pair; 150, 151; 150, 152; 151, string:'context'; 152, identifier:context; 153, pair; 153, 154; 153, 155; 154, string:'sort'; 155, identifier:sort; 156, pair; 156, 157; 156, 158; 157, string:'filter'; 158, identifier:filter; 159, pair; 159, 160; 159, 161; 160, string:'count'; 161, identifier:count; 162, pair; 162, 163; 162, 164; 163, string:'evidence_count'; 164, identifier:evidence_count; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:url; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, string:'/v1/environments/{0}/collections/{1}/query_relations'; 171, identifier:format; 172, argument_list; 172, 173; 173, list_splat; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:_encode_path_vars; 178, argument_list; 178, 179; 178, 180; 179, identifier:environment_id; 180, identifier:collection_id; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:response; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:request; 188, argument_list; 188, 189; 188, 192; 188, 195; 188, 198; 188, 201; 188, 204; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:method; 191, string:'POST'; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:url; 194, identifier:url; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:headers; 197, identifier:headers; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:params; 200, identifier:params; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:json; 203, identifier:data; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:accept_json; 206, True; 207, return_statement; 207, 208; 208, identifier:response | def query_relations(self,
environment_id,
collection_id,
entities=None,
context=None,
sort=None,
filter=None,
count=None,
evidence_count=None,
**kwargs):
if environment_id is None:
raise ValueError('environment_id must be provided')
if collection_id is None:
raise ValueError('collection_id must be provided')
if entities is not None:
entities = [
self._convert_model(x, QueryRelationsEntity) for x in entities
]
if context is not None:
context = self._convert_model(context, QueryEntitiesContext)
if filter is not None:
filter = self._convert_model(filter, QueryRelationsFilter)
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
sdk_headers = get_sdk_headers('discovery', 'V1', 'query_relations')
headers.update(sdk_headers)
params = {'version': self.version}
data = {
'entities': entities,
'context': context,
'sort': sort,
'filter': filter,
'count': count,
'evidence_count': evidence_count
}
url = '/v1/environments/{0}/collections/{1}/query_relations'.format(
*self._encode_path_vars(environment_id, collection_id))
response = self.request(
method='POST',
url=url,
headers=headers,
params=params,
json=data,
accept_json=True)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:query_log; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:filter; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:query; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:count; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:offset; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sort; 19, None; 20, dictionary_splat_pattern; 20, 21; 21, identifier:kwargs; 22, block; 22, 23; 22, 27; 22, 44; 22, 53; 22, 60; 22, 89; 22, 93; 22, 116; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:headers; 26, dictionary; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:in; 28, 29; 28, 30; 29, string:'headers'; 30, identifier:kwargs; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:headers; 36, identifier:update; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:kwargs; 41, identifier:get; 42, argument_list; 42, 43; 43, string:'headers'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:sdk_headers; 47, call; 47, 48; 47, 49; 48, identifier:get_sdk_headers; 49, argument_list; 49, 50; 49, 51; 49, 52; 50, string:'discovery'; 51, string:'V1'; 52, string:'query_log'; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:headers; 57, identifier:update; 58, argument_list; 58, 59; 59, identifier:sdk_headers; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:params; 63, dictionary; 63, 64; 63, 69; 63, 72; 63, 75; 63, 78; 63, 81; 64, pair; 64, 65; 64, 66; 65, string:'version'; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:version; 69, pair; 69, 70; 69, 71; 70, string:'filter'; 71, identifier:filter; 72, pair; 72, 73; 72, 74; 73, string:'query'; 74, identifier:query; 75, pair; 75, 76; 75, 77; 76, string:'count'; 77, identifier:count; 78, pair; 78, 79; 78, 80; 79, string:'offset'; 80, identifier:offset; 81, pair; 81, 82; 81, 83; 82, string:'sort'; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_convert_list; 87, argument_list; 87, 88; 88, identifier:sort; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:url; 92, string:'/v1/logs'; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:response; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:request; 100, argument_list; 100, 101; 100, 104; 100, 107; 100, 110; 100, 113; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:method; 103, string:'GET'; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:url; 106, identifier:url; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:headers; 109, identifier:headers; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:params; 112, identifier:params; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:accept_json; 115, True; 116, return_statement; 116, 117; 117, identifier:response | def query_log(self,
filter=None,
query=None,
count=None,
offset=None,
sort=None,
**kwargs):
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
sdk_headers = get_sdk_headers('discovery', 'V1', 'query_log')
headers.update(sdk_headers)
params = {
'version': self.version,
'filter': filter,
'query': query,
'count': count,
'offset': offset,
'sort': self._convert_list(sort)
}
url = '/v1/logs'
response = self.request(
method='GET',
url=url,
headers=headers,
params=params,
accept_json=True)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:list_workspaces; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:page_limit; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:include_count; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:cursor; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:include_audit; 19, None; 20, dictionary_splat_pattern; 20, 21; 21, identifier:kwargs; 22, block; 22, 23; 22, 27; 22, 44; 22, 53; 22, 60; 22, 84; 22, 88; 22, 111; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:headers; 26, dictionary; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:in; 28, 29; 28, 30; 29, string:'headers'; 30, identifier:kwargs; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:headers; 36, identifier:update; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:kwargs; 41, identifier:get; 42, argument_list; 42, 43; 43, string:'headers'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:sdk_headers; 47, call; 47, 48; 47, 49; 48, identifier:get_sdk_headers; 49, argument_list; 49, 50; 49, 51; 49, 52; 50, string:'conversation'; 51, string:'V1'; 52, string:'list_workspaces'; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:headers; 57, identifier:update; 58, argument_list; 58, 59; 59, identifier:sdk_headers; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:params; 63, dictionary; 63, 64; 63, 69; 63, 72; 63, 75; 63, 78; 63, 81; 64, pair; 64, 65; 64, 66; 65, string:'version'; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:version; 69, pair; 69, 70; 69, 71; 70, string:'page_limit'; 71, identifier:page_limit; 72, pair; 72, 73; 72, 74; 73, string:'include_count'; 74, identifier:include_count; 75, pair; 75, 76; 75, 77; 76, string:'sort'; 77, identifier:sort; 78, pair; 78, 79; 78, 80; 79, string:'cursor'; 80, identifier:cursor; 81, pair; 81, 82; 81, 83; 82, string:'include_audit'; 83, identifier:include_audit; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:url; 87, string:'/v1/workspaces'; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:response; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:request; 95, argument_list; 95, 96; 95, 99; 95, 102; 95, 105; 95, 108; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:method; 98, string:'GET'; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:url; 101, identifier:url; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:headers; 104, identifier:headers; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:params; 107, identifier:params; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:accept_json; 110, True; 111, return_statement; 111, 112; 112, identifier:response | def list_workspaces(self,
page_limit=None,
include_count=None,
sort=None,
cursor=None,
include_audit=None,
**kwargs):
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
sdk_headers = get_sdk_headers('conversation', 'V1', 'list_workspaces')
headers.update(sdk_headers)
params = {
'version': self.version,
'page_limit': page_limit,
'include_count': include_count,
'sort': sort,
'cursor': cursor,
'include_audit': include_audit
}
url = '/v1/workspaces'
response = self.request(
method='GET',
url=url,
headers=headers,
params=params,
accept_json=True)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 55; 2, function_name:list_feedback; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 3, 41; 3, 44; 3, 47; 3, 50; 3, 53; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:feedback_type; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:before; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:after; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:document_title; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:model_id; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:model_version; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:category_removed; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:category_added; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:category_not_changed; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:type_removed; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:type_added; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:type_not_changed; 40, None; 41, default_parameter; 41, 42; 41, 43; 42, identifier:page_limit; 43, None; 44, default_parameter; 44, 45; 44, 46; 45, identifier:cursor; 46, None; 47, default_parameter; 47, 48; 47, 49; 48, identifier:sort; 49, None; 50, default_parameter; 50, 51; 50, 52; 51, identifier:include_total; 52, None; 53, dictionary_splat_pattern; 53, 54; 54, identifier:kwargs; 55, block; 55, 56; 55, 60; 55, 77; 55, 86; 55, 93; 55, 150; 55, 154; 55, 177; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:headers; 59, dictionary; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:in; 61, 62; 61, 63; 62, string:'headers'; 63, identifier:kwargs; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:headers; 69, identifier:update; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:kwargs; 74, identifier:get; 75, argument_list; 75, 76; 76, string:'headers'; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:sdk_headers; 80, call; 80, 81; 80, 82; 81, identifier:get_sdk_headers; 82, argument_list; 82, 83; 82, 84; 82, 85; 83, string:'compare-comply'; 84, string:'V1'; 85, string:'list_feedback'; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:headers; 90, identifier:update; 91, argument_list; 91, 92; 92, identifier:sdk_headers; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:params; 96, dictionary; 96, 97; 96, 102; 96, 105; 96, 108; 96, 111; 96, 114; 96, 117; 96, 120; 96, 123; 96, 126; 96, 129; 96, 132; 96, 135; 96, 138; 96, 141; 96, 144; 96, 147; 97, pair; 97, 98; 97, 99; 98, string:'version'; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:version; 102, pair; 102, 103; 102, 104; 103, string:'feedback_type'; 104, identifier:feedback_type; 105, pair; 105, 106; 105, 107; 106, string:'before'; 107, identifier:before; 108, pair; 108, 109; 108, 110; 109, string:'after'; 110, identifier:after; 111, pair; 111, 112; 111, 113; 112, string:'document_title'; 113, identifier:document_title; 114, pair; 114, 115; 114, 116; 115, string:'model_id'; 116, identifier:model_id; 117, pair; 117, 118; 117, 119; 118, string:'model_version'; 119, identifier:model_version; 120, pair; 120, 121; 120, 122; 121, string:'category_removed'; 122, identifier:category_removed; 123, pair; 123, 124; 123, 125; 124, string:'category_added'; 125, identifier:category_added; 126, pair; 126, 127; 126, 128; 127, string:'category_not_changed'; 128, identifier:category_not_changed; 129, pair; 129, 130; 129, 131; 130, string:'type_removed'; 131, identifier:type_removed; 132, pair; 132, 133; 132, 134; 133, string:'type_added'; 134, identifier:type_added; 135, pair; 135, 136; 135, 137; 136, string:'type_not_changed'; 137, identifier:type_not_changed; 138, pair; 138, 139; 138, 140; 139, string:'page_limit'; 140, identifier:page_limit; 141, pair; 141, 142; 141, 143; 142, string:'cursor'; 143, identifier:cursor; 144, pair; 144, 145; 144, 146; 145, string:'sort'; 146, identifier:sort; 147, pair; 147, 148; 147, 149; 148, string:'include_total'; 149, identifier:include_total; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:url; 153, string:'/v1/feedback'; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:response; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:request; 161, argument_list; 161, 162; 161, 165; 161, 168; 161, 171; 161, 174; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:method; 164, string:'GET'; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:url; 167, identifier:url; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:headers; 170, identifier:headers; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:params; 173, identifier:params; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:accept_json; 176, True; 177, return_statement; 177, 178; 178, identifier:response | def list_feedback(self,
feedback_type=None,
before=None,
after=None,
document_title=None,
model_id=None,
model_version=None,
category_removed=None,
category_added=None,
category_not_changed=None,
type_removed=None,
type_added=None,
type_not_changed=None,
page_limit=None,
cursor=None,
sort=None,
include_total=None,
**kwargs):
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
sdk_headers = get_sdk_headers('compare-comply', 'V1', 'list_feedback')
headers.update(sdk_headers)
params = {
'version': self.version,
'feedback_type': feedback_type,
'before': before,
'after': after,
'document_title': document_title,
'model_id': model_id,
'model_version': model_version,
'category_removed': category_removed,
'category_added': category_added,
'category_not_changed': category_not_changed,
'type_removed': type_removed,
'type_added': type_added,
'type_not_changed': type_not_changed,
'page_limit': page_limit,
'cursor': cursor,
'sort': sort,
'include_total': include_total
}
url = '/v1/feedback'
response = self.request(
method='GET',
url=url,
headers=headers,
params=params,
accept_json=True)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:multi_index_insert_row; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:df; 5, identifier:index_row; 6, identifier:values_row; 7, block; 7, 8; 7, 32; 7, 49; 7, 60; 7, 88; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:row_index; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:pd; 14, identifier:MultiIndex; 15, argument_list; 15, 16; 15, 24; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:levels; 18, list_comprehension; 18, 19; 18, 21; 19, list:[i]; 19, 20; 20, identifier:i; 21, for_in_clause; 21, 22; 21, 23; 22, identifier:i; 23, identifier:index_row; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:labels; 26, list_comprehension; 26, 27; 26, 29; 27, list:[0]; 27, 28; 28, integer:0; 29, for_in_clause; 29, 30; 29, 31; 30, identifier:i; 31, identifier:index_row; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:row; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:pd; 38, identifier:DataFrame; 39, argument_list; 39, 40; 39, 41; 39, 44; 40, identifier:values_row; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:index; 43, identifier:row_index; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:columns; 46, attribute; 46, 47; 46, 48; 47, identifier:df; 48, identifier:columns; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:df; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:pd; 55, identifier:concat; 56, argument_list; 56, 57; 57, tuple; 57, 58; 57, 59; 58, identifier:df; 59, identifier:row; 60, if_statement; 60, 61; 60, 85; 61, boolean_operator:and; 61, 62; 61, 72; 62, comparison_operator:==; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:df; 66, identifier:index; 67, identifier:lexsort_depth; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:index_row; 72, comparison_operator:<; 72, 73; 72, 79; 73, subscript; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:df; 76, identifier:index; 77, unary_operator:-; 77, 78; 78, integer:2; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:df; 82, identifier:index; 83, unary_operator:-; 83, 84; 84, integer:1; 85, block; 85, 86; 86, return_statement; 86, 87; 87, identifier:df; 88, return_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:df; 92, identifier:sort_index; 93, argument_list | def multi_index_insert_row(df, index_row, values_row):
row_index = pd.MultiIndex(levels=[[i] for i in index_row],
labels=[[0] for i in index_row])
row = pd.DataFrame(values_row, index=row_index, columns=df.columns)
df = pd.concat((df, row))
if df.index.lexsort_depth == len(index_row) and df.index[-2] < df.index[-1]:
return df
return df.sort_index() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:substring_search; 3, parameters; 3, 4; 3, 5; 4, identifier:word; 5, identifier:collection; 6, block; 6, 7; 7, return_statement; 7, 8; 8, list_comprehension; 8, 9; 8, 10; 8, 16; 9, identifier:item; 10, for_in_clause; 10, 11; 10, 12; 11, identifier:item; 12, call; 12, 13; 12, 14; 13, identifier:sorted; 14, argument_list; 14, 15; 15, identifier:collection; 16, if_clause; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:item; 20, identifier:startswith; 21, argument_list; 21, 22; 22, identifier:word | def substring_search(word, collection):
return [item for item in sorted(collection) if item.startswith(word)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_nodes; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:list; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:set; 12, argument_list; 12, 13; 13, list_comprehension; 13, 14; 13, 15; 14, identifier:node; 15, for_in_clause; 15, 16; 15, 19; 16, pattern_list; 16, 17; 16, 18; 17, identifier:node; 18, identifier:timeslice; 19, call; 19, 20; 19, 27; 20, attribute; 20, 21; 20, 26; 21, call; 21, 22; 21, 23; 22, identifier:super; 23, argument_list; 23, 24; 23, 25; 24, identifier:DynamicBayesianNetwork; 25, identifier:self; 26, identifier:nodes; 27, argument_list | def _nodes(self):
return list(set([node for node, timeslice in
super(DynamicBayesianNetwork, self).nodes()])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:add_edge; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:start; 6, identifier:end; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 144; 9, 211; 9, 225; 10, try_statement; 10, 11; 10, 136; 11, block; 11, 12; 12, if_statement; 12, 13; 12, 26; 12, 32; 12, 56; 12, 81; 12, 108; 12, 122; 13, boolean_operator:or; 13, 14; 13, 20; 14, comparison_operator:!=; 14, 15; 14, 19; 15, call; 15, 16; 15, 17; 16, identifier:len; 17, argument_list; 17, 18; 18, identifier:start; 19, integer:2; 20, comparison_operator:!=; 20, 21; 20, 25; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:end; 25, integer:2; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:ValueError; 30, argument_list; 30, 31; 31, string:'Nodes must be of type (node, time_slice).'; 32, elif_clause; 32, 33; 32, 50; 33, boolean_operator:or; 33, 34; 33, 42; 34, not_operator; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:isinstance; 37, argument_list; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:start; 40, integer:1; 41, identifier:int; 42, not_operator; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:isinstance; 45, argument_list; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:end; 48, integer:1; 49, identifier:int; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:ValueError; 54, argument_list; 54, 55; 55, string:'Nodes must be of type (node, time_slice).'; 56, elif_clause; 56, 57; 56, 64; 57, comparison_operator:==; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:start; 60, integer:1; 61, subscript; 61, 62; 61, 63; 62, identifier:end; 63, integer:1; 64, block; 64, 65; 64, 73; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:start; 68, tuple; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:start; 71, integer:0; 72, integer:0; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:end; 76, tuple; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:end; 79, integer:0; 80, integer:0; 81, elif_clause; 81, 82; 81, 91; 82, comparison_operator:==; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:start; 85, integer:1; 86, binary_operator:-; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:end; 89, integer:1; 90, integer:1; 91, block; 91, 92; 91, 100; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:start; 95, tuple; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:start; 98, integer:0; 99, integer:0; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:end; 103, tuple; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:end; 106, integer:0; 107, integer:1; 108, elif_clause; 108, 109; 108, 116; 109, comparison_operator:>; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:start; 112, integer:1; 113, subscript; 113, 114; 113, 115; 114, identifier:end; 115, integer:1; 116, block; 116, 117; 117, raise_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:NotImplementedError; 120, argument_list; 120, 121; 121, string:'Edges in backward direction are not allowed.'; 122, elif_clause; 122, 123; 122, 130; 123, comparison_operator:!=; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:start; 126, integer:1; 127, subscript; 127, 128; 127, 129; 128, identifier:end; 129, integer:1; 130, block; 130, 131; 131, raise_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:ValueError; 134, argument_list; 134, 135; 135, string:"Edges over multiple time slices is not currently supported"; 136, except_clause; 136, 137; 136, 138; 137, identifier:TypeError; 138, block; 138, 139; 139, raise_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:ValueError; 142, argument_list; 142, 143; 143, string:'Nodes must be of type (node, time_slice).'; 144, if_statement; 144, 145; 144, 148; 144, 154; 145, comparison_operator:==; 145, 146; 145, 147; 146, identifier:start; 147, identifier:end; 148, block; 148, 149; 149, raise_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:ValueError; 152, argument_list; 152, 153; 153, string:'Self Loops are not allowed'; 154, elif_clause; 154, 155; 154, 189; 155, boolean_operator:and; 155, 156; 155, 180; 155, 181; 156, boolean_operator:and; 156, 157; 156, 168; 157, comparison_operator:in; 157, 158; 157, 159; 158, identifier:start; 159, call; 159, 160; 159, 167; 160, attribute; 160, 161; 160, 166; 161, call; 161, 162; 161, 163; 162, identifier:super; 163, argument_list; 163, 164; 163, 165; 164, identifier:DynamicBayesianNetwork; 165, identifier:self; 166, identifier:nodes; 167, argument_list; 168, comparison_operator:in; 168, 169; 168, 170; 168, 171; 169, identifier:end; 170, line_continuation:\; 171, call; 171, 172; 171, 179; 172, attribute; 172, 173; 172, 178; 173, call; 173, 174; 173, 175; 174, identifier:super; 175, argument_list; 175, 176; 175, 177; 176, identifier:DynamicBayesianNetwork; 177, identifier:self; 178, identifier:nodes; 179, argument_list; 180, line_continuation:\; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:nx; 184, identifier:has_path; 185, argument_list; 185, 186; 185, 187; 185, 188; 186, identifier:self; 187, identifier:end; 188, identifier:start; 189, block; 189, 190; 190, raise_statement; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:ValueError; 193, argument_list; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, string:'Loops are not allowed. Adding the edge from ({start} --> {end}) forms a loop.'; 197, identifier:format; 198, argument_list; 198, 199; 198, 205; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:start; 201, call; 201, 202; 201, 203; 202, identifier:str; 203, argument_list; 203, 204; 204, identifier:start; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:end; 207, call; 207, 208; 207, 209; 208, identifier:str; 209, argument_list; 209, 210; 210, identifier:end; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 220; 213, attribute; 213, 214; 213, 219; 214, call; 214, 215; 214, 216; 215, identifier:super; 216, argument_list; 216, 217; 216, 218; 217, identifier:DynamicBayesianNetwork; 218, identifier:self; 219, identifier:add_edge; 220, argument_list; 220, 221; 220, 222; 220, 223; 221, identifier:start; 222, identifier:end; 223, dictionary_splat; 223, 224; 224, identifier:kwargs; 225, if_statement; 225, 226; 225, 233; 225, 262; 226, comparison_operator:==; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:start; 229, integer:1; 230, subscript; 230, 231; 230, 232; 231, identifier:end; 232, integer:1; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 243; 236, attribute; 236, 237; 236, 242; 237, call; 237, 238; 237, 239; 238, identifier:super; 239, argument_list; 239, 240; 239, 241; 240, identifier:DynamicBayesianNetwork; 241, identifier:self; 242, identifier:add_edge; 243, argument_list; 243, 244; 243, 253; 244, tuple; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:start; 247, integer:0; 248, binary_operator:-; 248, 249; 248, 250; 249, integer:1; 250, subscript; 250, 251; 250, 252; 251, identifier:start; 252, integer:1; 253, tuple; 253, 254; 253, 257; 254, subscript; 254, 255; 254, 256; 255, identifier:end; 256, integer:0; 257, binary_operator:-; 257, 258; 257, 259; 258, integer:1; 259, subscript; 259, 260; 259, 261; 260, identifier:end; 261, integer:1; 262, else_clause; 262, 263; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 273; 266, attribute; 266, 267; 266, 272; 267, call; 267, 268; 267, 269; 268, identifier:super; 269, argument_list; 269, 270; 269, 271; 270, identifier:DynamicBayesianNetwork; 271, identifier:self; 272, identifier:add_node; 273, argument_list; 273, 274; 274, tuple; 274, 275; 274, 278; 275, subscript; 275, 276; 275, 277; 276, identifier:end; 277, integer:0; 278, binary_operator:-; 278, 279; 278, 280; 279, integer:1; 280, subscript; 280, 281; 280, 282; 281, identifier:end; 282, integer:1 | def add_edge(self, start, end, **kwargs):
try:
if len(start) != 2 or len(end) != 2:
raise ValueError('Nodes must be of type (node, time_slice).')
elif not isinstance(start[1], int) or not isinstance(end[1], int):
raise ValueError('Nodes must be of type (node, time_slice).')
elif start[1] == end[1]:
start = (start[0], 0)
end = (end[0], 0)
elif start[1] == end[1] - 1:
start = (start[0], 0)
end = (end[0], 1)
elif start[1] > end[1]:
raise NotImplementedError('Edges in backward direction are not allowed.')
elif start[1] != end[1]:
raise ValueError("Edges over multiple time slices is not currently supported")
except TypeError:
raise ValueError('Nodes must be of type (node, time_slice).')
if start == end:
raise ValueError('Self Loops are not allowed')
elif start in super(DynamicBayesianNetwork, self).nodes() and end \
in super(DynamicBayesianNetwork, self).nodes() and \
nx.has_path(self, end, start):
raise ValueError('Loops are not allowed. Adding the edge from ({start} --> {end}) forms a loop.'.format(
start=str(start), end=str(end)))
super(DynamicBayesianNetwork, self).add_edge(start, end, **kwargs)
if start[1] == end[1]:
super(DynamicBayesianNetwork, self).add_edge((start[0], 1 - start[1]), (end[0], 1 - end[1]))
else:
super(DynamicBayesianNetwork, self).add_node((end[0], 1 - end[1])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:estimate; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:start; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:tabu_length; 10, integer:0; 11, default_parameter; 11, 12; 11, 13; 12, identifier:max_indegree; 13, None; 14, block; 14, 15; 14, 19; 14, 29; 14, 75; 14, 79; 14, 83; 14, 239; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:epsilon; 18, float:1e-8; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:nodes; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:state_names; 27, identifier:keys; 28, argument_list; 29, if_statement; 29, 30; 29, 33; 29, 47; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:start; 32, None; 33, block; 33, 34; 33, 40; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:start; 37, call; 37, 38; 37, 39; 38, identifier:DAG; 39, argument_list; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:start; 44, identifier:add_nodes_from; 45, argument_list; 45, 46; 46, identifier:nodes; 47, elif_clause; 47, 48; 47, 69; 48, boolean_operator:or; 48, 49; 48, 55; 49, not_operator; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:isinstance; 52, argument_list; 52, 53; 52, 54; 53, identifier:start; 54, identifier:DAG; 55, not_operator; 55, 56; 56, comparison_operator:==; 56, 57; 56, 65; 57, call; 57, 58; 57, 59; 58, identifier:set; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:start; 63, identifier:nodes; 64, argument_list; 65, call; 65, 66; 65, 67; 66, identifier:set; 67, argument_list; 67, 68; 68, identifier:nodes; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:ValueError; 73, argument_list; 73, 74; 74, string:"'start' should be a DAG with the same variables as the data set, or 'None'."; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:tabu_list; 78, list:[]; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:current_model; 82, identifier:start; 83, while_statement; 83, 84; 83, 85; 84, True; 85, block; 85, 86; 85, 90; 85, 94; 85, 120; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:best_score_delta; 89, integer:0; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:best_operation; 93, None; 94, for_statement; 94, 95; 94, 98; 94, 106; 95, pattern_list; 95, 96; 95, 97; 96, identifier:operation; 97, identifier:score_delta; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:_legal_operations; 102, argument_list; 102, 103; 102, 104; 102, 105; 103, identifier:current_model; 104, identifier:tabu_list; 105, identifier:max_indegree; 106, block; 106, 107; 107, if_statement; 107, 108; 107, 111; 108, comparison_operator:>; 108, 109; 108, 110; 109, identifier:score_delta; 110, identifier:best_score_delta; 111, block; 111, 112; 111, 116; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:best_operation; 115, identifier:operation; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:best_score_delta; 119, identifier:score_delta; 120, if_statement; 120, 121; 120, 128; 120, 130; 120, 163; 120, 196; 121, boolean_operator:or; 121, 122; 121, 125; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:best_operation; 124, None; 125, comparison_operator:<; 125, 126; 125, 127; 126, identifier:best_score_delta; 127, identifier:epsilon; 128, block; 128, 129; 129, break_statement; 130, elif_clause; 130, 131; 130, 136; 131, comparison_operator:==; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:best_operation; 134, integer:0; 135, string:'+'; 136, block; 136, 137; 136, 147; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:current_model; 141, identifier:add_edge; 142, argument_list; 142, 143; 143, list_splat; 143, 144; 144, subscript; 144, 145; 144, 146; 145, identifier:best_operation; 146, integer:1; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:tabu_list; 150, subscript; 150, 151; 150, 160; 151, parenthesized_expression; 151, 152; 152, binary_operator:+; 152, 153; 152, 159; 153, list:[('-', best_operation[1])]; 153, 154; 154, tuple; 154, 155; 154, 156; 155, string:'-'; 156, subscript; 156, 157; 156, 158; 157, identifier:best_operation; 158, integer:1; 159, identifier:tabu_list; 160, slice; 160, 161; 160, 162; 161, colon; 162, identifier:tabu_length; 163, elif_clause; 163, 164; 163, 169; 164, comparison_operator:==; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:best_operation; 167, integer:0; 168, string:'-'; 169, block; 169, 170; 169, 180; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:current_model; 174, identifier:remove_edge; 175, argument_list; 175, 176; 176, list_splat; 176, 177; 177, subscript; 177, 178; 177, 179; 178, identifier:best_operation; 179, integer:1; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:tabu_list; 183, subscript; 183, 184; 183, 193; 184, parenthesized_expression; 184, 185; 185, binary_operator:+; 185, 186; 185, 192; 186, list:[('+', best_operation[1])]; 186, 187; 187, tuple; 187, 188; 187, 189; 188, string:'+'; 189, subscript; 189, 190; 189, 191; 190, identifier:best_operation; 191, integer:1; 192, identifier:tabu_list; 193, slice; 193, 194; 193, 195; 194, colon; 195, identifier:tabu_length; 196, elif_clause; 196, 197; 196, 202; 197, comparison_operator:==; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:best_operation; 200, integer:0; 201, string:'flip'; 202, block; 202, 203; 202, 211; 202, 219; 202, 227; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, pattern_list; 205, 206; 205, 207; 206, identifier:X; 207, identifier:Y; 208, subscript; 208, 209; 208, 210; 209, identifier:best_operation; 210, integer:1; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:current_model; 215, identifier:remove_edge; 216, argument_list; 216, 217; 216, 218; 217, identifier:X; 218, identifier:Y; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:current_model; 223, identifier:add_edge; 224, argument_list; 224, 225; 224, 226; 225, identifier:Y; 226, identifier:X; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:tabu_list; 230, subscript; 230, 231; 230, 236; 231, parenthesized_expression; 231, 232; 232, binary_operator:+; 232, 233; 232, 235; 233, list:[best_operation]; 233, 234; 234, identifier:best_operation; 235, identifier:tabu_list; 236, slice; 236, 237; 236, 238; 237, colon; 238, identifier:tabu_length; 239, return_statement; 239, 240; 240, identifier:current_model | def estimate(self, start=None, tabu_length=0, max_indegree=None):
epsilon = 1e-8
nodes = self.state_names.keys()
if start is None:
start = DAG()
start.add_nodes_from(nodes)
elif not isinstance(start, DAG) or not set(start.nodes()) == set(nodes):
raise ValueError("'start' should be a DAG with the same variables as the data set, or 'None'.")
tabu_list = []
current_model = start
while True:
best_score_delta = 0
best_operation = None
for operation, score_delta in self._legal_operations(current_model, tabu_list, max_indegree):
if score_delta > best_score_delta:
best_operation = operation
best_score_delta = score_delta
if best_operation is None or best_score_delta < epsilon:
break
elif best_operation[0] == '+':
current_model.add_edge(*best_operation[1])
tabu_list = ([('-', best_operation[1])] + tabu_list)[:tabu_length]
elif best_operation[0] == '-':
current_model.remove_edge(*best_operation[1])
tabu_list = ([('+', best_operation[1])] + tabu_list)[:tabu_length]
elif best_operation[0] == 'flip':
X, Y = best_operation[1]
current_model.remove_edge(X, Y)
current_model.add_edge(Y, X)
tabu_list = ([best_operation] + tabu_list)[:tabu_length]
return current_model |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:add_node; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:node; 6, default_parameter; 6, 7; 6, 8; 7, identifier:weight; 8, None; 9, block; 9, 10; 9, 64; 10, if_statement; 10, 11; 10, 31; 10, 55; 11, boolean_operator:and; 11, 12; 11, 24; 12, boolean_operator:and; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:node; 17, identifier:tuple; 18, comparison_operator:==; 18, 19; 18, 23; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:node; 23, integer:2; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:node; 29, integer:1; 30, identifier:dict; 31, block; 31, 32; 31, 38; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, pattern_list; 34, 35; 34, 36; 35, identifier:node; 36, identifier:attrs; 37, identifier:node; 38, if_statement; 38, 39; 38, 48; 39, comparison_operator:is; 39, 40; 39, 47; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:attrs; 43, identifier:get; 44, argument_list; 44, 45; 44, 46; 45, string:'weight'; 46, None; 47, None; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:attrs; 53, string:'weight'; 54, identifier:weight; 55, else_clause; 55, 56; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:attrs; 60, dictionary; 60, 61; 61, pair; 61, 62; 61, 63; 62, string:'weight'; 63, identifier:weight; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 73; 66, attribute; 66, 67; 66, 72; 67, call; 67, 68; 67, 69; 68, identifier:super; 69, argument_list; 69, 70; 69, 71; 70, identifier:DAG; 71, identifier:self; 72, identifier:add_node; 73, argument_list; 73, 74; 73, 75; 74, identifier:node; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:weight; 77, identifier:weight | def add_node(self, node, weight=None):
if isinstance(node, tuple) and len(node) == 2 and isinstance(node[1], dict):
node, attrs = node
if attrs.get('weight', None) is not None:
attrs['weight'] = weight
else:
attrs = {'weight': weight}
super(DAG, self).add_node(node, weight=weight) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:add_nodes_from; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:nodes; 6, default_parameter; 6, 7; 6, 8; 7, identifier:weights; 8, None; 9, block; 9, 10; 9, 17; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:nodes; 13, call; 13, 14; 13, 15; 14, identifier:list; 15, argument_list; 15, 16; 16, identifier:nodes; 17, if_statement; 17, 18; 17, 19; 17, 64; 18, identifier:weights; 19, block; 19, 20; 19, 38; 20, if_statement; 20, 21; 20, 30; 21, comparison_operator:!=; 21, 22; 21, 26; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, identifier:nodes; 26, call; 26, 27; 26, 28; 27, identifier:len; 28, argument_list; 28, 29; 29, identifier:weights; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:ValueError; 34, argument_list; 34, 35; 35, concatenated_string; 35, 36; 35, 37; 36, string:"The number of elements in nodes and weights"; 37, string:"should be equal."; 38, for_statement; 38, 39; 38, 40; 38, 47; 39, identifier:index; 40, call; 40, 41; 40, 42; 41, identifier:range; 42, argument_list; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, identifier:nodes; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:add_node; 53, argument_list; 53, 54; 53, 59; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:node; 56, subscript; 56, 57; 56, 58; 57, identifier:nodes; 58, identifier:index; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:weight; 61, subscript; 61, 62; 61, 63; 62, identifier:weights; 63, identifier:index; 64, else_clause; 64, 65; 65, block; 65, 66; 66, for_statement; 66, 67; 66, 68; 66, 69; 67, identifier:node; 68, identifier:nodes; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:add_node; 75, argument_list; 75, 76; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:node; 78, identifier:node | def add_nodes_from(self, nodes, weights=None):
nodes = list(nodes)
if weights:
if len(nodes) != len(weights):
raise ValueError("The number of elements in nodes and weights"
"should be equal.")
for index in range(len(nodes)):
self.add_node(node=nodes[index], weight=weights[index])
else:
for node in nodes:
self.add_node(node=node) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:rank_items; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:userid; 6, identifier:user_items; 7, identifier:selected_items; 8, default_parameter; 8, 9; 8, 10; 9, identifier:recalculate_user; 10, False; 11, block; 11, 12; 11, 36; 11, 42; 11, 53; 11, 77; 11, 91; 11, 112; 12, if_statement; 12, 13; 12, 30; 13, boolean_operator:or; 13, 14; 13, 24; 14, comparison_operator:>=; 14, 15; 14, 19; 15, call; 15, 16; 15, 17; 16, identifier:max; 17, argument_list; 17, 18; 18, identifier:selected_items; 19, subscript; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:user_items; 22, identifier:shape; 23, integer:1; 24, comparison_operator:<; 24, 25; 24, 29; 25, call; 25, 26; 25, 27; 26, identifier:min; 27, argument_list; 27, 28; 28, identifier:selected_items; 29, integer:0; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:IndexError; 34, argument_list; 34, 35; 35, string:"Some of selected itemids are not in the model"; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:liked_vector; 39, subscript; 39, 40; 39, 41; 40, identifier:user_items; 41, identifier:userid; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:recommendations; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:liked_vector; 48, identifier:dot; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:similarity; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:best; 56, call; 56, 57; 56, 58; 57, identifier:sorted; 58, argument_list; 58, 59; 58, 68; 59, call; 59, 60; 59, 61; 60, identifier:zip; 61, argument_list; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:recommendations; 64, identifier:indices; 65, attribute; 65, 66; 65, 67; 66, identifier:recommendations; 67, identifier:data; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:key; 70, lambda; 70, 71; 70, 73; 71, lambda_parameters; 71, 72; 72, identifier:x; 73, unary_operator:-; 73, 74; 74, subscript; 74, 75; 74, 76; 75, identifier:x; 76, integer:1; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:ret; 80, list_comprehension; 80, 81; 80, 82; 80, 85; 81, identifier:rec; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:rec; 84, identifier:best; 85, if_clause; 85, 86; 86, comparison_operator:in; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:rec; 89, integer:0; 90, identifier:selected_items; 91, for_statement; 91, 92; 91, 93; 91, 94; 92, identifier:itemid; 93, identifier:selected_items; 94, block; 94, 95; 95, if_statement; 95, 96; 95, 101; 96, comparison_operator:not; 96, 97; 96, 98; 97, identifier:itemid; 98, attribute; 98, 99; 98, 100; 99, identifier:recommendations; 100, identifier:indices; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:ret; 106, identifier:append; 107, argument_list; 107, 108; 108, tuple; 108, 109; 108, 110; 109, identifier:itemid; 110, unary_operator:-; 110, 111; 111, float:1.0; 112, return_statement; 112, 113; 113, identifier:ret | def rank_items(self, userid, user_items, selected_items, recalculate_user=False):
if max(selected_items) >= user_items.shape[1] or min(selected_items) < 0:
raise IndexError("Some of selected itemids are not in the model")
liked_vector = user_items[userid]
recommendations = liked_vector.dot(self.similarity)
best = sorted(zip(recommendations.indices, recommendations.data), key=lambda x: -x[1])
ret = [rec for rec in best if rec[0] in selected_items]
for itemid in selected_items:
if itemid not in recommendations.indices:
ret.append((itemid, -1.0))
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_sorted_structure; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, block; 11, 12; 11, 25; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:sites; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 19; 17, 22; 18, identifier:self; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:key; 21, identifier:key; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:reverse; 24, identifier:reverse; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:__class__; 31, identifier:from_sites; 32, argument_list; 32, 33; 32, 34; 33, identifier:sites; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:charge; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_charge | def get_sorted_structure(self, key=None, reverse=False):
sites = sorted(self, key=key, reverse=reverse)
return self.__class__.from_sites(sites, charge=self._charge) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:from_str; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:cls; 5, identifier:input_string; 6, identifier:fmt; 7, default_parameter; 7, 8; 7, 9; 8, identifier:primitive; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sort; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:merge_tol; 15, float:0.0; 16, block; 16, 17; 16, 24; 16, 31; 16, 38; 16, 45; 16, 52; 16, 60; 16, 218; 16, 229; 16, 239; 17, import_from_statement; 17, 18; 17, 22; 18, dotted_name; 18, 19; 18, 20; 18, 21; 19, identifier:pymatgen; 20, identifier:io; 21, identifier:cif; 22, dotted_name; 22, 23; 23, identifier:CifParser; 24, import_from_statement; 24, 25; 24, 29; 25, dotted_name; 25, 26; 25, 27; 25, 28; 26, identifier:pymatgen; 27, identifier:io; 28, identifier:vasp; 29, dotted_name; 29, 30; 30, identifier:Poscar; 31, import_from_statement; 31, 32; 31, 36; 32, dotted_name; 32, 33; 32, 34; 32, 35; 33, identifier:pymatgen; 34, identifier:io; 35, identifier:cssr; 36, dotted_name; 36, 37; 37, identifier:Cssr; 38, import_from_statement; 38, 39; 38, 43; 39, dotted_name; 39, 40; 39, 41; 39, 42; 40, identifier:pymatgen; 41, identifier:io; 42, identifier:xcrysden; 43, dotted_name; 43, 44; 44, identifier:XSF; 45, import_from_statement; 45, 46; 45, 50; 46, dotted_name; 46, 47; 46, 48; 46, 49; 47, identifier:pymatgen; 48, identifier:io; 49, identifier:atat; 50, dotted_name; 50, 51; 51, identifier:Mcsqs; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:fmt; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:fmt; 58, identifier:lower; 59, argument_list; 60, if_statement; 60, 61; 60, 64; 60, 87; 60, 107; 60, 127; 60, 150; 60, 179; 60, 195; 60, 209; 61, comparison_operator:==; 61, 62; 61, 63; 62, identifier:fmt; 63, string:"cif"; 64, block; 64, 65; 64, 74; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:parser; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:CifParser; 71, identifier:from_string; 72, argument_list; 72, 73; 73, identifier:input_string; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:s; 77, subscript; 77, 78; 77, 86; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:parser; 81, identifier:get_structures; 82, argument_list; 82, 83; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:primitive; 85, identifier:primitive; 86, integer:0; 87, elif_clause; 87, 88; 87, 91; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:fmt; 90, string:"poscar"; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:s; 95, attribute; 95, 96; 95, 106; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:Poscar; 99, identifier:from_string; 100, argument_list; 100, 101; 100, 102; 100, 103; 101, identifier:input_string; 102, False; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:read_velocities; 105, False; 106, identifier:structure; 107, elif_clause; 107, 108; 107, 111; 108, comparison_operator:==; 108, 109; 108, 110; 109, identifier:fmt; 110, string:"cssr"; 111, block; 111, 112; 111, 121; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:cssr; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:Cssr; 118, identifier:from_string; 119, argument_list; 119, 120; 120, identifier:input_string; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:s; 124, attribute; 124, 125; 124, 126; 125, identifier:cssr; 126, identifier:structure; 127, elif_clause; 127, 128; 127, 131; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:fmt; 130, string:"json"; 131, block; 131, 132; 131, 141; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:d; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:json; 138, identifier:loads; 139, argument_list; 139, 140; 140, identifier:input_string; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:s; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:Structure; 147, identifier:from_dict; 148, argument_list; 148, 149; 149, identifier:d; 150, elif_clause; 150, 151; 150, 154; 151, comparison_operator:==; 151, 152; 151, 153; 152, identifier:fmt; 153, string:"yaml"; 154, block; 154, 155; 154, 161; 154, 170; 155, import_statement; 155, 156; 156, aliased_import; 156, 157; 156, 160; 157, dotted_name; 157, 158; 157, 159; 158, identifier:ruamel; 159, identifier:yaml; 160, identifier:yaml; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:d; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:yaml; 167, identifier:safe_load; 168, argument_list; 168, 169; 169, identifier:input_string; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:s; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:Structure; 176, identifier:from_dict; 177, argument_list; 177, 178; 178, identifier:d; 179, elif_clause; 179, 180; 179, 183; 180, comparison_operator:==; 180, 181; 180, 182; 181, identifier:fmt; 182, string:"xsf"; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:s; 187, attribute; 187, 188; 187, 194; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:XSF; 191, identifier:from_string; 192, argument_list; 192, 193; 193, identifier:input_string; 194, identifier:structure; 195, elif_clause; 195, 196; 195, 199; 196, comparison_operator:==; 196, 197; 196, 198; 197, identifier:fmt; 198, string:"mcsqs"; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:s; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:Mcsqs; 206, identifier:structure_from_string; 207, argument_list; 207, 208; 208, identifier:input_string; 209, else_clause; 209, 210; 210, block; 210, 211; 211, raise_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:ValueError; 214, argument_list; 214, 215; 215, binary_operator:%; 215, 216; 215, 217; 216, string:"Unrecognized format `%s`!"; 217, identifier:fmt; 218, if_statement; 218, 219; 218, 220; 219, identifier:sort; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:s; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:s; 227, identifier:get_sorted_structure; 228, argument_list; 229, if_statement; 229, 230; 229, 231; 230, identifier:merge_tol; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:s; 236, identifier:merge_sites; 237, argument_list; 237, 238; 238, identifier:merge_tol; 239, return_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:cls; 243, identifier:from_sites; 244, argument_list; 244, 245; 245, identifier:s | def from_str(cls, input_string, fmt, primitive=False, sort=False,
merge_tol=0.0):
from pymatgen.io.cif import CifParser
from pymatgen.io.vasp import Poscar
from pymatgen.io.cssr import Cssr
from pymatgen.io.xcrysden import XSF
from pymatgen.io.atat import Mcsqs
fmt = fmt.lower()
if fmt == "cif":
parser = CifParser.from_string(input_string)
s = parser.get_structures(primitive=primitive)[0]
elif fmt == "poscar":
s = Poscar.from_string(input_string, False,
read_velocities=False).structure
elif fmt == "cssr":
cssr = Cssr.from_string(input_string)
s = cssr.structure
elif fmt == "json":
d = json.loads(input_string)
s = Structure.from_dict(d)
elif fmt == "yaml":
import ruamel.yaml as yaml
d = yaml.safe_load(input_string)
s = Structure.from_dict(d)
elif fmt == "xsf":
s = XSF.from_string(input_string).structure
elif fmt == "mcsqs":
s = Mcsqs.structure_from_string(input_string)
else:
raise ValueError("Unrecognized format `%s`!" % fmt)
if sort:
s = s.get_sorted_structure()
if merge_tol:
s.merge_sites(merge_tol)
return cls.from_sites(s) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_transition_chempots; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:element; 6, block; 6, 7; 6, 21; 6, 25; 6, 49; 6, 53; 6, 99; 6, 105; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:not; 8, 9; 8, 10; 9, identifier:element; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:elements; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:ValueError; 17, argument_list; 17, 18; 18, concatenated_string; 18, 19; 18, 20; 19, string:"get_transition_chempots can only be called with "; 20, string:"elements in the phase diagram."; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:critical_chempots; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 30; 26, identifier:facet; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:facets; 30, block; 30, 31; 30, 40; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:chempots; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_get_facet_chempots; 38, argument_list; 38, 39; 39, identifier:facet; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:critical_chempots; 44, identifier:append; 45, argument_list; 45, 46; 46, subscript; 46, 47; 46, 48; 47, identifier:chempots; 48, identifier:element; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:clean_pots; 52, list:[]; 53, for_statement; 53, 54; 53, 55; 53, 59; 54, identifier:c; 55, call; 55, 56; 55, 57; 56, identifier:sorted; 57, argument_list; 57, 58; 58, identifier:critical_chempots; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 67; 60, 75; 61, comparison_operator:==; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:len; 64, argument_list; 64, 65; 65, identifier:clean_pots; 66, integer:0; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:clean_pots; 72, identifier:append; 73, argument_list; 73, 74; 74, identifier:c; 75, else_clause; 75, 76; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 91; 78, comparison_operator:>; 78, 79; 78, 88; 79, call; 79, 80; 79, 81; 80, identifier:abs; 81, argument_list; 81, 82; 82, binary_operator:-; 82, 83; 82, 84; 83, identifier:c; 84, subscript; 84, 85; 84, 86; 85, identifier:clean_pots; 86, unary_operator:-; 86, 87; 87, integer:1; 88, attribute; 88, 89; 88, 90; 89, identifier:PhaseDiagram; 90, identifier:numerical_tol; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:clean_pots; 96, identifier:append; 97, argument_list; 97, 98; 98, identifier:c; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:clean_pots; 103, identifier:reverse; 104, argument_list; 105, return_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:tuple; 108, argument_list; 108, 109; 109, identifier:clean_pots | def get_transition_chempots(self, element):
if element not in self.elements:
raise ValueError("get_transition_chempots can only be called with "
"elements in the phase diagram.")
critical_chempots = []
for facet in self.facets:
chempots = self._get_facet_chempots(facet)
critical_chempots.append(chempots[element])
clean_pots = []
for c in sorted(critical_chempots):
if len(clean_pots) == 0:
clean_pots.append(c)
else:
if abs(c - clean_pots[-1]) > PhaseDiagram.numerical_tol:
clean_pots.append(c)
clean_pots.reverse()
return tuple(clean_pots) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:from_dir; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:cls; 5, identifier:top; 6, default_parameter; 6, 7; 6, 8; 7, identifier:exts; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:exclude_dirs; 11, string:"_*"; 12, block; 12, 13; 12, 17; 12, 177; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:pseudos; 16, list:[]; 17, if_statement; 17, 18; 17, 21; 17, 123; 18, comparison_operator:==; 18, 19; 18, 20; 19, identifier:exts; 20, string:"all_files"; 21, block; 21, 22; 21, 96; 21, 111; 22, for_statement; 22, 23; 22, 24; 22, 42; 23, identifier:f; 24, list_comprehension; 24, 25; 24, 34; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:os; 29, identifier:path; 30, identifier:join; 31, argument_list; 31, 32; 31, 33; 32, identifier:top; 33, identifier:fn; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:fn; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:os; 39, identifier:listdir; 40, argument_list; 40, 41; 41, identifier:top; 42, block; 42, 43; 43, if_statement; 43, 44; 43, 52; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:path; 49, identifier:isfile; 50, argument_list; 50, 51; 51, identifier:f; 52, block; 52, 53; 53, try_statement; 53, 54; 53, 85; 54, block; 54, 55; 54, 64; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:p; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:Pseudo; 61, identifier:from_file; 62, argument_list; 62, 63; 63, identifier:f; 64, if_statement; 64, 65; 64, 66; 64, 74; 65, identifier:p; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:pseudos; 71, identifier:append; 72, argument_list; 72, 73; 73, identifier:p; 74, else_clause; 74, 75; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:logger; 80, identifier:info; 81, argument_list; 81, 82; 82, binary_operator:%; 82, 83; 82, 84; 83, string:'Skipping file %s'; 84, identifier:f; 85, except_clause; 85, 86; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:logger; 91, identifier:info; 92, argument_list; 92, 93; 93, binary_operator:%; 93, 94; 93, 95; 94, string:'Skipping file %s'; 95, identifier:f; 96, if_statement; 96, 97; 96, 99; 97, not_operator; 97, 98; 98, identifier:pseudos; 99, block; 99, 100; 99, 109; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:logger; 104, identifier:warning; 105, argument_list; 105, 106; 106, binary_operator:%; 106, 107; 106, 108; 107, string:'No pseudopotentials parsed from folder %s'; 108, identifier:top; 109, return_statement; 109, 110; 110, None; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:logger; 115, identifier:info; 116, argument_list; 116, 117; 117, binary_operator:%; 117, 118; 117, 119; 118, string:'Creating PseudoTable with %i pseudopotentials'; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, identifier:pseudos; 123, else_clause; 123, 124; 124, block; 124, 125; 124, 135; 125, if_statement; 125, 126; 125, 129; 126, comparison_operator:is; 126, 127; 126, 128; 127, identifier:exts; 128, None; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:exts; 133, tuple; 133, 134; 134, string:"psp8"; 135, for_statement; 135, 136; 135, 137; 135, 145; 136, identifier:p; 137, call; 137, 138; 137, 139; 138, identifier:find_exts; 139, argument_list; 139, 140; 139, 141; 139, 142; 140, identifier:top; 141, identifier:exts; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:exclude_dirs; 144, identifier:exclude_dirs; 145, block; 145, 146; 146, try_statement; 146, 147; 146, 160; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:pseudos; 152, identifier:append; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:Pseudo; 157, identifier:from_file; 158, argument_list; 158, 159; 159, identifier:p; 160, except_clause; 160, 161; 160, 165; 161, as_pattern; 161, 162; 161, 163; 162, identifier:Exception; 163, as_pattern_target; 163, 164; 164, identifier:exc; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:logger; 170, identifier:critical; 171, argument_list; 171, 172; 172, binary_operator:%; 172, 173; 172, 174; 173, string:"Error in %s:\n%s"; 174, tuple; 174, 175; 174, 176; 175, identifier:p; 176, identifier:exc; 177, return_statement; 177, 178; 178, call; 178, 179; 178, 185; 179, attribute; 179, 180; 179, 184; 180, call; 180, 181; 180, 182; 181, identifier:cls; 182, argument_list; 182, 183; 183, identifier:pseudos; 184, identifier:sort_by_z; 185, argument_list | def from_dir(cls, top, exts=None, exclude_dirs="_*"):
pseudos = []
if exts == "all_files":
for f in [os.path.join(top, fn) for fn in os.listdir(top)]:
if os.path.isfile(f):
try:
p = Pseudo.from_file(f)
if p:
pseudos.append(p)
else:
logger.info('Skipping file %s' % f)
except:
logger.info('Skipping file %s' % f)
if not pseudos:
logger.warning('No pseudopotentials parsed from folder %s' % top)
return None
logger.info('Creating PseudoTable with %i pseudopotentials' % len(pseudos))
else:
if exts is None: exts=("psp8",)
for p in find_exts(top, exts, exclude_dirs=exclude_dirs):
try:
pseudos.append(Pseudo.from_file(p))
except Exception as exc:
logger.critical("Error in %s:\n%s" % (p, exc))
return cls(pseudos).sort_by_z() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sorted; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:attrname; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, block; 9, 10; 9, 14; 9, 48; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:attrs; 13, list:[]; 14, for_statement; 14, 15; 14, 18; 14, 19; 15, pattern_list; 15, 16; 15, 17; 16, identifier:i; 17, identifier:pseudo; 18, identifier:self; 19, block; 19, 20; 19, 39; 20, try_statement; 20, 21; 20, 30; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:a; 25, call; 25, 26; 25, 27; 26, identifier:getattr; 27, argument_list; 27, 28; 27, 29; 28, identifier:pseudo; 29, identifier:attrname; 30, except_clause; 30, 31; 30, 32; 31, identifier:AttributeError; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:a; 36, attribute; 36, 37; 36, 38; 37, identifier:np; 38, identifier:inf; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:attrs; 43, identifier:append; 44, argument_list; 44, 45; 45, tuple; 45, 46; 45, 47; 46, identifier:i; 47, identifier:a; 48, return_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:__class__; 53, argument_list; 53, 54; 54, list_comprehension; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 57; 56, identifier:self; 57, subscript; 57, 58; 57, 59; 58, identifier:a; 59, integer:0; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:a; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 64, 66; 64, 74; 65, identifier:attrs; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:key; 68, lambda; 68, 69; 68, 71; 69, lambda_parameters; 69, 70; 70, identifier:t; 71, subscript; 71, 72; 71, 73; 72, identifier:t; 73, integer:1; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:reverse; 76, identifier:reverse | def sorted(self, attrname, reverse=False):
attrs = []
for i, pseudo in self:
try:
a = getattr(pseudo, attrname)
except AttributeError:
a = np.inf
attrs.append((i, a))
return self.__class__([self[a[0]] for a in sorted(attrs, key=lambda t: t[1], reverse=reverse)]) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.