sequence
stringlengths
546
16.2k
code
stringlengths
108
19.3k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sortby; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:ntd; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 21; 9, 36; 10, comparison_operator:in; 10, 11; 10, 12; 11, string:'reldepth'; 12, subscript; 12, 13; 12, 20; 13, attribute; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:grprobj; 18, identifier:gosubdag; 19, identifier:prt_attr; 20, string:'flds'; 21, block; 21, 22; 22, return_statement; 22, 23; 23, list:[ntd.NS, -1*ntd.dcnt, ntd.reldepth]; 23, 24; 23, 27; 23, 33; 24, attribute; 24, 25; 24, 26; 25, identifier:ntd; 26, identifier:NS; 27, binary_operator:*; 27, 28; 27, 30; 28, unary_operator:-; 28, 29; 29, integer:1; 30, attribute; 30, 31; 30, 32; 31, identifier:ntd; 32, identifier:dcnt; 33, attribute; 33, 34; 33, 35; 34, identifier:ntd; 35, identifier:reldepth; 36, else_clause; 36, 37; 37, block; 37, 38; 38, return_statement; 38, 39; 39, list:[ntd.NS, -1*ntd.dcnt, ntd.depth]; 39, 40; 39, 43; 39, 49; 40, attribute; 40, 41; 40, 42; 41, identifier:ntd; 42, identifier:NS; 43, binary_operator:*; 43, 44; 43, 46; 44, unary_operator:-; 44, 45; 45, integer:1; 46, attribute; 46, 47; 46, 48; 47, identifier:ntd; 48, identifier:dcnt; 49, attribute; 49, 50; 49, 51; 50, identifier:ntd; 51, identifier:depth
def sortby(self, ntd): """Return function for sorting.""" if 'reldepth' in self.grprobj.gosubdag.prt_attr['flds']: return [ntd.NS, -1*ntd.dcnt, ntd.reldepth] else: return [ntd.NS, -1*ntd.dcnt, ntd.depth]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_nts_sorted; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:hdrgo_prt; 6, identifier:hdrgos; 7, identifier:hdrgo_sort; 8, block; 8, 9; 8, 11; 8, 15; 8, 25; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:nts_flat; 14, list:[]; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:get_sorted_hdrgo2usrgos; 20, argument_list; 20, 21; 20, 22; 20, 23; 20, 24; 21, identifier:hdrgos; 22, identifier:nts_flat; 23, identifier:hdrgo_prt; 24, identifier:hdrgo_sort; 25, return_statement; 25, 26; 26, identifier:nts_flat
def get_nts_sorted(self, hdrgo_prt, hdrgos, hdrgo_sort): """Return a flat list of grouped and sorted GO terms.""" nts_flat = [] self.get_sorted_hdrgo2usrgos(hdrgos, nts_flat, hdrgo_prt, hdrgo_sort) return nts_flat
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:get_sorted_hdrgo2usrgos; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:hdrgos; 6, default_parameter; 6, 7; 6, 8; 7, identifier:flat_list; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:hdrgo_prt; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:hdrgo_sort; 14, True; 15, block; 15, 16; 15, 18; 15, 19; 15, 23; 15, 33; 15, 34; 15, 43; 15, 72; 15, 187; 16, expression_statement; 16, 17; 17, comment; 18, comment; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:sorted_hdrgos_usrgos; 22, list:[]; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:h2u_get; 26, attribute; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:grprobj; 31, identifier:hdrgo2usrgos; 32, identifier:get; 33, comment; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:hdr_go2nt; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_get_go2nt; 41, argument_list; 41, 42; 42, identifier:hdrgos; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:hdrgo_sort; 46, True; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:hdr_go2nt; 51, call; 51, 52; 51, 53; 52, identifier:sorted; 53, argument_list; 53, 54; 53, 59; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:hdr_go2nt; 57, identifier:items; 58, argument_list; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:key; 61, lambda; 61, 62; 61, 64; 62, lambda_parameters; 62, 63; 63, identifier:t; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:hdrgo_sortby; 68, argument_list; 68, 69; 69, subscript; 69, 70; 69, 71; 70, identifier:t; 71, integer:1; 72, for_statement; 72, 73; 72, 76; 72, 77; 73, pattern_list; 73, 74; 73, 75; 74, identifier:hdrgo_id; 75, identifier:hdrgo_nt; 76, identifier:hdr_go2nt; 77, block; 77, 78; 77, 101; 77, 102; 77, 109; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:flat_list; 81, None; 82, block; 82, 83; 83, if_statement; 83, 84; 83, 93; 84, boolean_operator:or; 84, 85; 84, 86; 85, identifier:hdrgo_prt; 86, comparison_operator:in; 86, 87; 86, 88; 87, identifier:hdrgo_id; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:grprobj; 92, identifier:usrgos; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:flat_list; 98, identifier:append; 99, argument_list; 99, 100; 100, identifier:hdrgo_nt; 101, comment; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:usrgos_unsorted; 105, call; 105, 106; 105, 107; 106, identifier:h2u_get; 107, argument_list; 107, 108; 108, identifier:hdrgo_id; 109, if_statement; 109, 110; 109, 111; 109, 176; 110, identifier:usrgos_unsorted; 111, block; 111, 112; 111, 121; 111, 145; 111, 155; 111, 167; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:usrgo2nt; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:_get_go2nt; 119, argument_list; 119, 120; 120, identifier:usrgos_unsorted; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:usrgont_sorted; 124, call; 124, 125; 124, 126; 125, identifier:sorted; 126, argument_list; 126, 127; 126, 132; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:usrgo2nt; 130, identifier:items; 131, argument_list; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:key; 134, lambda; 134, 135; 134, 137; 135, lambda_parameters; 135, 136; 136, identifier:t; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:usrgo_sortby; 141, argument_list; 141, 142; 142, subscript; 142, 143; 142, 144; 143, identifier:t; 144, integer:1; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, pattern_list; 147, 148; 147, 149; 148, identifier:usrgos_sorted; 149, identifier:usrnts_sorted; 150, call; 150, 151; 150, 152; 151, identifier:zip; 152, argument_list; 152, 153; 153, list_splat; 153, 154; 154, identifier:usrgont_sorted; 155, if_statement; 155, 156; 155, 159; 156, comparison_operator:is; 156, 157; 156, 158; 157, identifier:flat_list; 158, None; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:flat_list; 164, identifier:extend; 165, argument_list; 165, 166; 166, identifier:usrnts_sorted; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:sorted_hdrgos_usrgos; 171, identifier:append; 172, argument_list; 172, 173; 173, tuple; 173, 174; 173, 175; 174, identifier:hdrgo_id; 175, identifier:usrgos_sorted; 176, else_clause; 176, 177; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:sorted_hdrgos_usrgos; 182, identifier:append; 183, argument_list; 183, 184; 184, tuple; 184, 185; 184, 186; 185, identifier:hdrgo_id; 186, list:[]; 187, return_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:cx; 191, identifier:OrderedDict; 192, argument_list; 192, 193; 193, identifier:sorted_hdrgos_usrgos
def get_sorted_hdrgo2usrgos(self, hdrgos, flat_list=None, hdrgo_prt=True, hdrgo_sort=True): """Return GO IDs sorting using go2nt's namedtuple.""" # Return user-specfied sort or default sort of header and user GO IDs sorted_hdrgos_usrgos = [] h2u_get = self.grprobj.hdrgo2usrgos.get # Sort GO group headers using GO info in go2nt hdr_go2nt = self._get_go2nt(hdrgos) if hdrgo_sort is True: hdr_go2nt = sorted(hdr_go2nt.items(), key=lambda t: self.hdrgo_sortby(t[1])) for hdrgo_id, hdrgo_nt in hdr_go2nt: if flat_list is not None: if hdrgo_prt or hdrgo_id in self.grprobj.usrgos: flat_list.append(hdrgo_nt) # Sort user GOs which are under the current GO header usrgos_unsorted = h2u_get(hdrgo_id) if usrgos_unsorted: usrgo2nt = self._get_go2nt(usrgos_unsorted) usrgont_sorted = sorted(usrgo2nt.items(), key=lambda t: self.usrgo_sortby(t[1])) usrgos_sorted, usrnts_sorted = zip(*usrgont_sorted) if flat_list is not None: flat_list.extend(usrnts_sorted) sorted_hdrgos_usrgos.append((hdrgo_id, usrgos_sorted)) else: sorted_hdrgos_usrgos.append((hdrgo_id, [])) return cx.OrderedDict(sorted_hdrgos_usrgos)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_init_hdrgo_sortby; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:hdrgo_sortby; 6, identifier:sortby; 7, block; 7, 8; 7, 10; 7, 17; 7, 24; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:hdrgo_sortby; 13, None; 14, block; 14, 15; 15, return_statement; 15, 16; 16, identifier:hdrgo_sortby; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:sortby; 20, None; 21, block; 21, 22; 22, return_statement; 22, 23; 23, identifier:sortby; 24, return_statement; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:sortby
def _init_hdrgo_sortby(self, hdrgo_sortby, sortby): """Initialize header sort function.""" if hdrgo_sortby is not None: return hdrgo_sortby if sortby is not None: return sortby return self.sortby
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_sortgo; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 25; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 16; 9, comparison_operator:in; 9, 10; 9, 11; 10, string:'sortgo'; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:datobj; 15, identifier:kws; 16, block; 16, 17; 17, return_statement; 17, 18; 18, subscript; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:datobj; 23, identifier:kws; 24, string:'sortgo'; 25, return_statement; 25, 26; 26, binary_operator:+; 26, 27; 26, 38; 27, subscript; 27, 28; 27, 37; 28, attribute; 28, 29; 28, 36; 29, attribute; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:datobj; 34, identifier:grprdflt; 35, identifier:gosubdag; 36, identifier:prt_attr; 37, string:'sort'; 38, string:"\n"
def _get_sortgo(self): """Get function for sorting GO terms in a list of namedtuples.""" if 'sortgo' in self.datobj.kws: return self.datobj.kws['sortgo'] return self.datobj.grprdflt.gosubdag.prt_attr['sort'] + "\n"
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_sorted_section; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:nts_section; 6, block; 6, 7; 6, 9; 6, 10; 6, 35; 6, 50; 6, 51; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, if_statement; 10, 11; 10, 16; 11, comparison_operator:is; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:section_sortby; 15, True; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 20, 22; 21, identifier:nts_section; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:key; 24, lambda; 24, 25; 24, 27; 25, lambda_parameters; 25, 26; 26, identifier:nt; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:sortgos; 32, identifier:usrgo_sortby; 33, argument_list; 33, 34; 34, identifier:nt; 35, if_statement; 35, 36; 35, 47; 36, boolean_operator:or; 36, 37; 36, 42; 37, comparison_operator:is; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:section_sortby; 41, False; 42, comparison_operator:is; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:section_sortby; 46, None; 47, block; 47, 48; 48, return_statement; 48, 49; 49, identifier:nts_section; 50, comment; 51, return_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:sorted; 54, argument_list; 54, 55; 54, 56; 55, identifier:nts_section; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:key; 58, lambda; 58, 59; 58, 61; 59, lambda_parameters; 59, 60; 60, identifier:nt; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:section_sortby; 65, argument_list; 65, 66; 66, identifier:nt
def _get_sorted_section(self, nts_section): """Sort GO IDs in each section, if requested by user.""" #pylint: disable=unnecessary-lambda if self.section_sortby is True: return sorted(nts_section, key=lambda nt: self.sortgos.usrgo_sortby(nt)) if self.section_sortby is False or self.section_sortby is None: return nts_section # print('SORT GO IDS IN A SECTION') return sorted(nts_section, key=lambda nt: self.section_sortby(nt))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_sections_2dnt; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:sec2d_go; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, return_statement; 9, 10; 10, list_comprehension; 10, 11; 10, 19; 11, tuple; 11, 12; 11, 13; 12, identifier:nm; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:get_ntgos_sorted; 17, argument_list; 17, 18; 18, identifier:gos; 19, for_in_clause; 19, 20; 19, 23; 20, pattern_list; 20, 21; 20, 22; 21, identifier:nm; 22, identifier:gos; 23, identifier:sec2d_go
def get_sections_2dnt(self, sec2d_go): """Return a sections list containing sorted lists of namedtuples.""" return [(nm, self.get_ntgos_sorted(gos)) for nm, gos in sec2d_go]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_ntgos_sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:hdrgos; 6, block; 6, 7; 6, 9; 6, 17; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:go2nt; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:grprobj; 16, identifier:go2nt; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 20, 32; 21, list_comprehension; 21, 22; 21, 25; 21, 28; 22, subscript; 22, 23; 22, 24; 23, identifier:go2nt; 24, identifier:go; 25, for_in_clause; 25, 26; 25, 27; 26, identifier:go; 27, identifier:hdrgos; 28, if_clause; 28, 29; 29, comparison_operator:in; 29, 30; 29, 31; 30, identifier:go; 31, identifier:go2nt; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:key; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:fncsortnt
def get_ntgos_sorted(self, hdrgos): """Return sorted Grouper namedtuples if there are user GO IDs underneath.""" go2nt = self.grprobj.go2nt return sorted([go2nt[go] for go in hdrgos if go in go2nt], key=self.fncsortnt)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_sortobj; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:goea_results; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kws; 8, block; 8, 9; 8, 11; 8, 24; 8, 36; 8, 48; 8, 67; 8, 76; 8, 77; 8, 96; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:nts_goea; 14, call; 14, 15; 14, 21; 15, attribute; 15, 16; 15, 20; 16, call; 16, 17; 16, 18; 17, identifier:MgrNtGOEAs; 18, argument_list; 18, 19; 19, identifier:goea_results; 20, identifier:get_goea_nts_prt; 21, argument_list; 21, 22; 22, dictionary_splat; 22, 23; 23, identifier:kws; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:goids; 27, call; 27, 28; 27, 29; 28, identifier:set; 29, generator_expression; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:nt; 32, identifier:GO; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:nt; 35, identifier:nts_goea; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:go2nt; 39, dictionary_comprehension; 39, 40; 39, 45; 40, pair; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:nt; 43, identifier:GO; 44, identifier:nt; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:nt; 47, identifier:nts_goea; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:grprobj; 51, call; 51, 52; 51, 53; 52, identifier:Grouper; 53, argument_list; 53, 54; 53, 55; 53, 56; 53, 59; 53, 64; 54, string:"GOEA"; 55, identifier:goids; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:hdrobj; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:grprdflt; 63, identifier:gosubdag; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:go2nt; 66, identifier:go2nt; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:grprobj; 71, identifier:prt_summary; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:sys; 75, identifier:stdout; 76, comment; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:sortobj; 80, call; 80, 81; 80, 82; 81, identifier:Sorter; 82, argument_list; 82, 83; 82, 84; 83, identifier:grprobj; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:section_sortby; 86, lambda; 86, 87; 86, 89; 87, lambda_parameters; 87, 88; 88, identifier:nt; 89, call; 89, 90; 89, 91; 90, identifier:getattr; 91, argument_list; 91, 92; 91, 93; 92, identifier:nt; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:pval_fld; 96, return_statement; 96, 97; 97, identifier:sortobj
def get_sortobj(self, goea_results, **kws): """Return a Grouper object, given a list of GOEnrichmentRecord.""" nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws) goids = set(nt.GO for nt in nts_goea) go2nt = {nt.GO:nt for nt in nts_goea} grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt) grprobj.prt_summary(sys.stdout) # hdrgo_prt", "section_prt", "top_n", "use_sections" sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld)) return sortobj
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_sorted_relationships; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:goterm; 6, block; 6, 7; 6, 9; 6, 19; 6, 30; 6, 45; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 17; 10, comparison_operator:in; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:goterm; 13, identifier:id; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:goids_seen; 17, block; 17, 18; 18, return_statement; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:goids_seen; 25, identifier:add; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:goterm; 29, identifier:id; 30, for_statement; 30, 31; 30, 32; 30, 37; 31, identifier:goterm_upper; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:goterm; 35, identifier:get_goterms_upper; 36, argument_list; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_get_sorted_relationships; 43, argument_list; 43, 44; 44, identifier:goterm_upper; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:goterms_sorted; 51, identifier:append; 52, argument_list; 52, 53; 53, identifier:goterm
def _get_sorted_relationships(self, goterm): """Traverse GO Terms above the current GO Term. Then add current GO Term to sorted.""" if goterm.id in self.goids_seen: return self.goids_seen.add(goterm.id) for goterm_upper in goterm.get_goterms_upper(): self._get_sorted_relationships(goterm_upper) self.goterms_sorted.append(goterm)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:write_dag; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:out; 7, attribute; 7, 8; 7, 9; 8, identifier:sys; 9, identifier:stdout; 10, block; 10, 11; 10, 13; 11, expression_statement; 11, 12; 12, comment; 13, for_statement; 13, 14; 13, 15; 13, 23; 14, identifier:rec; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:values; 22, argument_list; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:print; 27, argument_list; 27, 28; 27, 29; 28, identifier:rec; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:file; 31, identifier:out
def write_dag(self, out=sys.stdout): """Write info for all GO Terms in obo file, sorted numerically.""" for rec in sorted(self.values()): print(rec, file=out)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort_nts; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:nt_list; 6, identifier:codekey; 7, block; 7, 8; 7, 10; 7, 11; 7, 12; 7, 13; 7, 33; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:sortby; 16, lambda; 16, 17; 16, 19; 17, lambda_parameters; 17, 18; 18, identifier:nt; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:ev2idx; 24, identifier:get; 25, argument_list; 25, 26; 25, 31; 26, call; 26, 27; 26, 28; 27, identifier:getattr; 28, argument_list; 28, 29; 28, 30; 29, identifier:nt; 30, identifier:codekey; 31, unary_operator:-; 31, 32; 32, integer:1; 33, return_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:sorted; 36, argument_list; 36, 37; 36, 38; 37, identifier:nt_list; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:key; 40, identifier:sortby
def sort_nts(self, nt_list, codekey): """Sort list of namedtuples such so evidence codes in same order as code2nt.""" # Problem is that some members in the nt_list do NOT have # codekey=EvidenceCode, then it returns None, which breaks py34 and 35 # The fix here is that for these members, default to -1 (is this valid?) sortby = lambda nt: self.ev2idx.get(getattr(nt, codekey), -1) return sorted(nt_list, key=sortby)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:prt_gos; 3, parameters; 3, 4; 3, 5; 3, 10; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:prt; 7, attribute; 7, 8; 7, 9; 8, identifier:sys; 9, identifier:stdout; 10, dictionary_splat_pattern; 10, 11; 11, identifier:kws_usr; 12, block; 12, 13; 12, 15; 12, 16; 12, 17; 12, 18; 12, 28; 12, 29; 12, 43; 13, expression_statement; 13, 14; 14, comment; 15, comment; 16, comment; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:desc2nts; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:get_desc2nts; 25, argument_list; 25, 26; 26, dictionary_splat; 26, 27; 27, identifier:kws_usr; 28, comment; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:prt_nts; 34, argument_list; 34, 35; 34, 36; 34, 37; 35, identifier:desc2nts; 36, identifier:prt; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:kws_usr; 40, identifier:get; 41, argument_list; 41, 42; 42, string:'prtfmt'; 43, return_statement; 43, 44; 44, identifier:desc2nts
def prt_gos(self, prt=sys.stdout, **kws_usr): """Sort user GO ids, grouped under broader GO terms or sections. Print to screen.""" # deprecated # Keyword arguments (control content): hdrgo_prt section_prt use_sections # desc2nts contains: (sections hdrgo_prt sortobj) or (flat hdrgo_prt sortobj) desc2nts = self.get_desc2nts(**kws_usr) # Keyword arguments (control print format): prt prtfmt self.prt_nts(desc2nts, prt, kws_usr.get('prtfmt')) return desc2nts
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_nts_flat; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:hdrgo_prt; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:use_sections; 10, True; 11, block; 11, 12; 11, 14; 11, 15; 11, 46; 11, 62; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, if_statement; 15, 16; 15, 24; 16, boolean_operator:or; 16, 17; 16, 22; 17, comparison_operator:is; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:sectobj; 21, None; 22, not_operator; 22, 23; 23, identifier:use_sections; 24, block; 24, 25; 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:sortgos; 31, identifier:get_nts_sorted; 32, argument_list; 32, 33; 32, 34; 32, 43; 33, identifier:hdrgo_prt; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:hdrgos; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:grprobj; 41, identifier:get_hdrgos; 42, argument_list; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:hdrgo_sort; 45, True; 46, if_statement; 46, 47; 46, 49; 47, not_operator; 47, 48; 48, identifier:use_sections; 49, block; 49, 50; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:sectobj; 56, identifier:get_sorted_nts_omit_section; 57, argument_list; 57, 58; 57, 59; 58, identifier:hdrgo_prt; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:hdrgo_sort; 61, True; 62, return_statement; 62, 63; 63, None
def get_nts_flat(self, hdrgo_prt=True, use_sections=True): """Return a flat list of sorted nts.""" # Either there are no sections OR we are not using them if self.sectobj is None or not use_sections: return self.sortgos.get_nts_sorted( hdrgo_prt, hdrgos=self.grprobj.get_hdrgos(), hdrgo_sort=True) if not use_sections: return self.sectobj.get_sorted_nts_omit_section(hdrgo_prt, hdrgo_sort=True) return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_adjust_prt_flds; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:kws_xlsx; 6, identifier:desc2nts; 7, identifier:shade_hdrgos; 8, block; 8, 9; 8, 11; 8, 12; 8, 21; 8, 22; 8, 32; 8, 33; 8, 34; 8, 38; 8, 39; 8, 50; 8, 51; 8, 52; 8, 88; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:in; 13, 14; 13, 15; 14, string:"prt_flds"; 15, identifier:kws_xlsx; 16, block; 16, 17; 17, return_statement; 17, 18; 18, subscript; 18, 19; 18, 20; 19, identifier:kws_xlsx; 20, string:"prt_flds"; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:dont_print; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 27, 28; 28, list:['hdr_idx', 'is_hdrgo', 'is_usrgo']; 28, 29; 28, 30; 28, 31; 29, string:'hdr_idx'; 30, string:'is_hdrgo'; 31, string:'is_usrgo'; 32, comment; 33, comment; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:prt_flds_adjusted; 37, list:[]; 38, comment; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:nt_flds; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:sortobj; 47, identifier:get_fields; 48, argument_list; 48, 49; 49, identifier:desc2nts; 50, comment; 51, comment; 52, for_statement; 52, 53; 52, 54; 52, 55; 53, identifier:nt_fld; 54, identifier:nt_flds; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 60; 56, 61; 57, comparison_operator:not; 57, 58; 57, 59; 58, identifier:nt_fld; 59, identifier:dont_print; 60, comment; 61, block; 61, 62; 62, if_statement; 62, 63; 62, 66; 62, 79; 63, comparison_operator:==; 63, 64; 63, 65; 64, identifier:nt_fld; 65, string:"format_txt"; 66, block; 66, 67; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:shade_hdrgos; 70, True; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:prt_flds_adjusted; 76, identifier:append; 77, argument_list; 77, 78; 78, identifier:nt_fld; 79, else_clause; 79, 80; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:prt_flds_adjusted; 85, identifier:append; 86, argument_list; 86, 87; 87, identifier:nt_fld; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:kws_xlsx; 92, string:'prt_flds'; 93, identifier:prt_flds_adjusted
def _adjust_prt_flds(self, kws_xlsx, desc2nts, shade_hdrgos): """Print user-requested fields or provided fields minus info fields.""" # Use xlsx prt_flds from the user, if provided if "prt_flds" in kws_xlsx: return kws_xlsx["prt_flds"] # If the user did not provide specific fields to print in an xlsx file: dont_print = set(['hdr_idx', 'is_hdrgo', 'is_usrgo']) # Are we printing GO group headers? # Build new list of xlsx print fields, excluding those which add no new information prt_flds_adjusted = [] # Get all namedtuple fields nt_flds = self.sortobj.get_fields(desc2nts) # Keep fields intended for print and optionally gray-shade field (format_txt) # print('FFFFFFFFFFFFFFF WrXlsxSortedGos::_adjust_prt_flds:', nt_flds) for nt_fld in nt_flds: if nt_fld not in dont_print: # Only add grey-shade to hdrgo and section name rows if hdrgo_prt=True if nt_fld == "format_txt": if shade_hdrgos is True: prt_flds_adjusted.append(nt_fld) else: prt_flds_adjusted.append(nt_fld) kws_xlsx['prt_flds'] = prt_flds_adjusted
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_shade_hdrgos; 3, parameters; 3, 4; 4, dictionary_splat_pattern; 4, 5; 5, identifier:kws; 6, block; 6, 7; 6, 9; 6, 10; 6, 19; 6, 20; 6, 29; 6, 30; 6, 31; 6, 32; 6, 33; 6, 44; 6, 59; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:in; 11, 12; 11, 13; 12, string:'shade_hdrgos'; 13, identifier:kws; 14, block; 14, 15; 15, return_statement; 15, 16; 16, subscript; 16, 17; 16, 18; 17, identifier:kws; 18, string:'shade_hdrgos'; 19, comment; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:in; 21, 22; 21, 23; 22, string:'hdrgo_prt'; 23, identifier:kws; 24, block; 24, 25; 25, return_statement; 25, 26; 26, subscript; 26, 27; 26, 28; 27, identifier:kws; 28, string:'hdrgo_prt'; 29, comment; 30, comment; 31, comment; 32, comment; 33, if_statement; 33, 34; 33, 41; 34, boolean_operator:and; 34, 35; 34, 38; 35, comparison_operator:in; 35, 36; 35, 37; 36, string:'section_sortby'; 37, identifier:kws; 38, subscript; 38, 39; 38, 40; 39, identifier:kws; 40, string:'section_sortby'; 41, block; 41, 42; 42, return_statement; 42, 43; 43, False; 44, if_statement; 44, 45; 44, 56; 45, boolean_operator:and; 45, 46; 45, 49; 46, comparison_operator:in; 46, 47; 46, 48; 47, string:'top_n'; 48, identifier:kws; 49, call; 49, 50; 49, 51; 50, identifier:isinstance; 51, argument_list; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:kws; 54, string:'top_n'; 55, identifier:int; 56, block; 56, 57; 57, return_statement; 57, 58; 58, False; 59, return_statement; 59, 60; 60, True
def _get_shade_hdrgos(**kws): """If no hdrgo_prt specified, and these conditions are present -> hdrgo_prt=F.""" # KWS: shade_hdrgos hdrgo_prt section_sortby top_n if 'shade_hdrgos' in kws: return kws['shade_hdrgos'] # Return user-sepcified hdrgo_prt, if provided if 'hdrgo_prt' in kws: return kws['hdrgo_prt'] # If no hdrgo_prt provided, set hdrgo_prt to False if: # * section_sortby == True # * section_sortby = user_sort # * top_n == N if 'section_sortby' in kws and kws['section_sortby']: return False if 'top_n' in kws and isinstance(kws['top_n'], int): return False return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:dflt_sortby_objgoea; 3, parameters; 3, 4; 4, identifier:goea_res; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, return_statement; 8, 9; 9, list:[getattr(goea_res, 'enrichment'), getattr(goea_res, 'namespace'), getattr(goea_res, 'p_uncorrected'), getattr(goea_res, 'depth'), getattr(goea_res, 'GO')]; 9, 10; 9, 15; 9, 20; 9, 25; 9, 30; 10, call; 10, 11; 10, 12; 11, identifier:getattr; 12, argument_list; 12, 13; 12, 14; 13, identifier:goea_res; 14, string:'enrichment'; 15, call; 15, 16; 15, 17; 16, identifier:getattr; 17, argument_list; 17, 18; 17, 19; 18, identifier:goea_res; 19, string:'namespace'; 20, call; 20, 21; 20, 22; 21, identifier:getattr; 22, argument_list; 22, 23; 22, 24; 23, identifier:goea_res; 24, string:'p_uncorrected'; 25, call; 25, 26; 25, 27; 26, identifier:getattr; 27, argument_list; 27, 28; 27, 29; 28, identifier:goea_res; 29, string:'depth'; 30, call; 30, 31; 30, 32; 31, identifier:getattr; 32, argument_list; 32, 33; 32, 34; 33, identifier:goea_res; 34, string:'GO'
def dflt_sortby_objgoea(goea_res): """Default sorting of GOEA results.""" return [getattr(goea_res, 'enrichment'), getattr(goea_res, 'namespace'), getattr(goea_res, 'p_uncorrected'), getattr(goea_res, 'depth'), getattr(goea_res, 'GO')]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:dflt_sortby_ntgoea; 3, parameters; 3, 4; 4, identifier:ntgoea; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, return_statement; 8, 9; 9, list:[ntgoea.enrichment, ntgoea.namespace, ntgoea.p_uncorrected, ntgoea.depth, ntgoea.GO]; 9, 10; 9, 13; 9, 16; 9, 19; 9, 22; 10, attribute; 10, 11; 10, 12; 11, identifier:ntgoea; 12, identifier:enrichment; 13, attribute; 13, 14; 13, 15; 14, identifier:ntgoea; 15, identifier:namespace; 16, attribute; 16, 17; 16, 18; 17, identifier:ntgoea; 18, identifier:p_uncorrected; 19, attribute; 19, 20; 19, 21; 20, identifier:ntgoea; 21, identifier:depth; 22, attribute; 22, 23; 22, 24; 23, identifier:ntgoea; 24, identifier:GO
def dflt_sortby_ntgoea(ntgoea): """Default sorting of GOEA results stored in namedtuples.""" return [ntgoea.enrichment, ntgoea.namespace, ntgoea.p_uncorrected, ntgoea.depth, ntgoea.GO]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 12; 3, 15; 4, identifier:x; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, unary_operator:-; 7, 8; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:reverse; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:with_index; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:only_index; 17, False; 18, block; 18, 19; 18, 21; 18, 30; 18, 40; 19, expression_statement; 19, 20; 20, comment; 21, import_from_statement; 21, 22; 21, 26; 22, relative_import; 22, 23; 22, 24; 23, import_prefix; 24, dotted_name; 24, 25; 25, identifier:function_bases; 26, aliased_import; 26, 27; 26, 29; 27, dotted_name; 27, 28; 28, identifier:sort; 29, identifier:sort_base; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:n_outputs; 33, conditional_expression:if; 33, 34; 33, 35; 33, 39; 34, integer:2; 35, boolean_operator:and; 35, 36; 35, 37; 36, identifier:with_index; 37, not_operator; 37, 38; 38, identifier:only_index; 39, integer:1; 40, return_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:sort_base; 43, argument_list; 43, 44; 43, 45; 43, 46; 43, 47; 43, 48; 43, 49; 44, identifier:x; 45, identifier:axis; 46, identifier:reverse; 47, identifier:with_index; 48, identifier:only_index; 49, identifier:n_outputs
def sort(x, axis=-1, reverse=False, with_index=False, only_index=False): """Sorts the elements of `x` along a given `axis` in ascending order by value. A negative `axis` counts from the last dimension of `x`, so the default of -1 sorts along the last dimension. If `reverse` is True, then the elements are soreted in descending order. If `with_index` is True, result is a tuple ``(sorted, indices)`` or only ``indices`` if `only_index` is True. Setting `only_index` to True implies that `with_index` is also True. .. code-block:: python import numpy as np import nnabla as nn import nnabla.functions as F nn.set_auto_forward(True) x = nn.Variable.from_numpy_array(np.random.rand(2, 3, 4)) sorted = F.sort(x) assert np.allclose(sorted.d, np.sort(x.d)) sorted, indices = F.sort(x, with_index=True) assert np.allclose(sorted.d, np.sort(x.d)) assert np.all(indices.d == np.argsort(x.d)) indices = F.sort(x, only_index=True) assert np.all(indices.d == np.argsort(x.d)) Args: x(~nnabla.Variable): N-D array axis(int): Axis along which to sort. reverse(bool): Sort in descending order. with_index(bool): Return sorted values and index. only_index(bool): Return only the sort index. Returns: :obj:`~nnabla.Variable` `sorted` or :obj:`~nnabla.Variable` `indices` or (:obj:`~nnabla.Variable` `sorted`, :obj:`~nnabla.Variable` `indices`) """ from .function_bases import sort as sort_base n_outputs = 2 if with_index and not only_index else 1 return sort_base(x, axis, reverse, with_index, only_index, n_outputs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:optimize; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 30; 5, 31; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, with_statement; 9, 10; 9, 20; 10, with_clause; 10, 11; 11, with_item; 11, 12; 12, as_pattern; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:open; 15, argument_list; 15, 16; 15, 17; 16, identifier:LIBRARIES_FILE; 17, string:'r'; 18, as_pattern_target; 18, 19; 19, identifier:f; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:libs_data; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:json; 27, identifier:load; 28, argument_list; 28, 29; 29, identifier:f; 30, comment; 31, for_statement; 31, 32; 31, 35; 31, 40; 32, pattern_list; 32, 33; 32, 34; 33, identifier:alg; 34, identifier:libs_names; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:libs_data; 38, identifier:items; 39, argument_list; 40, block; 40, 41; 40, 50; 40, 55; 40, 56; 40, 78; 40, 79; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:libs; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:get_libs; 48, argument_list; 48, 49; 49, identifier:alg; 50, if_statement; 50, 51; 50, 53; 51, not_operator; 51, 52; 52, identifier:libs; 53, block; 53, 54; 54, continue_statement; 55, comment; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 63; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:libs; 62, identifier:alg; 63, list_comprehension; 63, 64; 63, 65; 63, 68; 64, identifier:lib; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:lib; 67, identifier:libs; 68, if_clause; 68, 69; 69, comparison_operator:in; 69, 70; 69, 77; 70, list:[lib.module_name, lib.func_name]; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:lib; 73, identifier:module_name; 74, attribute; 74, 75; 74, 76; 75, identifier:lib; 76, identifier:func_name; 77, identifier:libs_names; 78, comment; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 88; 81, attribute; 81, 82; 81, 87; 82, subscript; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:libs; 86, identifier:alg; 87, identifier:sort; 88, argument_list; 88, 89; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:key; 91, lambda; 91, 92; 91, 94; 92, lambda_parameters; 92, 93; 93, identifier:lib; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:libs_names; 97, identifier:index; 98, argument_list; 98, 99; 99, list:[lib.module_name, lib.func_name]; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:lib; 102, identifier:module_name; 103, attribute; 103, 104; 103, 105; 104, identifier:lib; 105, identifier:func_name
def optimize(self): """Sort algorithm implementations by speed. """ # load benchmarks results with open(LIBRARIES_FILE, 'r') as f: libs_data = json.load(f) # optimize for alg, libs_names in libs_data.items(): libs = self.get_libs(alg) if not libs: continue # drop slow libs self.libs[alg] = [lib for lib in libs if [lib.module_name, lib.func_name] in libs_names] # sort libs by speed self.libs[alg].sort(key=lambda lib: libs_names.index([lib.module_name, lib.func_name]))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:sort_common_members; 3, parameters; 4, block; 4, 5; 4, 7; 4, 13; 4, 17; 4, 24; 4, 28; 4, 45; 4, 52; 4, 78; 4, 92; 5, expression_statement; 5, 6; 6, comment; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:filename; 10, binary_operator:+; 10, 11; 10, 12; 11, identifier:PREFIX; 12, string:'/common_members.json'; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:sorted_json_data; 16, dictionary; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:json_data; 20, call; 20, 21; 20, 22; 21, identifier:read_json; 22, argument_list; 22, 23; 23, identifier:filename; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:all_keys; 27, list:[]; 28, for_statement; 28, 29; 28, 32; 28, 37; 29, pattern_list; 29, 30; 29, 31; 30, identifier:key; 31, identifier:value; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:json_data; 35, identifier:items; 36, argument_list; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:all_keys; 42, identifier:append; 43, argument_list; 43, 44; 44, identifier:key; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:sorted_keys; 48, call; 48, 49; 48, 50; 49, identifier:sorted; 50, argument_list; 50, 51; 51, identifier:all_keys; 52, for_statement; 52, 53; 52, 54; 52, 55; 53, identifier:key; 54, identifier:sorted_keys; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 65; 56, 66; 57, comparison_operator:>; 57, 58; 57, 64; 58, call; 58, 59; 58, 60; 59, identifier:len; 60, argument_list; 60, 61; 61, subscript; 61, 62; 61, 63; 62, identifier:json_data; 63, identifier:key; 64, integer:0; 65, comment; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:sorted_json_data; 71, identifier:key; 72, call; 72, 73; 72, 74; 73, identifier:sorted; 74, argument_list; 74, 75; 75, subscript; 75, 76; 75, 77; 76, identifier:json_data; 77, identifier:key; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:print; 81, argument_list; 81, 82; 82, binary_operator:+; 82, 83; 82, 84; 83, string:'--> Sorted/cleaned '; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:os; 88, identifier:path; 89, identifier:basename; 90, argument_list; 90, 91; 91, identifier:filename; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:write_json; 95, argument_list; 95, 96; 95, 97; 96, identifier:sorted_json_data; 97, identifier:filename
def sort_common_members(): """Sorts the keys and members""" filename = PREFIX + '/common_members.json' sorted_json_data = {} json_data = read_json(filename) all_keys = [] for key, value in json_data.items(): all_keys.append(key) sorted_keys = sorted(all_keys) for key in sorted_keys: if len(json_data[key]) > 0: # Only add modules which have common members sorted_json_data[key] = sorted(json_data[key]) print('--> Sorted/cleaned ' + os.path.basename(filename)) write_json(sorted_json_data, filename)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_ConstructPartitions; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:collection_links; 6, identifier:partitions_per_node; 7, block; 7, 8; 7, 10; 7, 17; 7, 35; 7, 39; 7, 94; 7, 100; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:collections_node_count; 13, call; 13, 14; 13, 15; 14, identifier:len; 15, argument_list; 15, 16; 16, identifier:collection_links; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:partitions; 20, list_comprehension; 20, 21; 20, 26; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:partition; 24, identifier:_Partition; 25, argument_list; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:_; 28, call; 28, 29; 28, 30; 29, identifier:xrange; 30, argument_list; 30, 31; 30, 32; 31, integer:0; 32, binary_operator:*; 32, 33; 32, 34; 33, identifier:partitions_per_node; 34, identifier:collections_node_count; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:index; 38, integer:0; 39, for_statement; 39, 40; 39, 41; 39, 42; 40, identifier:collection_node; 41, identifier:collection_links; 42, block; 42, 43; 42, 59; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:hash_value; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:hash_generator; 51, identifier:ComputeHash; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_GetBytes; 57, argument_list; 57, 58; 58, identifier:collection_node; 59, for_statement; 59, 60; 59, 61; 59, 66; 60, identifier:_; 61, call; 61, 62; 61, 63; 62, identifier:xrange; 63, argument_list; 63, 64; 63, 65; 64, integer:0; 65, identifier:partitions_per_node; 66, block; 66, 67; 66, 79; 66, 83; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:partitions; 71, identifier:index; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:partition; 75, identifier:_Partition; 76, argument_list; 76, 77; 76, 78; 77, identifier:hash_value; 78, identifier:collection_node; 79, expression_statement; 79, 80; 80, augmented_assignment:+=; 80, 81; 80, 82; 81, identifier:index; 82, integer:1; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:hash_value; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:hash_generator; 91, identifier:ComputeHash; 92, argument_list; 92, 93; 93, identifier:hash_value; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:partitions; 98, identifier:sort; 99, argument_list; 100, return_statement; 100, 101; 101, identifier:partitions
def _ConstructPartitions(self, collection_links, partitions_per_node): """Constructs the partitions in the consistent ring by assigning them to collection nodes using the hashing algorithm and then finally sorting the partitions based on the hash value. """ collections_node_count = len(collection_links) partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)] index = 0 for collection_node in collection_links: hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node)) for _ in xrange(0, partitions_per_node): partitions[index] = partition._Partition(hash_value, collection_node) index += 1 hash_value = self.hash_generator.ComputeHash(hash_value) partitions.sort() return partitions
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_leap_seconds; 3, parameters; 3, 4; 4, identifier:fileobj; 5, block; 5, 6; 5, 8; 5, 15; 5, 35; 5, 44; 5, 95; 5, 96; 5, 97; 5, 98; 5, 107; 5, 117; 5, 133; 5, 147; 5, 153; 5, 165; 5, 172; 5, 186; 5, 198; 5, 206; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:lines; 11, call; 11, 12; 11, 13; 12, identifier:iter; 13, argument_list; 13, 14; 14, identifier:fileobj; 15, for_statement; 15, 16; 15, 17; 15, 18; 15, 28; 16, identifier:line; 17, identifier:lines; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 26; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:line; 23, identifier:startswith; 24, argument_list; 24, 25; 25, string:b'# File expires on'; 26, block; 26, 27; 27, break_statement; 28, else_clause; 28, 29; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:ValueError; 33, argument_list; 33, 34; 34, string:'Leap_Second.dat is missing its expiration date'; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:line; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:line; 41, identifier:decode; 42, argument_list; 42, 43; 43, string:'ascii'; 44, with_statement; 44, 45; 44, 48; 44, 49; 45, with_clause; 45, 46; 46, with_item; 46, 47; 47, identifier:_lock; 48, comment; 49, block; 49, 50; 49, 61; 49, 71; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:original_locale; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:locale; 56, identifier:setlocale; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:locale; 60, identifier:LC_ALL; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:locale; 65, identifier:setlocale; 66, argument_list; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:locale; 69, identifier:LC_ALL; 70, string:'C'; 71, try_statement; 71, 72; 71, 83; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:dt; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:datetime; 79, identifier:strptime; 80, argument_list; 80, 81; 80, 82; 81, identifier:line; 82, string:'# File expires on %d %B %Y\n'; 83, finally_clause; 83, 84; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:locale; 89, identifier:setlocale; 90, argument_list; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:locale; 93, identifier:LC_ALL; 94, identifier:original_locale; 95, comment; 96, comment; 97, comment; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:grace_period; 101, call; 101, 102; 101, 103; 102, identifier:timedelta; 103, argument_list; 103, 104; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:days; 106, integer:30; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:expiration_date; 110, binary_operator:+; 110, 111; 110, 116; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:dt; 114, identifier:date; 115, argument_list; 116, identifier:grace_period; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 125; 119, pattern_list; 119, 120; 119, 121; 119, 122; 119, 123; 119, 124; 120, identifier:mjd; 121, identifier:day; 122, identifier:month; 123, identifier:year; 124, identifier:offsets; 125, attribute; 125, 126; 125, 132; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:np; 129, identifier:loadtxt; 130, argument_list; 130, 131; 131, identifier:lines; 132, identifier:T; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:leap_dates; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:np; 139, identifier:ndarray; 140, argument_list; 140, 141; 141, binary_operator:+; 141, 142; 141, 146; 142, call; 142, 143; 142, 144; 143, identifier:len; 144, argument_list; 144, 145; 145, identifier:mjd; 146, integer:2; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:leap_dates; 151, integer:0; 152, string:'-inf'; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 162; 155, subscript; 155, 156; 155, 157; 156, identifier:leap_dates; 157, slice; 157, 158; 157, 159; 157, 160; 158, integer:1; 159, colon; 160, unary_operator:-; 160, 161; 161, integer:1; 162, binary_operator:+; 162, 163; 162, 164; 163, identifier:mjd; 164, float:2400000.5; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 171; 167, subscript; 167, 168; 167, 169; 168, identifier:leap_dates; 169, unary_operator:-; 169, 170; 170, integer:1; 171, string:'inf'; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:leap_offsets; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:np; 178, identifier:ndarray; 179, argument_list; 179, 180; 180, binary_operator:+; 180, 181; 180, 185; 181, call; 181, 182; 181, 183; 182, identifier:len; 183, argument_list; 183, 184; 184, identifier:mjd; 185, integer:2; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:leap_offsets; 190, integer:0; 191, assignment; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:leap_offsets; 194, integer:1; 195, subscript; 195, 196; 195, 197; 196, identifier:offsets; 197, integer:0; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 205; 200, subscript; 200, 201; 200, 202; 201, identifier:leap_offsets; 202, slice; 202, 203; 202, 204; 203, integer:2; 204, colon; 205, identifier:offsets; 206, return_statement; 206, 207; 207, expression_list; 207, 208; 207, 209; 208, identifier:expiration_date; 209, tuple; 209, 210; 209, 211; 210, identifier:leap_dates; 211, identifier:leap_offsets
def parse_leap_seconds(fileobj): """Parse the IERS file ``Leap_Second.dat``. The leap dates array can be searched with:: index = np.searchsorted(leap_dates, jd, 'right') The resulting index allows (TAI - UTC) to be fetched with:: offset = leap_offsets[index] """ lines = iter(fileobj) for line in lines: if line.startswith(b'# File expires on'): break else: raise ValueError('Leap_Second.dat is missing its expiration date') line = line.decode('ascii') with _lock: # won't help if anyone user threads are doing parsing, alas original_locale = locale.setlocale(locale.LC_ALL) locale.setlocale(locale.LC_ALL, 'C') try: dt = datetime.strptime(line, '# File expires on %d %B %Y\n') finally: locale.setlocale(locale.LC_ALL, original_locale) # The file went out of date at the beginning of July 2016, and kept # downloading every time a user ran a Skyfield program. So we now # build in a grace period: grace_period = timedelta(days=30) expiration_date = dt.date() + grace_period mjd, day, month, year, offsets = np.loadtxt(lines).T leap_dates = np.ndarray(len(mjd) + 2) leap_dates[0] = '-inf' leap_dates[1:-1] = mjd + 2400000.5 leap_dates[-1] = 'inf' leap_offsets = np.ndarray(len(mjd) + 2) leap_offsets[0] = leap_offsets[1] = offsets[0] leap_offsets[2:] = offsets return expiration_date, (leap_dates, leap_offsets)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:build_delta_t_table; 3, parameters; 3, 4; 4, identifier:delta_t_recent; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 5, 23; 5, 30; 5, 40; 5, 58; 5, 59; 5, 66; 5, 76; 5, 84; 5, 104; 5, 105; 5, 109; 5, 118; 5, 131; 5, 141; 5, 155; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:ancient; 11, call; 11, 12; 11, 13; 12, identifier:load_bundled_npy; 13, argument_list; 13, 14; 14, string:'morrison_stephenson_deltat.npy'; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:historic; 18, call; 18, 19; 18, 20; 19, identifier:load_bundled_npy; 20, argument_list; 20, 21; 21, string:'historic_deltat.npy'; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:historic_start_time; 26, subscript; 26, 27; 26, 28; 26, 29; 27, identifier:historic; 28, integer:0; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:i; 33, call; 33, 34; 33, 35; 34, identifier:searchsorted; 35, argument_list; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:ancient; 38, integer:0; 39, identifier:historic_start_time; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:bundled; 43, call; 43, 44; 43, 45; 44, identifier:concatenate; 45, argument_list; 45, 46; 45, 55; 46, list:[ancient[:,:i], historic]; 46, 47; 46, 54; 47, subscript; 47, 48; 47, 49; 47, 51; 48, identifier:ancient; 49, slice; 49, 50; 50, colon; 51, slice; 51, 52; 51, 53; 52, colon; 53, identifier:i; 54, identifier:historic; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:axis; 57, integer:1; 58, comment; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:recent_start_time; 62, subscript; 62, 63; 62, 64; 62, 65; 63, identifier:delta_t_recent; 64, integer:0; 65, integer:0; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:i; 69, call; 69, 70; 69, 71; 70, identifier:searchsorted; 71, argument_list; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:bundled; 74, integer:0; 75, identifier:recent_start_time; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:row; 79, tuple; 79, 80; 79, 82; 80, tuple; 80, 81; 81, integer:0; 82, tuple; 82, 83; 83, integer:0; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:table; 87, call; 87, 88; 87, 89; 88, identifier:concatenate; 89, argument_list; 89, 90; 89, 101; 90, list:[row, bundled[:,:i], delta_t_recent, row]; 90, 91; 90, 92; 90, 99; 90, 100; 91, identifier:row; 92, subscript; 92, 93; 92, 94; 92, 96; 93, identifier:bundled; 94, slice; 94, 95; 95, colon; 96, slice; 96, 97; 96, 98; 97, colon; 98, identifier:i; 99, identifier:delta_t_recent; 100, identifier:row; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:axis; 103, integer:1; 104, comment; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:century; 108, float:36524.0; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:start; 112, binary_operator:-; 112, 113; 112, 117; 113, subscript; 113, 114; 113, 115; 113, 116; 114, identifier:table; 115, integer:0; 116, integer:1; 117, identifier:century; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 122; 120, 124; 121, identifier:table; 122, slice; 122, 123; 123, colon; 124, integer:0; 125, expression_list; 125, 126; 125, 127; 126, identifier:start; 127, call; 127, 128; 127, 129; 128, identifier:delta_t_formula_morrison_and_stephenson_2004; 129, argument_list; 129, 130; 130, identifier:start; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:end; 134, binary_operator:+; 134, 135; 134, 140; 135, subscript; 135, 136; 135, 137; 135, 138; 136, identifier:table; 137, integer:0; 138, unary_operator:-; 138, 139; 139, integer:2; 140, identifier:century; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 149; 143, subscript; 143, 144; 143, 145; 143, 147; 144, identifier:table; 145, slice; 145, 146; 146, colon; 147, unary_operator:-; 147, 148; 148, integer:1; 149, expression_list; 149, 150; 149, 151; 150, identifier:end; 151, call; 151, 152; 151, 153; 152, identifier:delta_t_formula_morrison_and_stephenson_2004; 153, argument_list; 153, 154; 154, identifier:end; 155, return_statement; 155, 156; 156, identifier:table
def build_delta_t_table(delta_t_recent): """Build a table for interpolating Delta T. Given a 2xN array of recent Delta T values, whose element 0 is a sorted array of TT Julian dates and element 1 is Delta T values, this routine returns a more complete table by prepending two built-in data sources that ship with Skyfield as pre-built arrays: * The historical values from Morrison and Stephenson (2004) which the http://eclipse.gsfc.nasa.gov/SEcat5/deltat.html NASA web page presents in an HTML table. * The United States Naval Observatory ``historic_deltat.data`` values for Delta T over the years 1657 through 1984. """ ancient = load_bundled_npy('morrison_stephenson_deltat.npy') historic = load_bundled_npy('historic_deltat.npy') # Prefer USNO over Morrison and Stephenson where they overlap. historic_start_time = historic[0,0] i = searchsorted(ancient[0], historic_start_time) bundled = concatenate([ancient[:,:i], historic], axis=1) # Let recent data replace everything else. recent_start_time = delta_t_recent[0,0] i = searchsorted(bundled[0], recent_start_time) row = ((0,),(0,)) table = concatenate([row, bundled[:,:i], delta_t_recent, row], axis=1) # Create initial and final point to provide continuity with formula. century = 36524.0 start = table[0,1] - century table[:,0] = start, delta_t_formula_morrison_and_stephenson_2004(start) end = table[0,-2] + century table[:,-1] = end, delta_t_formula_morrison_and_stephenson_2004(end) return table
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 55; 2, function_name:plot_confusion_matrix_with_cv; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 3, 40; 3, 43; 3, 46; 3, 49; 3, 52; 4, identifier:clf; 5, identifier:X; 6, identifier:y; 7, default_parameter; 7, 8; 7, 9; 8, identifier:labels; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:true_labels; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:pred_labels; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:title; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:normalize; 21, False; 22, default_parameter; 22, 23; 22, 24; 23, identifier:hide_zeros; 24, False; 25, default_parameter; 25, 26; 25, 27; 26, identifier:x_tick_rotation; 27, integer:0; 28, default_parameter; 28, 29; 28, 30; 29, identifier:do_cv; 30, True; 31, default_parameter; 31, 32; 31, 33; 32, identifier:cv; 33, None; 34, default_parameter; 34, 35; 34, 36; 35, identifier:shuffle; 36, True; 37, default_parameter; 37, 38; 37, 39; 38, identifier:random_state; 39, None; 40, default_parameter; 40, 41; 40, 42; 41, identifier:ax; 42, None; 43, default_parameter; 43, 44; 43, 45; 44, identifier:figsize; 45, None; 46, default_parameter; 46, 47; 46, 48; 47, identifier:cmap; 48, string:'Blues'; 49, default_parameter; 49, 50; 49, 51; 50, identifier:title_fontsize; 51, string:"large"; 52, default_parameter; 52, 53; 52, 54; 53, identifier:text_fontsize; 54, string:"medium"; 55, block; 55, 56; 55, 58; 55, 67; 55, 228; 55, 278; 56, expression_statement; 56, 57; 57, comment; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:y; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:np; 64, identifier:array; 65, argument_list; 65, 66; 66, identifier:y; 67, if_statement; 67, 68; 67, 70; 67, 84; 68, not_operator; 68, 69; 69, identifier:do_cv; 70, block; 70, 71; 70, 80; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:y_pred; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:clf; 77, identifier:predict; 78, argument_list; 78, 79; 79, identifier:X; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:y_true; 83, identifier:y; 84, else_clause; 84, 85; 85, block; 85, 86; 85, 128; 85, 135; 85, 139; 85, 143; 85, 210; 85, 219; 86, if_statement; 86, 87; 86, 90; 86, 103; 86, 125; 87, comparison_operator:is; 87, 88; 87, 89; 88, identifier:cv; 89, None; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:cv; 94, call; 94, 95; 94, 96; 95, identifier:StratifiedKFold; 96, argument_list; 96, 97; 96, 100; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:shuffle; 99, identifier:shuffle; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:random_state; 102, identifier:random_state; 103, elif_clause; 103, 104; 103, 109; 104, call; 104, 105; 104, 106; 105, identifier:isinstance; 106, argument_list; 106, 107; 106, 108; 107, identifier:cv; 108, identifier:int; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:cv; 113, call; 113, 114; 113, 115; 114, identifier:StratifiedKFold; 115, argument_list; 115, 116; 115, 119; 115, 122; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:n_splits; 118, identifier:cv; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:shuffle; 121, identifier:shuffle; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:random_state; 124, identifier:random_state; 125, else_clause; 125, 126; 126, block; 126, 127; 127, pass_statement; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:clf_clone; 131, call; 131, 132; 131, 133; 132, identifier:clone; 133, argument_list; 133, 134; 134, identifier:clf; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:preds_list; 138, list:[]; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:trues_list; 142, list:[]; 143, for_statement; 143, 144; 143, 147; 143, 154; 144, pattern_list; 144, 145; 144, 146; 145, identifier:train_index; 146, identifier:test_index; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:cv; 150, identifier:split; 151, argument_list; 151, 152; 151, 153; 152, identifier:X; 153, identifier:y; 154, block; 154, 155; 154, 167; 154, 179; 154, 187; 154, 196; 154, 203; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, pattern_list; 157, 158; 157, 159; 158, identifier:X_train; 159, identifier:X_test; 160, expression_list; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:X; 163, identifier:train_index; 164, subscript; 164, 165; 164, 166; 165, identifier:X; 166, identifier:test_index; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, pattern_list; 169, 170; 169, 171; 170, identifier:y_train; 171, identifier:y_test; 172, expression_list; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:y; 175, identifier:train_index; 176, subscript; 176, 177; 176, 178; 177, identifier:y; 178, identifier:test_index; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:clf_clone; 183, identifier:fit; 184, argument_list; 184, 185; 184, 186; 185, identifier:X_train; 186, identifier:y_train; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:preds; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:clf_clone; 193, identifier:predict; 194, argument_list; 194, 195; 195, identifier:X_test; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:preds_list; 200, identifier:append; 201, argument_list; 201, 202; 202, identifier:preds; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:trues_list; 207, identifier:append; 208, argument_list; 208, 209; 209, identifier:y_test; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:y_pred; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:np; 216, identifier:concatenate; 217, argument_list; 217, 218; 218, identifier:preds_list; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:y_true; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:np; 225, identifier:concatenate; 226, argument_list; 226, 227; 227, identifier:trues_list; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:ax; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:plotters; 234, identifier:plot_confusion_matrix; 235, argument_list; 235, 236; 235, 239; 235, 242; 235, 245; 235, 248; 235, 251; 235, 254; 235, 257; 235, 260; 235, 263; 235, 266; 235, 269; 235, 272; 235, 275; 236, keyword_argument; 236, 237; 236, 238; 237, identifier:y_true; 238, identifier:y_true; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:y_pred; 241, identifier:y_pred; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:labels; 244, identifier:labels; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:true_labels; 247, identifier:true_labels; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:pred_labels; 250, identifier:pred_labels; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:title; 253, identifier:title; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:normalize; 256, identifier:normalize; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:hide_zeros; 259, identifier:hide_zeros; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:x_tick_rotation; 262, identifier:x_tick_rotation; 263, keyword_argument; 263, 264; 263, 265; 264, identifier:ax; 265, identifier:ax; 266, keyword_argument; 266, 267; 266, 268; 267, identifier:figsize; 268, identifier:figsize; 269, keyword_argument; 269, 270; 269, 271; 270, identifier:cmap; 271, identifier:cmap; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:title_fontsize; 274, identifier:title_fontsize; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:text_fontsize; 277, identifier:text_fontsize; 278, return_statement; 278, 279; 279, identifier:ax
def plot_confusion_matrix_with_cv(clf, X, y, labels=None, true_labels=None, pred_labels=None, title=None, normalize=False, hide_zeros=False, x_tick_rotation=0, do_cv=True, cv=None, shuffle=True, random_state=None, ax=None, figsize=None, cmap='Blues', title_fontsize="large", text_fontsize="medium"): """Generates the confusion matrix for a given classifier and dataset. Args: clf: Classifier instance that implements ``fit`` and ``predict`` methods. X (array-like, shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features. y (array-like, shape (n_samples) or (n_samples, n_features)): Target relative to X for classification. labels (array-like, shape (n_classes), optional): List of labels to index the matrix. This may be used to reorder or select a subset of labels. If none is given, those that appear at least once in ``y`` are used in sorted order. (new in v0.2.5) true_labels (array-like, optional): The true labels to display. If none is given, then all of the labels are used. pred_labels (array-like, optional): The predicted labels to display. If none is given, then all of the labels are used. title (string, optional): Title of the generated plot. Defaults to "Confusion Matrix" if normalize` is True. Else, defaults to "Normalized Confusion Matrix. normalize (bool, optional): If True, normalizes the confusion matrix before plotting. Defaults to False. hide_zeros (bool, optional): If True, does not plot cells containing a value of zero. Defaults to False. x_tick_rotation (int, optional): Rotates x-axis tick labels by the specified angle. This is useful in cases where there are numerous categories and the labels overlap each other. do_cv (bool, optional): If True, the classifier is cross-validated on the dataset using the cross-validation strategy in `cv` to generate the confusion matrix. If False, the confusion matrix is generated without training or cross-validating the classifier. This assumes that the classifier has already been called with its `fit` method beforehand. cv (int, cross-validation generator, iterable, optional): Determines the cross-validation strategy to be used for splitting. Possible inputs for cv are: - None, to use the default 3-fold cross-validation, - integer, to specify the number of folds. - An object to be used as a cross-validation generator. - An iterable yielding train/test splits. For integer/None inputs, if ``y`` is binary or multiclass, :class:`StratifiedKFold` used. If the estimator is not a classifier or if ``y`` is neither binary nor multiclass, :class:`KFold` is used. shuffle (bool, optional): Used when do_cv is set to True. Determines whether to shuffle the training data before splitting using cross-validation. Default set to True. random_state (int :class:`RandomState`): Pseudo-random number generator state used for random sampling. ax (:class:`matplotlib.axes.Axes`, optional): The axes upon which to plot the learning curve. If None, the plot is drawn on a new set of axes. figsize (2-tuple, optional): Tuple denoting figure size of the plot e.g. (6, 6). Defaults to ``None``. cmap (string or :class:`matplotlib.colors.Colormap` instance, optional): Colormap used for plotting the projection. View Matplotlib Colormap documentation for available options. https://matplotlib.org/users/colormaps.html title_fontsize (string or int, optional): Matplotlib-style fontsizes. Use e.g. "small", "medium", "large" or integer-values. Defaults to "large". text_fontsize (string or int, optional): Matplotlib-style fontsizes. Use e.g. "small", "medium", "large" or integer-values. Defaults to "medium". Returns: ax (:class:`matplotlib.axes.Axes`): The axes on which the plot was drawn. Example: >>> rf = classifier_factory(RandomForestClassifier()) >>> rf.plot_confusion_matrix(X, y, normalize=True) <matplotlib.axes._subplots.AxesSubplot object at 0x7fe967d64490> >>> plt.show() .. image:: _static/examples/plot_confusion_matrix.png :align: center :alt: Confusion matrix """ y = np.array(y) if not do_cv: y_pred = clf.predict(X) y_true = y else: if cv is None: cv = StratifiedKFold(shuffle=shuffle, random_state=random_state) elif isinstance(cv, int): cv = StratifiedKFold(n_splits=cv, shuffle=shuffle, random_state=random_state) else: pass clf_clone = clone(clf) preds_list = [] trues_list = [] for train_index, test_index in cv.split(X, y): X_train, X_test = X[train_index], X[test_index] y_train, y_test = y[train_index], y[test_index] clf_clone.fit(X_train, y_train) preds = clf_clone.predict(X_test) preds_list.append(preds) trues_list.append(y_test) y_pred = np.concatenate(preds_list) y_true = np.concatenate(trues_list) ax = plotters.plot_confusion_matrix(y_true=y_true, y_pred=y_pred, labels=labels, true_labels=true_labels, pred_labels=pred_labels, title=title, normalize=normalize, hide_zeros=hide_zeros, x_tick_rotation=x_tick_rotation, ax=ax, figsize=figsize, cmap=cmap, title_fontsize=title_fontsize, text_fontsize=text_fontsize) return ax
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 42; 2, function_name:plot_confusion_matrix; 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; 4, identifier:y_true; 5, identifier:y_pred; 6, default_parameter; 6, 7; 6, 8; 7, identifier:labels; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:true_labels; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:pred_labels; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:title; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:normalize; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:hide_zeros; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:x_tick_rotation; 26, integer:0; 27, default_parameter; 27, 28; 27, 29; 28, identifier:ax; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:figsize; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:cmap; 35, string:'Blues'; 36, default_parameter; 36, 37; 36, 38; 37, identifier:title_fontsize; 38, string:"large"; 39, default_parameter; 39, 40; 39, 41; 40, identifier:text_fontsize; 41, string:"medium"; 42, block; 42, 43; 42, 45; 42, 65; 42, 76; 42, 100; 42, 150; 42, 190; 42, 232; 42, 270; 42, 292; 42, 301; 42, 313; 42, 325; 42, 332; 42, 345; 42, 352; 42, 362; 42, 372; 42, 442; 42, 452; 42, 462; 42, 469; 43, expression_statement; 43, 44; 44, comment; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:ax; 48, None; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, pattern_list; 52, 53; 52, 54; 53, identifier:fig; 54, identifier:ax; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:plt; 58, identifier:subplots; 59, argument_list; 59, 60; 59, 61; 59, 62; 60, integer:1; 61, integer:1; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:figsize; 64, identifier:figsize; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:cm; 68, call; 68, 69; 68, 70; 69, identifier:confusion_matrix; 70, argument_list; 70, 71; 70, 72; 70, 73; 71, identifier:y_true; 72, identifier:y_pred; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:labels; 75, identifier:labels; 76, if_statement; 76, 77; 76, 80; 76, 89; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:labels; 79, None; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:classes; 84, call; 84, 85; 84, 86; 85, identifier:unique_labels; 86, argument_list; 86, 87; 86, 88; 87, identifier:y_true; 88, identifier:y_pred; 89, else_clause; 89, 90; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:classes; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:np; 97, identifier:asarray; 98, argument_list; 98, 99; 99, identifier:labels; 100, if_statement; 100, 101; 100, 102; 101, identifier:normalize; 102, block; 102, 103; 102, 127; 102, 139; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:cm; 106, binary_operator:/; 106, 107; 106, 113; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:cm; 110, identifier:astype; 111, argument_list; 111, 112; 112, string:'float'; 113, subscript; 113, 114; 113, 122; 113, 124; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:cm; 117, identifier:sum; 118, argument_list; 118, 119; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:axis; 121, integer:1; 122, slice; 122, 123; 123, colon; 124, attribute; 124, 125; 124, 126; 125, identifier:np; 126, identifier:newaxis; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:cm; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:np; 133, identifier:around; 134, argument_list; 134, 135; 134, 136; 135, identifier:cm; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:decimals; 138, integer:2; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 149; 141, subscript; 141, 142; 141, 143; 142, identifier:cm; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:np; 146, identifier:isnan; 147, argument_list; 147, 148; 148, identifier:cm; 149, float:0.0; 150, if_statement; 150, 151; 150, 154; 150, 159; 151, comparison_operator:is; 151, 152; 151, 153; 152, identifier:true_labels; 153, None; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:true_classes; 158, identifier:classes; 159, else_clause; 159, 160; 160, block; 160, 161; 160, 168; 160, 178; 160, 184; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:validate_labels; 164, argument_list; 164, 165; 164, 166; 164, 167; 165, identifier:classes; 166, identifier:true_labels; 167, string:"true_labels"; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:true_label_indexes; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:np; 174, identifier:in1d; 175, argument_list; 175, 176; 175, 177; 176, identifier:classes; 177, identifier:true_labels; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:true_classes; 181, subscript; 181, 182; 181, 183; 182, identifier:classes; 183, identifier:true_label_indexes; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:cm; 187, subscript; 187, 188; 187, 189; 188, identifier:cm; 189, identifier:true_label_indexes; 190, if_statement; 190, 191; 190, 194; 190, 199; 191, comparison_operator:is; 191, 192; 191, 193; 192, identifier:pred_labels; 193, None; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:pred_classes; 198, identifier:classes; 199, else_clause; 199, 200; 200, block; 200, 201; 200, 208; 200, 218; 200, 224; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:validate_labels; 204, argument_list; 204, 205; 204, 206; 204, 207; 205, identifier:classes; 206, identifier:pred_labels; 207, string:"pred_labels"; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:pred_label_indexes; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:np; 214, identifier:in1d; 215, argument_list; 215, 216; 215, 217; 216, identifier:classes; 217, identifier:pred_labels; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:pred_classes; 221, subscript; 221, 222; 221, 223; 222, identifier:classes; 223, identifier:pred_label_indexes; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:cm; 227, subscript; 227, 228; 227, 229; 227, 231; 228, identifier:cm; 229, slice; 229, 230; 230, colon; 231, identifier:pred_label_indexes; 232, if_statement; 232, 233; 232, 234; 232, 245; 232, 258; 233, identifier:title; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:ax; 239, identifier:set_title; 240, argument_list; 240, 241; 240, 242; 241, identifier:title; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:fontsize; 244, identifier:title_fontsize; 245, elif_clause; 245, 246; 245, 247; 246, identifier:normalize; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:ax; 252, identifier:set_title; 253, argument_list; 253, 254; 253, 255; 254, string:'Normalized Confusion Matrix'; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:fontsize; 257, identifier:title_fontsize; 258, else_clause; 258, 259; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:ax; 264, identifier:set_title; 265, argument_list; 265, 266; 265, 267; 266, string:'Confusion Matrix'; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:fontsize; 269, identifier:title_fontsize; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:image; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:ax; 276, identifier:imshow; 277, argument_list; 277, 278; 277, 279; 277, 282; 278, identifier:cm; 279, keyword_argument; 279, 280; 279, 281; 280, identifier:interpolation; 281, string:'nearest'; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:cmap; 284, call; 284, 285; 284, 290; 285, attribute; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:plt; 288, identifier:cm; 289, identifier:get_cmap; 290, argument_list; 290, 291; 291, identifier:cmap; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:plt; 296, identifier:colorbar; 297, argument_list; 297, 298; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:mappable; 300, identifier:image; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:x_tick_marks; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:np; 307, identifier:arange; 308, argument_list; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:len; 311, argument_list; 311, 312; 312, identifier:pred_classes; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:y_tick_marks; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:np; 319, identifier:arange; 320, argument_list; 320, 321; 321, call; 321, 322; 321, 323; 322, identifier:len; 323, argument_list; 323, 324; 324, identifier:true_classes; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:ax; 329, identifier:set_xticks; 330, argument_list; 330, 331; 331, identifier:x_tick_marks; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:ax; 336, identifier:set_xticklabels; 337, argument_list; 337, 338; 337, 339; 337, 342; 338, identifier:pred_classes; 339, keyword_argument; 339, 340; 339, 341; 340, identifier:fontsize; 341, identifier:text_fontsize; 342, keyword_argument; 342, 343; 342, 344; 343, identifier:rotation; 344, identifier:x_tick_rotation; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:ax; 349, identifier:set_yticks; 350, argument_list; 350, 351; 351, identifier:y_tick_marks; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:ax; 356, identifier:set_yticklabels; 357, argument_list; 357, 358; 357, 359; 358, identifier:true_classes; 359, keyword_argument; 359, 360; 359, 361; 360, identifier:fontsize; 361, identifier:text_fontsize; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 365; 364, identifier:thresh; 365, binary_operator:/; 365, 366; 365, 371; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:cm; 369, identifier:max; 370, argument_list; 371, float:2.; 372, for_statement; 372, 373; 372, 376; 372, 397; 373, pattern_list; 373, 374; 373, 375; 374, identifier:i; 375, identifier:j; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:itertools; 379, identifier:product; 380, argument_list; 380, 381; 380, 389; 381, call; 381, 382; 381, 383; 382, identifier:range; 383, argument_list; 383, 384; 384, subscript; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:cm; 387, identifier:shape; 388, integer:0; 389, call; 389, 390; 389, 391; 390, identifier:range; 391, argument_list; 391, 392; 392, subscript; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:cm; 395, identifier:shape; 396, integer:1; 397, block; 397, 398; 398, if_statement; 398, 399; 398, 409; 399, not_operator; 399, 400; 400, parenthesized_expression; 400, 401; 401, boolean_operator:and; 401, 402; 401, 403; 402, identifier:hide_zeros; 403, comparison_operator:==; 403, 404; 403, 408; 404, subscript; 404, 405; 404, 406; 404, 407; 405, identifier:cm; 406, identifier:i; 407, identifier:j; 408, integer:0; 409, block; 409, 410; 410, expression_statement; 410, 411; 411, call; 411, 412; 411, 415; 412, attribute; 412, 413; 412, 414; 413, identifier:ax; 414, identifier:text; 415, argument_list; 415, 416; 415, 417; 415, 418; 415, 422; 415, 425; 415, 428; 415, 431; 416, identifier:j; 417, identifier:i; 418, subscript; 418, 419; 418, 420; 418, 421; 419, identifier:cm; 420, identifier:i; 421, identifier:j; 422, keyword_argument; 422, 423; 422, 424; 423, identifier:horizontalalignment; 424, string:"center"; 425, keyword_argument; 425, 426; 425, 427; 426, identifier:verticalalignment; 427, string:"center"; 428, keyword_argument; 428, 429; 428, 430; 429, identifier:fontsize; 430, identifier:text_fontsize; 431, keyword_argument; 431, 432; 431, 433; 432, identifier:color; 433, conditional_expression:if; 433, 434; 433, 435; 433, 441; 434, string:"white"; 435, comparison_operator:>; 435, 436; 435, 440; 436, subscript; 436, 437; 436, 438; 436, 439; 437, identifier:cm; 438, identifier:i; 439, identifier:j; 440, identifier:thresh; 441, string:"black"; 442, expression_statement; 442, 443; 443, call; 443, 444; 443, 447; 444, attribute; 444, 445; 444, 446; 445, identifier:ax; 446, identifier:set_ylabel; 447, argument_list; 447, 448; 447, 449; 448, string:'True label'; 449, keyword_argument; 449, 450; 449, 451; 450, identifier:fontsize; 451, identifier:text_fontsize; 452, expression_statement; 452, 453; 453, call; 453, 454; 453, 457; 454, attribute; 454, 455; 454, 456; 455, identifier:ax; 456, identifier:set_xlabel; 457, argument_list; 457, 458; 457, 459; 458, string:'Predicted label'; 459, keyword_argument; 459, 460; 459, 461; 460, identifier:fontsize; 461, identifier:text_fontsize; 462, expression_statement; 462, 463; 463, call; 463, 464; 463, 467; 464, attribute; 464, 465; 464, 466; 465, identifier:ax; 466, identifier:grid; 467, argument_list; 467, 468; 468, string:'off'; 469, return_statement; 469, 470; 470, identifier:ax
def plot_confusion_matrix(y_true, y_pred, labels=None, true_labels=None, pred_labels=None, title=None, normalize=False, hide_zeros=False, x_tick_rotation=0, ax=None, figsize=None, cmap='Blues', title_fontsize="large", text_fontsize="medium"): """Generates confusion matrix plot from predictions and true labels Args: y_true (array-like, shape (n_samples)): Ground truth (correct) target values. y_pred (array-like, shape (n_samples)): Estimated targets as returned by a classifier. labels (array-like, shape (n_classes), optional): List of labels to index the matrix. This may be used to reorder or select a subset of labels. If none is given, those that appear at least once in ``y_true`` or ``y_pred`` are used in sorted order. (new in v0.2.5) true_labels (array-like, optional): The true labels to display. If none is given, then all of the labels are used. pred_labels (array-like, optional): The predicted labels to display. If none is given, then all of the labels are used. title (string, optional): Title of the generated plot. Defaults to "Confusion Matrix" if `normalize` is True. Else, defaults to "Normalized Confusion Matrix. normalize (bool, optional): If True, normalizes the confusion matrix before plotting. Defaults to False. hide_zeros (bool, optional): If True, does not plot cells containing a value of zero. Defaults to False. x_tick_rotation (int, optional): Rotates x-axis tick labels by the specified angle. This is useful in cases where there are numerous categories and the labels overlap each other. ax (:class:`matplotlib.axes.Axes`, optional): The axes upon which to plot the curve. If None, the plot is drawn on a new set of axes. figsize (2-tuple, optional): Tuple denoting figure size of the plot e.g. (6, 6). Defaults to ``None``. cmap (string or :class:`matplotlib.colors.Colormap` instance, optional): Colormap used for plotting the projection. View Matplotlib Colormap documentation for available options. https://matplotlib.org/users/colormaps.html title_fontsize (string or int, optional): Matplotlib-style fontsizes. Use e.g. "small", "medium", "large" or integer-values. Defaults to "large". text_fontsize (string or int, optional): Matplotlib-style fontsizes. Use e.g. "small", "medium", "large" or integer-values. Defaults to "medium". Returns: ax (:class:`matplotlib.axes.Axes`): The axes on which the plot was drawn. Example: >>> import scikitplot.plotters as skplt >>> rf = RandomForestClassifier() >>> rf = rf.fit(X_train, y_train) >>> y_pred = rf.predict(X_test) >>> skplt.plot_confusion_matrix(y_test, y_pred, normalize=True) <matplotlib.axes._subplots.AxesSubplot object at 0x7fe967d64490> >>> plt.show() .. image:: _static/examples/plot_confusion_matrix.png :align: center :alt: Confusion matrix """ if ax is None: fig, ax = plt.subplots(1, 1, figsize=figsize) cm = confusion_matrix(y_true, y_pred, labels=labels) if labels is None: classes = unique_labels(y_true, y_pred) else: classes = np.asarray(labels) if normalize: cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] cm = np.around(cm, decimals=2) cm[np.isnan(cm)] = 0.0 if true_labels is None: true_classes = classes else: validate_labels(classes, true_labels, "true_labels") true_label_indexes = np.in1d(classes, true_labels) true_classes = classes[true_label_indexes] cm = cm[true_label_indexes] if pred_labels is None: pred_classes = classes else: validate_labels(classes, pred_labels, "pred_labels") pred_label_indexes = np.in1d(classes, pred_labels) pred_classes = classes[pred_label_indexes] cm = cm[:, pred_label_indexes] if title: ax.set_title(title, fontsize=title_fontsize) elif normalize: ax.set_title('Normalized Confusion Matrix', fontsize=title_fontsize) else: ax.set_title('Confusion Matrix', fontsize=title_fontsize) image = ax.imshow(cm, interpolation='nearest', cmap=plt.cm.get_cmap(cmap)) plt.colorbar(mappable=image) x_tick_marks = np.arange(len(pred_classes)) y_tick_marks = np.arange(len(true_classes)) ax.set_xticks(x_tick_marks) ax.set_xticklabels(pred_classes, fontsize=text_fontsize, rotation=x_tick_rotation) ax.set_yticks(y_tick_marks) ax.set_yticklabels(true_classes, fontsize=text_fontsize) thresh = cm.max() / 2. for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])): if not (hide_zeros and cm[i, j] == 0): ax.text(j, i, cm[i, j], horizontalalignment="center", verticalalignment="center", fontsize=text_fontsize, color="white" if cm[i, j] > thresh else "black") ax.set_ylabel('True label', fontsize=text_fontsize) ax.set_xlabel('Predicted label', fontsize=text_fontsize) ax.grid('off') return ax
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorting; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 126; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 17; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:qs; 14, identifier:get; 15, argument_list; 15, 16; 16, string:'sort'; 17, block; 17, 18; 17, 22; 17, 124; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:sorting_results; 21, list:[]; 22, for_statement; 22, 23; 22, 24; 22, 34; 23, identifier:sort_field; 24, call; 24, 25; 24, 32; 25, attribute; 25, 26; 25, 31; 26, subscript; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:qs; 30, string:'sort'; 31, identifier:split; 32, argument_list; 32, 33; 33, string:','; 34, block; 34, 35; 34, 45; 34, 69; 34, 89; 34, 99; 34, 111; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:field; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:sort_field; 41, identifier:replace; 42, argument_list; 42, 43; 42, 44; 43, string:'-'; 44, string:''; 45, if_statement; 45, 46; 45, 53; 46, comparison_operator:not; 46, 47; 46, 48; 47, identifier:field; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:schema; 52, identifier:_declared_fields; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:InvalidSort; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:"{} has no attribute {}"; 61, identifier:format; 62, argument_list; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:schema; 67, identifier:__name__; 68, identifier:field; 69, if_statement; 69, 70; 69, 78; 70, comparison_operator:in; 70, 71; 70, 72; 71, identifier:field; 72, call; 72, 73; 72, 74; 73, identifier:get_relationships; 74, argument_list; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:schema; 78, block; 78, 79; 79, raise_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:InvalidSort; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, string:"You can't sort on {} because it is a relationship field"; 86, identifier:format; 87, argument_list; 87, 88; 88, identifier:field; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:field; 92, call; 92, 93; 92, 94; 93, identifier:get_model_field; 94, argument_list; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:schema; 98, identifier:field; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:order; 102, conditional_expression:if; 102, 103; 102, 104; 102, 110; 103, string:'desc'; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:sort_field; 107, identifier:startswith; 108, argument_list; 108, 109; 109, string:'-'; 110, string:'asc'; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:sorting_results; 115, identifier:append; 116, argument_list; 116, 117; 117, dictionary; 117, 118; 117, 121; 118, pair; 118, 119; 118, 120; 119, string:'field'; 120, identifier:field; 121, pair; 121, 122; 121, 123; 122, string:'order'; 123, identifier:order; 124, return_statement; 124, 125; 125, identifier:sorting_results; 126, return_statement; 126, 127; 127, list:[]
def sorting(self): """Return fields to sort by including sort name for SQLAlchemy and row sort parameter for other ORMs :return list: a list of sorting information Example of return value:: [ {'field': 'created_at', 'order': 'desc'}, ] """ if self.qs.get('sort'): sorting_results = [] for sort_field in self.qs['sort'].split(','): field = sort_field.replace('-', '') if field not in self.schema._declared_fields: raise InvalidSort("{} has no attribute {}".format(self.schema.__name__, field)) if field in get_relationships(self.schema): raise InvalidSort("You can't sort on {} because it is a relationship field".format(field)) field = get_model_field(self.schema, field) order = 'desc' if sort_field.startswith('-') else 'asc' sorting_results.append({'field': field, 'order': order}) return sorting_results return []
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:filter_query; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:query; 6, identifier:filter_info; 7, identifier:model; 8, block; 8, 9; 8, 11; 8, 35; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 13; 12, identifier:filter_info; 13, block; 13, 14; 13, 25; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:filters; 17, call; 17, 18; 17, 19; 18, identifier:create_filters; 19, argument_list; 19, 20; 19, 21; 19, 22; 20, identifier:model; 21, identifier:filter_info; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:resource; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:query; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:query; 31, identifier:filter; 32, argument_list; 32, 33; 33, list_splat; 33, 34; 34, identifier:filters; 35, return_statement; 35, 36; 36, identifier:query
def filter_query(self, query, filter_info, model): """Filter query according to jsonapi 1.0 :param Query query: sqlalchemy query to sort :param filter_info: filter information :type filter_info: dict or None :param DeclarativeMeta model: an sqlalchemy model :return Query: the sorted query """ if filter_info: filters = create_filters(model, filter_info, self.resource) query = query.filter(*filters) return query
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort_query; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:query; 6, identifier:sort_info; 7, block; 7, 8; 7, 10; 7, 68; 8, expression_statement; 8, 9; 9, comment; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:sort_opt; 12, identifier:sort_info; 13, block; 13, 14; 13, 20; 13, 45; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:field; 17, subscript; 17, 18; 17, 19; 18, identifier:sort_opt; 19, string:'field'; 20, if_statement; 20, 21; 20, 29; 21, not_operator; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:hasattr; 24, argument_list; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:model; 28, identifier:field; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:InvalidSort; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, string:"{} has no attribute {}"; 37, identifier:format; 38, argument_list; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:model; 43, identifier:__name__; 44, identifier:field; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:query; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:query; 51, identifier:order_by; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 67; 54, call; 54, 55; 54, 56; 55, identifier:getattr; 56, argument_list; 56, 57; 56, 64; 57, call; 57, 58; 57, 59; 58, identifier:getattr; 59, argument_list; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:model; 63, identifier:field; 64, subscript; 64, 65; 64, 66; 65, identifier:sort_opt; 66, string:'order'; 67, argument_list; 68, return_statement; 68, 69; 69, identifier:query
def sort_query(self, query, sort_info): """Sort query according to jsonapi 1.0 :param Query query: sqlalchemy query to sort :param list sort_info: sort information :return Query: the sorted query """ for sort_opt in sort_info: field = sort_opt['field'] if not hasattr(self.model, field): raise InvalidSort("{} has no attribute {}".format(self.model.__name__, field)) query = query.order_by(getattr(getattr(self.model, field), sort_opt['order'])()) return query
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 25; 2, function_name:_get_log_entries; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, generic_type; 6, 7; 6, 8; 7, identifier:List; 8, type_parameter; 8, 9; 9, type; 9, 10; 10, generic_type; 10, 11; 10, 12; 11, identifier:Tuple; 12, type_parameter; 12, 13; 12, 15; 12, 17; 12, 23; 13, type; 13, 14; 14, identifier:int; 15, type; 15, 16; 16, identifier:bytes; 17, type; 17, 18; 18, generic_type; 18, 19; 18, 20; 19, identifier:List; 20, type_parameter; 20, 21; 21, type; 21, 22; 22, identifier:int; 23, type; 23, 24; 24, identifier:bytes; 25, block; 25, 26; 25, 28; 26, expression_statement; 26, 27; 27, comment; 28, if_statement; 28, 29; 28, 32; 28, 35; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:is_error; 32, block; 32, 33; 33, return_statement; 33, 34; 34, list:[]; 35, else_clause; 35, 36; 36, block; 36, 37; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:sorted; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:itertools; 44, identifier:chain; 45, argument_list; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_log_entries; 49, list_splat; 49, 50; 50, generator_expression; 50, 51; 50, 56; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:child; 54, identifier:_get_log_entries; 55, argument_list; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:child; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:children
def _get_log_entries(self) -> List[Tuple[int, bytes, List[int], bytes]]: """ Return the log entries for this computation and its children. They are sorted in the same order they were emitted during the transaction processing, and include the sequential counter as the first element of the tuple representing every entry. """ if self.is_error: return [] else: return sorted(itertools.chain( self._log_entries, *(child._get_log_entries() for child in self.children) ))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sort_by_size; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:group_limit; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:discard_others; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:others_label; 13, string:'others'; 14, block; 14, 15; 14, 17; 14, 18; 14, 51; 14, 52; 14, 162; 14, 163; 15, expression_statement; 15, 16; 16, comment; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:groups; 23, call; 23, 24; 23, 25; 24, identifier:OrderedDict; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 28, 37; 28, 48; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:six; 32, identifier:iteritems; 33, argument_list; 33, 34; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:groups; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, lambda; 39, 40; 39, 42; 40, lambda_parameters; 40, 41; 41, identifier:x; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, subscript; 45, 46; 45, 47; 46, identifier:x; 47, integer:1; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:reverse; 50, True; 51, comment; 52, if_statement; 52, 53; 52, 56; 52, 57; 53, comparison_operator:is; 53, 54; 53, 55; 54, identifier:group_limit; 55, None; 56, comment; 57, block; 57, 58; 57, 106; 57, 107; 57, 136; 57, 137; 58, if_statement; 58, 59; 58, 61; 58, 90; 59, not_operator; 59, 60; 60, identifier:discard_others; 61, block; 61, 62; 61, 78; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:group_keys; 65, subscript; 65, 66; 65, 73; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:groups; 71, identifier:keys; 72, argument_list; 73, slice; 73, 74; 73, 77; 74, binary_operator:-; 74, 75; 74, 76; 75, identifier:group_limit; 76, integer:1; 77, colon; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:groups; 84, identifier:setdefault; 85, argument_list; 85, 86; 85, 87; 86, identifier:others_label; 87, call; 87, 88; 87, 89; 88, identifier:list; 89, argument_list; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:group_keys; 95, subscript; 95, 96; 95, 103; 96, call; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:groups; 101, identifier:keys; 102, argument_list; 103, slice; 103, 104; 103, 105; 104, identifier:group_limit; 105, colon; 106, comment; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:g; 109, identifier:group_keys; 110, block; 110, 111; 110, 130; 111, if_statement; 111, 112; 111, 114; 112, not_operator; 112, 113; 113, identifier:discard_others; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 124; 117, attribute; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:groups; 122, identifier:others_label; 123, identifier:extend; 124, argument_list; 124, 125; 125, subscript; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:groups; 129, identifier:g; 130, delete_statement; 130, 131; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:groups; 135, identifier:g; 136, comment; 137, if_statement; 137, 138; 137, 155; 138, parenthesized_expression; 138, 139; 139, boolean_operator:and; 139, 140; 139, 145; 140, comparison_operator:in; 140, 141; 140, 142; 141, identifier:others_label; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:groups; 145, comparison_operator:==; 145, 146; 145, 154; 146, call; 146, 147; 146, 148; 147, identifier:len; 148, argument_list; 148, 149; 149, subscript; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:groups; 153, identifier:others_label; 154, integer:0; 155, block; 155, 156; 156, delete_statement; 156, 157; 157, subscript; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:groups; 161, identifier:others_label; 162, comment; 163, if_statement; 163, 164; 163, 171; 164, boolean_operator:and; 164, 165; 164, 166; 165, identifier:discard_others; 166, comparison_operator:in; 166, 167; 166, 168; 167, identifier:others_label; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:groups; 171, block; 171, 172; 172, delete_statement; 172, 173; 173, subscript; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:groups; 177, identifier:others_label
def sort_by_size(self, group_limit=None, discard_others=False, others_label='others'): """ Sort the groups by the number of elements they contain, descending. Also has option to limit the number of groups. If this option is chosen, the remaining elements are placed into another group with the name specified with others_label. if discard_others is True, the others group is removed instead. """ # sort groups by number of elements self.groups = OrderedDict(sorted(six.iteritems(self.groups), key=lambda x: len(x[1]), reverse=True)) # if group-limit is provided, combine remaining groups if group_limit is not None: # now group together all groups that did not make the limit if not discard_others: group_keys = self.groups.keys()[group_limit - 1:] self.groups.setdefault(others_label, list()) else: group_keys = self.groups.keys()[group_limit:] # only go to second last (-1), since the 'others' group is now last for g in group_keys: if not discard_others: self.groups[others_label].extend(self.groups[g]) del self.groups[g] # remove if empty if (others_label in self.groups and len(self.groups[others_label]) == 0): del self.groups[others_label] # remove others group regardless of limit if requested if discard_others and others_label in self.groups: del self.groups[others_label]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_comments; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:resource; 6, default_parameter; 6, 7; 6, 8; 7, identifier:before; 8, None; 9, block; 9, 10; 9, 12; 9, 29; 9, 69; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:params; 15, call; 15, 16; 15, 17; 16, identifier:dict; 17, argument_list; 17, 18; 17, 23; 17, 26; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:apikey; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:api_key; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:resource; 25, identifier:resource; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:before; 28, identifier:before; 29, try_statement; 29, 30; 29, 52; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:response; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:requests; 37, identifier:get; 38, argument_list; 38, 39; 38, 44; 38, 47; 39, binary_operator:+; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:base; 43, string:'comments/get'; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:params; 46, identifier:params; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:proxies; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:proxies; 52, except_clause; 52, 53; 52, 59; 53, as_pattern; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:requests; 56, identifier:RequestException; 57, as_pattern_target; 57, 58; 58, identifier:e; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:dict; 63, argument_list; 63, 64; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:error; 66, attribute; 66, 67; 66, 68; 67, identifier:e; 68, identifier:message; 69, return_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:_return_response_and_status_code; 72, argument_list; 72, 73; 73, identifier:response
def get_comments(self, resource, before=None): """ Get comments for a file or URL. Retrieve a list of VirusTotal Community comments for a given file or URL. VirusTotal Community comments are user submitted reviews on a given item, these comments may contain anything from the in-the-wild locations of files up to fully-featured reverse engineering reports on a given sample. :param resource: Either an md5/sha1/sha256 hash of the file or the URL itself you want to retrieve. :param before: (optional) A datetime token that allows you to iterate over all comments on a specific item whenever it has been commented on more than 25 times. :return: JSON response - The application answers with the comments sorted in descending order according to their date. """ params = dict(apikey=self.api_key, resource=resource, before=before) try: response = requests.get(self.base + 'comments/get', params=params, proxies=self.proxies) except requests.RequestException as e: return dict(error=e.message) return _return_response_and_status_code(response)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:clean_fail; 3, parameters; 3, 4; 4, identifier:func; 5, block; 5, 6; 5, 8; 5, 56; 6, expression_statement; 6, 7; 7, string:''' A decorator to cleanly exit on a failed call to AWS. catch a `botocore.exceptions.ClientError` raised from an action. This sort of error is raised if you are targeting a region that isn't set up (see, `credstash setup`. '''; 8, function_definition; 8, 9; 8, 10; 8, 15; 9, function_name:func_wrapper; 10, parameters; 10, 11; 10, 13; 11, list_splat_pattern; 11, 12; 12, identifier:args; 13, dictionary_splat_pattern; 13, 14; 14, identifier:kwargs; 15, block; 15, 16; 16, try_statement; 16, 17; 16, 26; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:func; 21, argument_list; 21, 22; 21, 24; 22, list_splat; 22, 23; 23, identifier:args; 24, dictionary_splat; 24, 25; 25, identifier:kwargs; 26, except_clause; 26, 27; 26, 35; 27, as_pattern; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:botocore; 31, identifier:exceptions; 32, identifier:ClientError; 33, as_pattern_target; 33, 34; 34, identifier:e; 35, block; 35, 36; 35, 49; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:print; 39, argument_list; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:str; 42, argument_list; 42, 43; 43, identifier:e; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:file; 46, attribute; 46, 47; 46, 48; 47, identifier:sys; 48, identifier:stderr; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:sys; 53, identifier:exit; 54, argument_list; 54, 55; 55, integer:1; 56, return_statement; 56, 57; 57, identifier:func_wrapper
def clean_fail(func): ''' A decorator to cleanly exit on a failed call to AWS. catch a `botocore.exceptions.ClientError` raised from an action. This sort of error is raised if you are targeting a region that isn't set up (see, `credstash setup`. ''' def func_wrapper(*args, **kwargs): try: return func(*args, **kwargs) except botocore.exceptions.ClientError as e: print(str(e), file=sys.stderr) sys.exit(1) return func_wrapper
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:parse_header; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:value; 7, string:'*/*'; 8, block; 8, 9; 8, 11; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, yield; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:sorted; 15, argument_list; 15, 16; 15, 41; 16, generator_expression; 16, 17; 16, 27; 16, 35; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:cls; 20, identifier:from_string; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:token; 25, identifier:strip; 26, argument_list; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:token; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:value; 32, identifier:split; 33, argument_list; 33, 34; 34, string:','; 35, if_clause; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:token; 39, identifier:strip; 40, argument_list; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:reverse; 43, True
def parse_header(cls, value='*/*'): """Parse HTTP accept header and return instances sorted by weight.""" yield from sorted(( cls.from_string(token.strip()) for token in value.split(',') if token.strip() ), reverse=True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_canonical; 3, parameters; 3, 4; 3, 5; 4, identifier:keyword; 5, identifier:stmts; 6, block; 6, 7; 6, 9; 6, 24; 6, 28; 6, 29; 6, 42; 6, 109; 6, 110; 6, 125; 7, expression_statement; 7, 8; 8, comment; 9, try_statement; 9, 10; 9, 19; 10, block; 10, 11; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 16; 13, tuple_pattern; 13, 14; 13, 15; 14, identifier:_arg_type; 15, identifier:subspec; 16, subscript; 16, 17; 16, 18; 17, identifier:stmt_map; 18, identifier:keyword; 19, except_clause; 19, 20; 19, 21; 20, identifier:KeyError; 21, block; 21, 22; 22, return_statement; 22, 23; 23, identifier:stmts; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:res; 27, list:[]; 28, comment; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:keep; 32, binary_operator:+; 32, 33; 32, 40; 33, list_comprehension; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:s; 36, integer:0; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:s; 39, identifier:data_def_stmts; 40, list:['case']; 40, 41; 41, string:'case'; 42, for_statement; 42, 43; 42, 46; 42, 50; 42, 51; 43, tuple_pattern; 43, 44; 43, 45; 44, identifier:kw; 45, identifier:_spec; 46, call; 46, 47; 46, 48; 47, identifier:flatten_spec; 48, argument_list; 48, 49; 49, identifier:subspec; 50, comment; 51, block; 51, 52; 51, 56; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:comments; 55, list:[]; 56, for_statement; 56, 57; 56, 58; 56, 59; 57, identifier:s; 58, identifier:stmts; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 66; 60, 74; 60, 103; 61, comparison_operator:==; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:s; 64, identifier:keyword; 65, string:'_comment'; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:comments; 71, identifier:append; 72, argument_list; 72, 73; 73, identifier:s; 74, elif_clause; 74, 75; 74, 84; 75, boolean_operator:and; 75, 76; 75, 81; 76, comparison_operator:==; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:s; 79, identifier:keyword; 80, identifier:kw; 81, comparison_operator:not; 81, 82; 81, 83; 82, identifier:kw; 83, identifier:keep; 84, block; 84, 85; 84, 92; 84, 96; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:res; 89, identifier:extend; 90, argument_list; 90, 91; 91, identifier:comments; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:comments; 95, list:[]; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:res; 100, identifier:append; 101, argument_list; 101, 102; 102, identifier:s; 103, else_clause; 103, 104; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:comments; 108, list:[]; 109, comment; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:res; 114, identifier:extend; 115, argument_list; 115, 116; 116, list_comprehension; 116, 117; 116, 118; 116, 121; 117, identifier:stmt; 118, for_in_clause; 118, 119; 118, 120; 119, identifier:stmt; 120, identifier:stmts; 121, if_clause; 121, 122; 122, comparison_operator:not; 122, 123; 122, 124; 123, identifier:stmt; 124, identifier:res; 125, return_statement; 125, 126; 126, identifier:res
def sort_canonical(keyword, stmts): """Sort all `stmts` in the canonical order defined by `keyword`. Return the sorted list. The `stmt` list is not modified. If `keyword` does not have a canonical order, the list is returned as is. """ try: (_arg_type, subspec) = stmt_map[keyword] except KeyError: return stmts res = [] # keep the order of data definition statements and case keep = [s[0] for s in data_def_stmts] + ['case'] for (kw, _spec) in flatten_spec(subspec): # keep comments before a statement together with that statement comments = [] for s in stmts: if s.keyword == '_comment': comments.append(s) elif s.keyword == kw and kw not in keep: res.extend(comments) comments = [] res.append(s) else: comments = [] # then copy all other statements (extensions) res.extend([stmt for stmt in stmts if stmt not in res]) return res
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:start; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:num; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:by; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:get; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:desc; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:alpha; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:store; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:groups; 29, False; 30, block; 30, 31; 30, 33; 30, 58; 30, 63; 30, 82; 30, 112; 30, 162; 30, 172; 30, 182; 30, 201; 30, 229; 30, 242; 31, expression_statement; 31, 32; 32, string:'''Sort and return the list, set or sorted set at ``key``. ``start`` and ``num`` allow for paging through the sorted data ``by`` allows using an external key to weight and sort the items. Use an "*" to indicate where in the key the item value is located ``get`` allows for returning items from external keys rather than the sorted data itself. Use an "*" to indicate where int he key the item value is located ``desc`` allows for reversing the sort ``alpha`` allows for sorting lexicographically rather than numerically ``store`` allows for storing the result of the sort into the key ``store`` ``groups`` if set to True and if ``get`` contains at least two elements, sort will return a list of tuples, each containing the values fetched from the arguments to ``get``. '''; 33, if_statement; 33, 34; 33, 52; 34, parenthesized_expression; 34, 35; 35, boolean_operator:or; 35, 36; 35, 44; 36, parenthesized_expression; 36, 37; 37, boolean_operator:and; 37, 38; 37, 41; 38, comparison_operator:is; 38, 39; 38, 40; 39, identifier:start; 40, None; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:num; 43, None; 44, parenthesized_expression; 44, 45; 45, boolean_operator:and; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:num; 48, None; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:start; 51, None; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:CommandError; 56, argument_list; 56, 57; 57, string:"``start`` and ``num`` must both be specified"; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:pieces; 61, list:[key]; 61, 62; 62, identifier:key; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:by; 66, None; 67, block; 67, 68; 67, 75; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:pieces; 72, identifier:append; 73, argument_list; 73, 74; 74, string:'BY'; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:pieces; 79, identifier:append; 80, argument_list; 80, 81; 81, identifier:by; 82, if_statement; 82, 83; 82, 90; 83, boolean_operator:and; 83, 84; 83, 87; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:start; 86, None; 87, comparison_operator:is; 87, 88; 87, 89; 88, identifier:num; 89, None; 90, block; 90, 91; 90, 98; 90, 105; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:pieces; 95, identifier:append; 96, argument_list; 96, 97; 97, string:'LIMIT'; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:pieces; 102, identifier:append; 103, argument_list; 103, 104; 104, identifier:start; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:pieces; 109, identifier:append; 110, argument_list; 110, 111; 111, identifier:num; 112, if_statement; 112, 113; 112, 116; 112, 117; 112, 118; 112, 119; 112, 120; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:get; 115, None; 116, comment; 117, comment; 118, comment; 119, comment; 120, block; 120, 121; 121, if_statement; 121, 122; 121, 127; 121, 142; 122, call; 122, 123; 122, 124; 123, identifier:isinstance; 124, argument_list; 124, 125; 124, 126; 125, identifier:get; 126, identifier:str; 127, block; 127, 128; 127, 135; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:pieces; 132, identifier:append; 133, argument_list; 133, 134; 134, string:'GET'; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:pieces; 139, identifier:append; 140, argument_list; 140, 141; 141, identifier:get; 142, else_clause; 142, 143; 143, block; 143, 144; 144, for_statement; 144, 145; 144, 146; 144, 147; 145, identifier:g; 146, identifier:get; 147, block; 147, 148; 147, 155; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:pieces; 152, identifier:append; 153, argument_list; 153, 154; 154, string:'GET'; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:pieces; 159, identifier:append; 160, argument_list; 160, 161; 161, identifier:g; 162, if_statement; 162, 163; 162, 164; 163, identifier:desc; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:pieces; 169, identifier:append; 170, argument_list; 170, 171; 171, string:'DESC'; 172, if_statement; 172, 173; 172, 174; 173, identifier:alpha; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:pieces; 179, identifier:append; 180, argument_list; 180, 181; 181, string:'ALPHA'; 182, if_statement; 182, 183; 182, 186; 183, comparison_operator:is; 183, 184; 183, 185; 184, identifier:store; 185, None; 186, block; 186, 187; 186, 194; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:pieces; 191, identifier:append; 192, argument_list; 192, 193; 193, string:'STORE'; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:pieces; 198, identifier:append; 199, argument_list; 199, 200; 200, identifier:store; 201, if_statement; 201, 202; 201, 203; 202, identifier:groups; 203, block; 203, 204; 204, if_statement; 204, 205; 204, 220; 205, boolean_operator:or; 205, 206; 205, 214; 206, boolean_operator:or; 206, 207; 206, 209; 207, not_operator; 207, 208; 208, identifier:get; 209, call; 209, 210; 209, 211; 210, identifier:isinstance; 211, argument_list; 211, 212; 211, 213; 212, identifier:get; 213, identifier:str; 214, comparison_operator:<; 214, 215; 214, 219; 215, call; 215, 216; 215, 217; 216, identifier:len; 217, argument_list; 217, 218; 218, identifier:get; 219, integer:2; 220, block; 220, 221; 221, raise_statement; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:CommandError; 224, argument_list; 224, 225; 225, concatenated_string; 225, 226; 225, 227; 225, 228; 226, string:'when using "groups" the "get" argument '; 227, string:'must be specified and contain at least '; 228, string:'two keys'; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:options; 232, dictionary; 232, 233; 233, pair; 233, 234; 233, 235; 234, string:'groups'; 235, conditional_expression:if; 235, 236; 235, 240; 235, 241; 236, call; 236, 237; 236, 238; 237, identifier:len; 238, argument_list; 238, 239; 239, identifier:get; 240, identifier:groups; 241, None; 242, return_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:execute_command; 247, argument_list; 247, 248; 247, 249; 247, 251; 248, string:'SORT'; 249, list_splat; 249, 250; 250, identifier:pieces; 251, dictionary_splat; 251, 252; 252, identifier:options
def sort(self, key, start=None, num=None, by=None, get=None, desc=False, alpha=False, store=None, groups=False): '''Sort and return the list, set or sorted set at ``key``. ``start`` and ``num`` allow for paging through the sorted data ``by`` allows using an external key to weight and sort the items. Use an "*" to indicate where in the key the item value is located ``get`` allows for returning items from external keys rather than the sorted data itself. Use an "*" to indicate where int he key the item value is located ``desc`` allows for reversing the sort ``alpha`` allows for sorting lexicographically rather than numerically ``store`` allows for storing the result of the sort into the key ``store`` ``groups`` if set to True and if ``get`` contains at least two elements, sort will return a list of tuples, each containing the values fetched from the arguments to ``get``. ''' if ((start is not None and num is None) or (num is not None and start is None)): raise CommandError("``start`` and ``num`` must both be specified") pieces = [key] if by is not None: pieces.append('BY') pieces.append(by) if start is not None and num is not None: pieces.append('LIMIT') pieces.append(start) pieces.append(num) if get is not None: # If get is a string assume we want to get a single value. # Otherwise assume it's an interable and we want to get multiple # values. We can't just iterate blindly because strings are # iterable. if isinstance(get, str): pieces.append('GET') pieces.append(get) else: for g in get: pieces.append('GET') pieces.append(g) if desc: pieces.append('DESC') if alpha: pieces.append('ALPHA') if store is not None: pieces.append('STORE') pieces.append(store) if groups: if not get or isinstance(get, str) or len(get) < 2: raise CommandError('when using "groups" the "get" argument ' 'must be specified and contain at least ' 'two keys') options = {'groups': len(get) if groups else None} return self.execute_command('SORT', *pieces, **options)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_url_filemeta; 3, parameters; 3, 4; 4, identifier:url; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 5, 37; 5, 45; 5, 129; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:parsed_url; 11, call; 11, 12; 11, 13; 12, identifier:try_parse_url; 13, argument_list; 13, 14; 14, identifier:url; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:parsed_url; 18, None; 19, block; 19, 20; 20, return_statement; 20, 21; 21, None; 22, if_statement; 22, 23; 22, 31; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:parsed_url; 27, identifier:scheme; 28, identifier:startswith; 29, argument_list; 29, 30; 30, string:'ftp'; 31, block; 31, 32; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:get_ftp_filemeta; 35, argument_list; 35, 36; 36, identifier:parsed_url; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:url; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:parsed_url; 43, identifier:geturl; 44, argument_list; 45, try_statement; 45, 46; 45, 115; 45, 120; 46, block; 46, 47; 46, 65; 46, 78; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:r; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:requests; 53, identifier:get; 54, argument_list; 54, 55; 54, 56; 54, 59; 54, 62; 55, identifier:url; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:stream; 58, True; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:allow_redirects; 61, True; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:timeout; 64, integer:5; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:remote_size; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:r; 72, identifier:headers; 73, identifier:get; 74, argument_list; 74, 75; 74, 76; 75, string:'Content-Length'; 76, unary_operator:-; 76, 77; 77, integer:1; 78, return_statement; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:dict; 81, argument_list; 81, 82; 81, 85; 81, 90; 81, 95; 81, 100; 81, 103; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:url; 84, identifier:url; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:hostname; 87, attribute; 87, 88; 87, 89; 88, identifier:parsed_url; 89, identifier:hostname; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:path; 92, attribute; 92, 93; 92, 94; 93, identifier:parsed_url; 94, identifier:path; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:username; 97, attribute; 97, 98; 97, 99; 98, identifier:parsed_url; 99, identifier:username; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:remote_size; 102, identifier:remote_size; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:filename; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:os; 109, identifier:path; 110, identifier:basename; 111, argument_list; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:parsed_url; 114, identifier:path; 115, except_clause; 115, 116; 115, 117; 116, identifier:ConnectionError; 117, block; 117, 118; 118, return_statement; 118, 119; 119, None; 120, except_clause; 120, 121; 120, 126; 121, tuple; 121, 122; 121, 123; 121, 124; 121, 125; 122, identifier:InvalidURL; 123, identifier:InvalidSchema; 124, identifier:InvalidHeader; 125, identifier:MissingSchema; 126, block; 126, 127; 127, return_statement; 127, 128; 128, None; 129, return_statement; 129, 130; 130, None
def get_url_filemeta(url): """ Request HTML for the page at the URL indicated and return the url, filename, and remote size TODO: just add remote_size and basename and filename attributes to the urlparse object instead of returning a dict >>> sorted(get_url_filemeta('mozilla.com').items()) [('filename', ''), ('hostname', 'mozilla.com'), ('path', ''), ('remote_size', -1), ('url', 'http://mozilla.com'), ('username', None)] >>> sorted(get_url_filemeta('https://duckduckgo.com/about?q=nlp').items()) [('filename', 'about'), ('hostname', 'duckduckgo.com'), ('path', '/about'), ('remote_size', -1), ('url', 'https://duckduckgo.com/about?q=nlp'), ('username', None)] >>> 1000 <= int(get_url_filemeta('en.wikipedia.org')['remote_size']) <= 200000 True """ parsed_url = try_parse_url(url) if parsed_url is None: return None if parsed_url.scheme.startswith('ftp'): return get_ftp_filemeta(parsed_url) url = parsed_url.geturl() try: r = requests.get(url, stream=True, allow_redirects=True, timeout=5) remote_size = r.headers.get('Content-Length', -1) return dict(url=url, hostname=parsed_url.hostname, path=parsed_url.path, username=parsed_url.username, remote_size=remote_size, filename=os.path.basename(parsed_url.path)) except ConnectionError: return None except (InvalidURL, InvalidSchema, InvalidHeader, MissingSchema): return None return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 59; 2, function_name:offline_plotly_scatter_bubble; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 32; 3, 35; 3, 38; 3, 50; 3, 56; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:x; 7, string:'x'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:y; 10, string:'y'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:size_col; 13, string:'size'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:text_col; 16, string:'text'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:category_col; 19, string:'category'; 20, default_parameter; 20, 21; 20, 22; 21, identifier:possible_categories; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:filename; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:config; 28, dictionary; 28, 29; 29, pair; 29, 30; 29, 31; 30, string:'displaylogo'; 31, False; 32, default_parameter; 32, 33; 32, 34; 33, identifier:xscale; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:yscale; 37, string:'log'; 38, default_parameter; 38, 39; 38, 40; 39, identifier:layout; 40, dictionary; 40, 41; 40, 44; 40, 47; 41, pair; 41, 42; 41, 43; 42, string:'hovermode'; 43, string:'closest'; 44, pair; 44, 45; 44, 46; 45, string:'showlegend'; 46, False; 47, pair; 47, 48; 47, 49; 48, string:'autosize'; 49, True; 50, default_parameter; 50, 51; 50, 52; 51, identifier:marker; 52, dictionary; 52, 53; 53, pair; 53, 54; 53, 55; 54, string:'sizemode'; 55, string:'area'; 56, default_parameter; 56, 57; 56, 58; 57, identifier:min_size; 58, integer:10; 59, block; 59, 60; 59, 62; 59, 69; 59, 98; 59, 105; 59, 114; 59, 140; 59, 148; 59, 160; 59, 171; 59, 214; 59, 224; 59, 271; 59, 354; 60, expression_statement; 60, 61; 61, comment; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:config_default; 65, call; 65, 66; 65, 67; 66, identifier:dict; 67, argument_list; 67, 68; 68, identifier:DEFAULT_PLOTLY_CONFIG; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:marker_default; 72, dictionary; 72, 73; 72, 78; 72, 81; 73, pair; 73, 74; 73, 75; 74, string:'size'; 75, boolean_operator:or; 75, 76; 75, 77; 76, identifier:size_col; 77, identifier:min_size; 78, pair; 78, 79; 78, 80; 79, string:'sizemode'; 80, string:'area'; 81, pair; 81, 82; 81, 83; 82, string:'sizeref'; 83, conditional_expression:if; 83, 84; 83, 96; 83, 97; 84, call; 84, 85; 84, 86; 85, identifier:int; 86, argument_list; 86, 87; 87, binary_operator:*; 87, 88; 87, 95; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:df; 92, identifier:size_col; 93, identifier:min; 94, argument_list; 95, float:.8; 96, identifier:size_col; 97, identifier:min_size; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:marker_default; 102, identifier:update; 103, argument_list; 103, 104; 104, identifier:marker; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:size_col; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:marker_default; 111, identifier:pop; 112, argument_list; 112, 113; 113, string:'size'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:layout_default; 117, dictionary; 117, 118; 117, 129; 118, pair; 118, 119; 118, 120; 119, string:'xaxis'; 120, call; 120, 121; 120, 122; 121, identifier:XAxis; 122, argument_list; 122, 123; 122, 126; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:title; 125, identifier:x; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:type; 128, identifier:xscale; 129, pair; 129, 130; 129, 131; 130, string:'yaxis'; 131, call; 131, 132; 131, 133; 132, identifier:YAxis; 133, argument_list; 133, 134; 133, 137; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:title; 136, identifier:y; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:type; 139, identifier:yscale; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:layout_default; 144, identifier:update; 145, argument_list; 145, 146; 146, dictionary_splat; 146, 147; 147, identifier:layout; 148, if_statement; 148, 149; 148, 152; 149, comparison_operator:is; 149, 150; 149, 151; 150, identifier:config; 151, None; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:config_default; 157, identifier:update; 158, argument_list; 158, 159; 159, identifier:config; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:df; 164, identifier:columns; 165, call; 165, 166; 165, 167; 166, identifier:clean_columns; 167, argument_list; 167, 168; 168, attribute; 168, 169; 168, 170; 169, identifier:df; 170, identifier:columns; 171, if_statement; 171, 172; 171, 179; 172, boolean_operator:and; 172, 173; 172, 176; 173, comparison_operator:is; 173, 174; 173, 175; 174, identifier:possible_categories; 175, None; 176, comparison_operator:is; 176, 177; 176, 178; 177, identifier:category_col; 178, None; 179, block; 179, 180; 179, 204; 180, if_statement; 180, 181; 180, 186; 180, 193; 181, comparison_operator:in; 181, 182; 181, 183; 182, identifier:category_col; 183, attribute; 183, 184; 183, 185; 184, identifier:df; 185, identifier:columns; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:category_labels; 190, subscript; 190, 191; 190, 192; 191, identifier:df; 192, identifier:category_col; 193, else_clause; 193, 194; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:category_labels; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:np; 201, identifier:array; 202, argument_list; 202, 203; 203, identifier:category_col; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:possible_categories; 207, call; 207, 208; 207, 209; 208, identifier:list; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:set; 212, argument_list; 212, 213; 213, identifier:category_labels; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:possible_categories; 217, conditional_expression:if; 217, 218; 217, 220; 217, 223; 218, list:[None]; 218, 219; 219, None; 220, comparison_operator:is; 220, 221; 220, 222; 221, identifier:possible_categories; 222, None; 223, identifier:possible_categories; 224, if_statement; 224, 225; 224, 230; 224, 248; 225, boolean_operator:and; 225, 226; 225, 227; 226, identifier:category_col; 227, comparison_operator:in; 227, 228; 227, 229; 228, identifier:category_col; 229, identifier:df; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:masks; 234, list_comprehension; 234, 235; 234, 245; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:np; 238, identifier:array; 239, argument_list; 239, 240; 240, comparison_operator:==; 240, 241; 240, 244; 241, subscript; 241, 242; 241, 243; 242, identifier:df; 243, identifier:category_col; 244, identifier:label; 245, for_in_clause; 245, 246; 245, 247; 246, identifier:label; 247, identifier:possible_categories; 248, else_clause; 248, 249; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:masks; 253, binary_operator:*; 253, 254; 253, 267; 254, list:[np.array([True] * len(df))]; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:np; 258, identifier:array; 259, argument_list; 259, 260; 260, binary_operator:*; 260, 261; 260, 263; 261, list:[True]; 261, 262; 262, True; 263, call; 263, 264; 263, 265; 264, identifier:len; 265, argument_list; 265, 266; 266, identifier:df; 267, call; 267, 268; 267, 269; 268, identifier:len; 269, argument_list; 269, 270; 270, identifier:possible_categories; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:data; 274, dictionary; 274, 275; 274, 347; 275, pair; 275, 276; 275, 277; 276, string:'data'; 277, list_comprehension; 277, 278; 277, 338; 278, call; 278, 279; 278, 280; 279, identifier:Scatter; 280, argument_list; 280, 281; 280, 290; 280, 299; 280, 308; 280, 329; 280, 332; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:x; 283, attribute; 283, 284; 283, 289; 284, subscript; 284, 285; 284, 288; 285, subscript; 285, 286; 285, 287; 286, identifier:df; 287, identifier:x; 288, identifier:mask; 289, identifier:values; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:y; 292, attribute; 292, 293; 292, 298; 293, subscript; 293, 294; 293, 297; 294, subscript; 294, 295; 294, 296; 295, identifier:df; 296, identifier:y; 297, identifier:mask; 298, identifier:values; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:text; 301, attribute; 301, 302; 301, 307; 302, subscript; 302, 303; 302, 306; 303, subscript; 303, 304; 303, 305; 304, identifier:df; 305, identifier:text_col; 306, identifier:mask; 307, identifier:values; 308, keyword_argument; 308, 309; 308, 310; 309, identifier:marker; 310, call; 310, 311; 310, 312; 311, identifier:Marker; 312, argument_list; 312, 313; 312, 327; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:size; 315, conditional_expression:if; 315, 316; 315, 321; 315, 326; 316, subscript; 316, 317; 316, 320; 317, subscript; 317, 318; 317, 319; 318, identifier:df; 319, identifier:size_col; 320, identifier:mask; 321, comparison_operator:in; 321, 322; 321, 323; 322, identifier:size_col; 323, attribute; 323, 324; 323, 325; 324, identifier:df; 325, identifier:columns; 326, identifier:size_col; 327, dictionary_splat; 327, 328; 328, identifier:marker_default; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:mode; 331, string:'markers'; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:name; 334, call; 334, 335; 334, 336; 335, identifier:str; 336, argument_list; 336, 337; 337, identifier:category_name; 338, for_in_clause; 338, 339; 338, 342; 339, tuple_pattern; 339, 340; 339, 341; 340, identifier:category_name; 341, identifier:mask; 342, call; 342, 343; 342, 344; 343, identifier:zip; 344, argument_list; 344, 345; 344, 346; 345, identifier:possible_categories; 346, identifier:masks; 347, pair; 347, 348; 347, 349; 348, string:'layout'; 349, call; 349, 350; 349, 351; 350, identifier:Layout; 351, argument_list; 351, 352; 352, dictionary_splat; 352, 353; 353, identifier:layout_default; 354, return_statement; 354, 355; 355, call; 355, 356; 355, 357; 356, identifier:offline_plotly_data; 357, argument_list; 357, 358; 357, 359; 357, 362; 358, identifier:data; 359, keyword_argument; 359, 360; 359, 361; 360, identifier:filename; 361, identifier:filename; 362, keyword_argument; 362, 363; 362, 364; 363, identifier:config; 364, identifier:config_default
def offline_plotly_scatter_bubble(df, x='x', y='y', size_col='size', text_col='text', category_col='category', possible_categories=None, filename=None, config={'displaylogo': False}, xscale=None, yscale='log', layout={'hovermode': 'closest', 'showlegend': False, 'autosize': True}, marker={'sizemode': 'area'}, min_size=10, ): r"""Interactive scatterplot of a DataFrame with the size and color of circles linke to two columns config keys: fillFrame setBackground displaylogo sendData showLink linkText staticPlot scrollZoom plot3dPixelRatio displayModeBar showTips workspace doubleClick autosizable editable layout keys: angularaxis annotations autosize bargap bargroupgap barmode barnorm boxgap boxgroupgap boxmode calendar direction dragmode font geo height hiddenlabels hiddenlabelssrc hidesources hovermode images legend mapbox margin orientation paper_bgcolor plot_bgcolor radialaxis scene separators shapes showlegend sliders smith ternary title titlefont updatemenus width xaxis yaxis marker keys: autocolorscale blend border cauto cmax cmin color colorbar colors colorscale colorsrc colorssrc line maxdisplayed opacity opacitysrc outliercolor reversescale showscale size sizemax sizemin sizemode sizeref sizesrc symbol symbolsrc marker['sizeref'] gives the denominator of the circle scaling factor. Typically it should be about a tenth of the minimum 'size' column value >>> from nlpia.data.loaders import get_data >>> df = get_data('cities_us_wordvectors_pca2_meta').iloc[:100] >>> html = offline_plotly_scatter_bubble( ... df.sort_values('population', ascending=False)[:350].copy().sort_values('population'), ... x='x', y='y', ... size_col='population', text_col='name', category_col='timezone', ... xscale=None, yscale=None, # 'log' or None ... layout={}, marker={'sizeref': 3000}) """ config_default = dict(DEFAULT_PLOTLY_CONFIG) marker_default = { 'size': size_col or min_size, 'sizemode': 'area', 'sizeref': int(df[size_col].min() * .8) if size_col else min_size} marker_default.update(marker) size_col = marker_default.pop('size') layout_default = { 'xaxis': XAxis(title=x, type=xscale), 'yaxis': YAxis(title=y, type=yscale), } layout_default.update(**layout) if config is not None: config_default.update(config) df.columns = clean_columns(df.columns) if possible_categories is None and category_col is not None: if category_col in df.columns: category_labels = df[category_col] else: category_labels = np.array(category_col) possible_categories = list(set(category_labels)) possible_categories = [None] if possible_categories is None else possible_categories if category_col and category_col in df: masks = [np.array(df[category_col] == label) for label in possible_categories] else: masks = [np.array([True] * len(df))] * len(possible_categories) data = {'data': [ Scatter(x=df[x][mask].values, y=df[y][mask].values, text=df[text_col][mask].values, marker=Marker(size=df[size_col][mask] if size_col in df.columns else size_col, **marker_default), mode='markers', name=str(category_name)) for (category_name, mask) in zip(possible_categories, masks) ], 'layout': Layout(**layout_default) } return offline_plotly_data(data, filename=filename, config=config_default)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_acronyms; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:manuscript; 6, call; 6, 7; 6, 12; 7, attribute; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:os; 10, identifier:path; 11, identifier:expanduser; 12, argument_list; 12, 13; 13, string:'~/code/nlpia/lane/manuscript'; 14, block; 14, 15; 14, 17; 14, 21; 14, 158; 15, expression_statement; 15, 16; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:acronyms; 20, list:[]; 21, for_statement; 21, 22; 21, 25; 21, 29; 22, pattern_list; 22, 23; 22, 24; 23, identifier:f; 24, identifier:lines; 25, call; 25, 26; 25, 27; 26, identifier:get_lines; 27, argument_list; 27, 28; 28, identifier:manuscript; 29, block; 29, 30; 30, for_statement; 30, 31; 30, 32; 30, 33; 31, identifier:line; 32, identifier:lines; 33, block; 33, 34; 33, 43; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:matches; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:CRE_ACRONYM; 40, identifier:finditer; 41, argument_list; 41, 42; 42, identifier:line; 43, if_statement; 43, 44; 43, 45; 44, identifier:matches; 45, block; 45, 46; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:m; 48, identifier:matches; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 57; 50, 77; 50, 104; 50, 131; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:m; 54, identifier:group; 55, argument_list; 55, 56; 56, string:'a2'; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:acronyms; 62, identifier:append; 63, argument_list; 63, 64; 64, tuple; 64, 65; 64, 71; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:m; 68, identifier:group; 69, argument_list; 69, 70; 70, string:'a2'; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:m; 74, identifier:group; 75, argument_list; 75, 76; 76, string:'s2'; 77, elif_clause; 77, 78; 77, 84; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:m; 81, identifier:group; 82, argument_list; 82, 83; 83, string:'a3'; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:acronyms; 89, identifier:append; 90, argument_list; 90, 91; 91, tuple; 91, 92; 91, 98; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:m; 95, identifier:group; 96, argument_list; 96, 97; 97, string:'a3'; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:m; 101, identifier:group; 102, argument_list; 102, 103; 103, string:'s3'; 104, elif_clause; 104, 105; 104, 111; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:m; 108, identifier:group; 109, argument_list; 109, 110; 110, string:'a4'; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:acronyms; 116, identifier:append; 117, argument_list; 117, 118; 118, tuple; 118, 119; 118, 125; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:m; 122, identifier:group; 123, argument_list; 123, 124; 124, string:'a4'; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:m; 128, identifier:group; 129, argument_list; 129, 130; 130, string:'s4'; 131, elif_clause; 131, 132; 131, 138; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:m; 135, identifier:group; 136, argument_list; 136, 137; 137, string:'a5'; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:acronyms; 143, identifier:append; 144, argument_list; 144, 145; 145, tuple; 145, 146; 145, 152; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:m; 149, identifier:group; 150, argument_list; 150, 151; 151, string:'a5'; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:m; 155, identifier:group; 156, argument_list; 156, 157; 157, string:'s5'; 158, return_statement; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:sorted; 161, argument_list; 161, 162; 162, call; 162, 163; 162, 169; 163, attribute; 163, 164; 163, 168; 164, call; 164, 165; 164, 166; 165, identifier:dict; 166, argument_list; 166, 167; 167, identifier:acronyms; 168, identifier:items; 169, argument_list
def get_acronyms(manuscript=os.path.expanduser('~/code/nlpia/lane/manuscript')): """ Find all the 2 and 3-letter acronyms in the manuscript and return as a sorted list of tuples """ acronyms = [] for f, lines in get_lines(manuscript): for line in lines: matches = CRE_ACRONYM.finditer(line) if matches: for m in matches: if m.group('a2'): acronyms.append((m.group('a2'), m.group('s2'))) elif m.group('a3'): acronyms.append((m.group('a3'), m.group('s3'))) elif m.group('a4'): acronyms.append((m.group('a4'), m.group('s4'))) elif m.group('a5'): acronyms.append((m.group('a5'), m.group('s5'))) return sorted(dict(acronyms).items())
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_find; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:rpcmethod; 6, block; 6, 7; 6, 9; 6, 25; 6, 31; 6, 53; 6, 65; 6, 69; 6, 106; 6, 114; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:log; 13, identifier:info; 14, argument_list; 14, 15; 14, 16; 15, string:"crawling network with nearest: %s"; 16, call; 16, 17; 16, 18; 17, identifier:str; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:tuple; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:nearest; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:count; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:alpha; 31, if_statement; 31, 32; 31, 43; 32, comparison_operator:==; 32, 33; 32, 40; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:nearest; 38, identifier:get_ids; 39, argument_list; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:last_ids_crawled; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:count; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:nearest; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:last_ids_crawled; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:nearest; 63, identifier:get_ids; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:dicts; 68, dictionary; 69, for_statement; 69, 70; 69, 71; 69, 82; 70, identifier:peer; 71, subscript; 71, 72; 71, 79; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:nearest; 77, identifier:get_uncontacted; 78, argument_list; 79, slice; 79, 80; 79, 81; 80, colon; 81, identifier:count; 82, block; 82, 83; 82, 97; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 90; 85, subscript; 85, 86; 85, 87; 86, identifier:dicts; 87, attribute; 87, 88; 87, 89; 88, identifier:peer; 89, identifier:id; 90, call; 90, 91; 90, 92; 91, identifier:rpcmethod; 92, argument_list; 92, 93; 92, 94; 93, identifier:peer; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:node; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:nearest; 103, identifier:mark_contacted; 104, argument_list; 104, 105; 105, identifier:peer; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:found; 109, await; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:gather_dict; 112, argument_list; 112, 113; 113, identifier:dicts; 114, return_statement; 114, 115; 115, await; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:_nodes_found; 120, argument_list; 120, 121; 121, identifier:found
async def _find(self, rpcmethod): """ Get either a value or list of nodes. Args: rpcmethod: The protocol's callfindValue or call_find_node. The process: 1. calls find_* to current ALPHA nearest not already queried nodes, adding results to current nearest list of k nodes. 2. current nearest list needs to keep track of who has been queried already sort by nearest, keep KSIZE 3. if list is same as last time, next call should be to everyone not yet queried 4. repeat, unless nearest list has all been queried, then ur done """ log.info("crawling network with nearest: %s", str(tuple(self.nearest))) count = self.alpha if self.nearest.get_ids() == self.last_ids_crawled: count = len(self.nearest) self.last_ids_crawled = self.nearest.get_ids() dicts = {} for peer in self.nearest.get_uncontacted()[:count]: dicts[peer.id] = rpcmethod(peer, self.node) self.nearest.mark_contacted(peer) found = await gather_dict(dicts) return await self._nodes_found(found)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 21; 2, function_name:match_key; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, generic_type; 6, 7; 6, 8; 7, identifier:Tuple; 8, type_parameter; 8, 9; 8, 11; 8, 13; 8, 15; 9, type; 9, 10; 10, identifier:bool; 11, type; 11, 12; 12, identifier:bool; 13, type; 13, 14; 14, identifier:int; 15, type; 15, 16; 16, generic_type; 16, 17; 16, 18; 17, identifier:List; 18, type_parameter; 18, 19; 19, type; 19, 20; 20, identifier:WeightedPart; 21, block; 21, 22; 21, 24; 21, 36; 21, 50; 22, expression_statement; 22, 23; 23, comment; 24, if_statement; 24, 25; 24, 30; 25, comparison_operator:is; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:map; 29, None; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:RuntimeError; 34, argument_list; 34, 35; 35, string:f"{self!r} is not bound to a Map"; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:complex_rule; 39, call; 39, 40; 39, 41; 40, identifier:any; 41, generator_expression; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:weight; 44, identifier:converter; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:weight; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_weights; 50, return_statement; 50, 51; 51, tuple; 51, 52; 51, 59; 51, 60; 51, 67; 52, not_operator; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:bool; 55, argument_list; 55, 56; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:defaults; 59, identifier:complex_rule; 60, unary_operator:-; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:len; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_weights; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_weights
def match_key(self) -> Tuple[bool, bool, int, List[WeightedPart]]: """A Key to sort the rules by weight for matching. The key leads to ordering: - By first order by defaults as they are simple rules without conversions. - Then on the complexity of the rule, i.e. does it have any converted parts. This is as simple rules are quick to match or reject. - Then by the number of parts, with more complex (more parts) first. - Finally by the weights themselves. Note that weights are also sub keyed by converter first then weight second. """ if self.map is None: raise RuntimeError(f"{self!r} is not bound to a Map") complex_rule = any(weight.converter for weight in self._weights) return (not bool(self.defaults), complex_rule, -len(self._weights), self._weights)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 13; 2, function_name:build_key; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, generic_type; 6, 7; 6, 8; 7, identifier:Tuple; 8, type_parameter; 8, 9; 8, 11; 9, type; 9, 10; 10, identifier:bool; 11, type; 11, 12; 12, identifier:int; 13, block; 13, 14; 13, 16; 13, 28; 14, expression_statement; 14, 15; 15, comment; 16, if_statement; 16, 17; 16, 22; 17, comparison_operator:is; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:map; 21, None; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:RuntimeError; 26, argument_list; 26, 27; 27, string:f"{self!r} is not bound to a Map"; 28, return_statement; 28, 29; 29, tuple; 29, 30; 29, 37; 30, not_operator; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:bool; 33, argument_list; 33, 34; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:defaults; 37, unary_operator:-; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:sum; 40, generator_expression; 40, 41; 40, 42; 40, 47; 41, integer:1; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:weight; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_weights; 47, if_clause; 47, 48; 48, attribute; 48, 49; 48, 50; 49, identifier:weight; 50, identifier:converter
def build_key(self) -> Tuple[bool, int]: """A Key to sort the rules by weight for building. The key leads to ordering: - By routes with defaults first, as these must be evaulated for building before ones without. - Then the more complex routes (most converted parts). """ if self.map is None: raise RuntimeError(f"{self!r} is not bound to a Map") return (not bool(self.defaults), -sum(1 for weight in self._weights if weight.converter))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:load_ui_file; 3, parameters; 3, 4; 4, identifier:name; 5, block; 5, 6; 5, 8; 5, 16; 5, 33; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:ui; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:gtk; 14, identifier:Builder; 15, argument_list; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:ui; 20, identifier:add_from_file; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:os; 26, identifier:path; 27, identifier:join; 28, argument_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:runtime; 31, identifier:data_dir; 32, identifier:name; 33, return_statement; 33, 34; 34, identifier:ui
def load_ui_file(name): """loads interface from the glade file; sorts out the path business""" ui = gtk.Builder() ui.add_from_file(os.path.join(runtime.data_dir, name)) return ui
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__remove_category; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:id; 6, block; 6, 7; 6, 9; 6, 13; 6, 30; 6, 34; 6, 43; 6, 52; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:affected_query; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:affected_ids; 16, list_comprehension; 16, 17; 16, 20; 17, subscript; 17, 18; 17, 19; 18, identifier:res; 19, integer:0; 20, for_in_clause; 20, 21; 20, 22; 21, identifier:res; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:fetchall; 26, argument_list; 26, 27; 26, 28; 27, identifier:affected_query; 28, tuple; 28, 29; 29, identifier:id; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:update; 33, string:"update activities set category_id = -1 where category_id = ?"; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:execute; 39, argument_list; 39, 40; 39, 41; 40, identifier:update; 41, tuple; 41, 42; 42, identifier:id; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:execute; 48, argument_list; 48, 49; 48, 50; 49, string:"delete from categories where id = ?"; 50, tuple; 50, 51; 51, identifier:id; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:__remove_index; 57, argument_list; 57, 58; 58, identifier:affected_ids
def __remove_category(self, id): """move all activities to unsorted and remove category""" affected_query = """ SELECT id FROM facts WHERE activity_id in (SELECT id FROM activities where category_id=?) """ affected_ids = [res[0] for res in self.fetchall(affected_query, (id,))] update = "update activities set category_id = -1 where category_id = ?" self.execute(update, (id, )) self.execute("delete from categories where id = ?", (id, )) self.__remove_index(affected_ids)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 15; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:__dict__; 14, string:'_z_ordered_sprites'; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:sprites; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:key; 23, lambda; 23, 24; 23, 26; 24, lambda_parameters; 24, 25; 25, identifier:sprite; 26, attribute; 26, 27; 26, 28; 27, identifier:sprite; 28, identifier:z_order
def _sort(self): """sort sprites by z_order""" self.__dict__['_z_ordered_sprites'] = sorted(self.sprites, key=lambda sprite:sprite.z_order)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_mouse_cursor; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 8, 19; 8, 34; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:mouse_cursor; 13, None; 14, block; 14, 15; 15, return_statement; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:mouse_cursor; 19, elif_clause; 19, 20; 19, 27; 20, boolean_operator:and; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:interactive; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:draggable; 27, block; 27, 28; 28, return_statement; 28, 29; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:gdk; 32, identifier:CursorType; 33, identifier:FLEUR; 34, elif_clause; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:interactive; 38, block; 38, 39; 39, return_statement; 39, 40; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:gdk; 43, identifier:CursorType; 44, identifier:HAND2
def _get_mouse_cursor(self): """Determine mouse cursor. By default look for self.mouse_cursor is defined and take that. Otherwise use gdk.CursorType.FLEUR for draggable sprites and gdk.CursorType.HAND2 for interactive sprites. Defaults to scenes cursor. """ if self.mouse_cursor is not None: return self.mouse_cursor elif self.interactive and self.draggable: return gdk.CursorType.FLEUR elif self.interactive: return gdk.CursorType.HAND2
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:entries; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 33; 5, 50; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:log; 13, argument_list; 13, 14; 14, string:u"Getting entries"; 15, if_statement; 15, 16; 15, 22; 16, not_operator; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:exists; 21, argument_list; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:log_exc; 28, argument_list; 28, 29; 28, 30; 28, 31; 28, 32; 29, string:u"This container does not exist. Wrong path?"; 30, None; 31, True; 32, identifier:TypeError; 33, if_statement; 33, 34; 33, 39; 34, comparison_operator:is; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:actual_container; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:log_exc; 45, argument_list; 45, 46; 45, 47; 45, 48; 45, 49; 46, string:u"The actual container object has not been set"; 47, None; 48, True; 49, identifier:TypeError; 50, return_statement; 50, 51; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:actual_container; 55, identifier:entries
def entries(self): """ Return the sorted list of entries in this container, each represented by its full path inside the container. :rtype: list of strings (path) :raises: TypeError: if this container does not exist :raises: OSError: if an error occurred reading the given container (e.g., empty file, damaged file, etc.) """ self.log(u"Getting entries") if not self.exists(): self.log_exc(u"This container does not exist. Wrong path?", None, True, TypeError) if self.actual_container is None: self.log_exc(u"The actual container object has not been set", None, True, TypeError) return self.actual_container.entries
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 5, 28; 5, 39; 5, 46; 5, 53; 5, 134; 5, 141; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:is_guaranteed_sorted; 12, block; 12, 13; 12, 20; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:log; 18, argument_list; 18, 19; 19, string:u"Already sorted, returning"; 20, return_statement; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:log; 26, argument_list; 26, 27; 27, string:u"Sorting..."; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:__fragments; 33, call; 33, 34; 33, 35; 34, identifier:sorted; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:__fragments; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:log; 44, argument_list; 44, 45; 45, string:u"Sorting... done"; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:log; 51, argument_list; 51, 52; 52, string:u"Checking relative positions..."; 53, for_statement; 53, 54; 53, 55; 53, 64; 54, identifier:i; 55, call; 55, 56; 55, 57; 56, identifier:range; 57, argument_list; 57, 58; 58, binary_operator:-; 58, 59; 58, 63; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, identifier:self; 63, integer:1; 64, block; 64, 65; 64, 73; 64, 83; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:current_interval; 68, attribute; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:self; 71, identifier:i; 72, identifier:interval; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:next_interval; 76, attribute; 76, 77; 76, 82; 77, subscript; 77, 78; 77, 79; 78, identifier:self; 79, binary_operator:+; 79, 80; 79, 81; 80, identifier:i; 81, integer:1; 82, identifier:interval; 83, if_statement; 83, 84; 83, 94; 84, comparison_operator:not; 84, 85; 84, 91; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:current_interval; 88, identifier:relative_position_of; 89, argument_list; 89, 90; 90, identifier:next_interval; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:ALLOWED_POSITIONS; 94, block; 94, 95; 94, 102; 94, 112; 94, 124; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:log; 100, argument_list; 100, 101; 101, string:u"Found overlapping fragments:"; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:log; 107, argument_list; 107, 108; 108, list:[u" Index %d => %s", i, current_interval]; 108, 109; 108, 110; 108, 111; 109, string:u" Index %d => %s"; 110, identifier:i; 111, identifier:current_interval; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:log; 117, argument_list; 117, 118; 118, list:[u" Index %d => %s", i + 1, next_interval]; 118, 119; 118, 120; 118, 123; 119, string:u" Index %d => %s"; 120, binary_operator:+; 120, 121; 120, 122; 121, identifier:i; 122, integer:1; 123, identifier:next_interval; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:log_exc; 129, argument_list; 129, 130; 129, 131; 129, 132; 129, 133; 130, string:u"The list contains two fragments overlapping in a forbidden way"; 131, None; 132, True; 133, identifier:ValueError; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:log; 139, argument_list; 139, 140; 140, string:u"Checking relative positions... done"; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:__sorted; 146, True
def sort(self): """ Sort the fragments in the list. :raises ValueError: if there is a fragment which violates the list constraints """ if self.is_guaranteed_sorted: self.log(u"Already sorted, returning") return self.log(u"Sorting...") self.__fragments = sorted(self.__fragments) self.log(u"Sorting... done") self.log(u"Checking relative positions...") for i in range(len(self) - 1): current_interval = self[i].interval next_interval = self[i + 1].interval if current_interval.relative_position_of(next_interval) not in self.ALLOWED_POSITIONS: self.log(u"Found overlapping fragments:") self.log([u" Index %d => %s", i, current_interval]) self.log([u" Index %d => %s", i + 1, next_interval]) self.log_exc(u"The list contains two fragments overlapping in a forbidden way", None, True, ValueError) self.log(u"Checking relative positions... done") self.__sorted = True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 171; 5, 185; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:sorted; 12, block; 12, 13; 13, return_statement; 14, function_definition; 14, 15; 14, 16; 14, 18; 15, function_name:key; 16, parameters; 16, 17; 17, identifier:variant; 18, block; 18, 19; 18, 23; 18, 29; 18, 87; 18, 91; 18, 122; 18, 169; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:requested_key; 22, list:[]; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:names; 26, call; 26, 27; 26, 28; 27, identifier:set; 28, argument_list; 29, for_statement; 29, 30; 29, 33; 29, 41; 30, pattern_list; 30, 31; 30, 32; 31, identifier:i; 32, identifier:request; 33, call; 33, 34; 33, 35; 34, identifier:enumerate; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:solver; 40, identifier:request_list; 41, block; 41, 42; 42, if_statement; 42, 43; 42, 47; 43, not_operator; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:request; 46, identifier:conflict; 47, block; 47, 48; 47, 61; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:req; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:variant; 55, identifier:requires_list; 56, identifier:get; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:request; 60, identifier:name; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:req; 64, None; 65, block; 65, 66; 65, 78; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:requested_key; 70, identifier:append; 71, argument_list; 71, 72; 72, tuple; 72, 73; 72, 75; 73, unary_operator:-; 73, 74; 74, identifier:i; 75, attribute; 75, 76; 75, 77; 76, identifier:req; 77, identifier:range; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:names; 82, identifier:add; 83, argument_list; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:req; 86, identifier:name; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:additional_key; 90, list:[]; 91, for_statement; 91, 92; 91, 93; 91, 96; 92, identifier:request; 93, attribute; 93, 94; 93, 95; 94, identifier:variant; 95, identifier:requires_list; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 108; 98, boolean_operator:and; 98, 99; 98, 103; 99, not_operator; 99, 100; 100, attribute; 100, 101; 100, 102; 101, identifier:request; 102, identifier:conflict; 103, comparison_operator:not; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:request; 106, identifier:name; 107, identifier:names; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:additional_key; 113, identifier:append; 114, argument_list; 114, 115; 115, tuple; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:request; 118, identifier:range; 119, attribute; 119, 120; 119, 121; 120, identifier:request; 121, identifier:name; 122, if_statement; 122, 123; 122, 133; 122, 148; 123, parenthesized_expression; 123, 124; 124, comparison_operator:==; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 127; 126, identifier:VariantSelectMode; 127, attribute; 127, 128; 127, 129; 128, identifier:config; 129, identifier:variant_select_mode; 130, attribute; 130, 131; 130, 132; 131, identifier:VariantSelectMode; 132, identifier:version_priority; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:k; 137, tuple; 137, 138; 137, 139; 137, 144; 137, 145; 138, identifier:requested_key; 139, unary_operator:-; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:len; 142, argument_list; 142, 143; 143, identifier:additional_key; 144, identifier:additional_key; 145, attribute; 145, 146; 145, 147; 146, identifier:variant; 147, identifier:index; 148, else_clause; 148, 149; 148, 150; 149, comment; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:k; 154, tuple; 154, 155; 154, 159; 154, 160; 154, 165; 154, 166; 155, call; 155, 156; 155, 157; 156, identifier:len; 157, argument_list; 157, 158; 158, identifier:requested_key; 159, identifier:requested_key; 160, unary_operator:-; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:len; 163, argument_list; 163, 164; 164, identifier:additional_key; 165, identifier:additional_key; 166, attribute; 166, 167; 166, 168; 167, identifier:variant; 168, identifier:index; 169, return_statement; 169, 170; 170, identifier:k; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:variants; 177, identifier:sort; 178, argument_list; 178, 179; 178, 182; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:key; 181, identifier:key; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:reverse; 184, True; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:sorted; 190, True
def sort(self): """Sort variants from most correct to consume, to least. Sort rules: version_priority: - sort by highest versions of packages shared with request; - THEN least number of additional packages added to solve; - THEN highest versions of additional packages; - THEN alphabetical on name of additional packages; - THEN variant index. intersection_priority: - sort by highest number of packages shared with request; - THEN sort according to version_priority Note: In theory 'variant.index' should never factor into the sort unless two variants are identical (which shouldn't happen) - this is just here as a safety measure so that sorting is guaranteed repeatable regardless. """ if self.sorted: return def key(variant): requested_key = [] names = set() for i, request in enumerate(self.solver.request_list): if not request.conflict: req = variant.requires_list.get(request.name) if req is not None: requested_key.append((-i, req.range)) names.add(req.name) additional_key = [] for request in variant.requires_list: if not request.conflict and request.name not in names: additional_key.append((request.range, request.name)) if (VariantSelectMode[config.variant_select_mode] == VariantSelectMode.version_priority): k = (requested_key, -len(additional_key), additional_key, variant.index) else: # VariantSelectMode.intersection_priority k = (len(requested_key), requested_key, -len(additional_key), additional_key, variant.index) return k self.variants.sort(key=key, reverse=True) self.sorted = True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_versions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 81; 5, 82; 5, 104; 5, 110; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:sorted; 12, block; 12, 13; 13, return_statement; 14, for_statement; 14, 15; 14, 16; 14, 24; 15, identifier:orderer; 16, parenthesized_expression; 16, 17; 17, boolean_operator:or; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:solver; 22, identifier:package_orderers; 23, list:[]; 24, block; 24, 25; 24, 44; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:entries; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:orderer; 31, identifier:reorder; 32, argument_list; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:entries; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:key; 38, lambda; 38, 39; 38, 41; 39, lambda_parameters; 39, 40; 40, identifier:x; 41, attribute; 41, 42; 41, 43; 42, identifier:x; 43, identifier:package; 44, if_statement; 44, 45; 44, 48; 45, comparison_operator:is; 45, 46; 45, 47; 46, identifier:entries; 47, None; 48, block; 48, 49; 48, 55; 48, 61; 48, 80; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:entries; 54, identifier:entries; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:sorted; 60, True; 61, if_statement; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:pr; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:pr; 71, argument_list; 71, 72; 71, 73; 71, 76; 72, string:"sorted: %s packages: %s"; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:package_name; 76, call; 76, 77; 76, 78; 77, identifier:repr; 78, argument_list; 78, 79; 79, identifier:orderer; 80, return_statement; 81, comment; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:entries; 87, call; 87, 88; 87, 89; 88, identifier:sorted; 89, argument_list; 89, 90; 89, 93; 89, 101; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:entries; 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, attribute; 98, 99; 98, 100; 99, identifier:x; 100, identifier:version; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:reverse; 103, True; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:sorted; 109, True; 110, if_statement; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:pr; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:pr; 120, argument_list; 120, 121; 120, 122; 121, string:"sorted: %s packages: version descending"; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:package_name
def sort_versions(self): """Sort entries by version. The order is typically descending, but package order functions can change this. """ if self.sorted: return for orderer in (self.solver.package_orderers or []): entries = orderer.reorder(self.entries, key=lambda x: x.package) if entries is not None: self.entries = entries self.sorted = True if self.pr: self.pr("sorted: %s packages: %s", self.package_name, repr(orderer)) return # default ordering is version descending self.entries = sorted(self.entries, key=lambda x: x.version, reverse=True) self.sorted = True if self.pr: self.pr("sorted: %s packages: version descending", self.package_name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_reset; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:load; 6, block; 6, 7; 6, 9; 6, 20; 6, 26; 6, 32; 6, 40; 6, 48; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:values; 12, call; 12, 13; 12, 14; 13, identifier:reduce; 14, argument_list; 14, 15; 14, 16; 14, 19; 15, identifier:iadd; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_lists; 19, list:[]; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:_clear; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_load; 31, identifier:load; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_half; 37, binary_operator:>>; 37, 38; 37, 39; 38, identifier:load; 39, integer:1; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_dual; 45, binary_operator:<<; 45, 46; 45, 47; 46, identifier:load; 47, integer:1; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_update; 53, argument_list; 53, 54; 54, identifier:values
def _reset(self, load): """ Reset sorted list load. The *load* specifies the load-factor of the list. The default load factor of '1000' works well for lists from tens to tens of millions of elements. Good practice is to use a value that is the cube root of the list size. With billions of elements, the best load factor depends on your usage. It's best to leave the load factor at the default until you start benchmarking. """ values = reduce(iadd, self._lists, []) self._clear() self._load = load self._half = load >> 1 self._dual = load << 1 self._update(values)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_build_index; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 5, 45; 5, 52; 5, 59; 5, 74; 5, 92; 5, 118; 5, 139; 5, 155; 5, 161; 5, 211; 5, 223; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:row0; 11, call; 11, 12; 11, 13; 12, identifier:list; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:map; 16, argument_list; 16, 17; 16, 18; 17, identifier:len; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_lists; 21, if_statement; 21, 22; 21, 28; 22, comparison_operator:==; 22, 23; 22, 27; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:row0; 27, integer:1; 28, block; 28, 29; 28, 38; 28, 44; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 37; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_index; 35, slice; 35, 36; 36, colon; 37, identifier:row0; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_offset; 43, integer:0; 44, return_statement; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:head; 48, call; 48, 49; 48, 50; 49, identifier:iter; 50, argument_list; 50, 51; 51, identifier:row0; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:tail; 55, call; 55, 56; 55, 57; 56, identifier:iter; 57, argument_list; 57, 58; 58, identifier:head; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:row1; 62, call; 62, 63; 62, 64; 63, identifier:list; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:starmap; 67, argument_list; 67, 68; 67, 69; 68, identifier:add; 69, call; 69, 70; 69, 71; 70, identifier:zip; 71, argument_list; 71, 72; 71, 73; 72, identifier:head; 73, identifier:tail; 74, if_statement; 74, 75; 74, 81; 75, binary_operator:&; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:row0; 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:row1; 86, identifier:append; 87, argument_list; 87, 88; 88, subscript; 88, 89; 88, 90; 89, identifier:row0; 90, unary_operator:-; 90, 91; 91, integer:1; 92, if_statement; 92, 93; 92, 99; 93, comparison_operator:==; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:row1; 98, integer:1; 99, block; 99, 100; 99, 111; 99, 117; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 108; 102, subscript; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_index; 106, slice; 106, 107; 107, colon; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:row1; 110, identifier:row0; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:_offset; 116, integer:1; 117, return_statement; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:size; 121, binary_operator:**; 121, 122; 121, 123; 122, integer:2; 123, parenthesized_expression; 123, 124; 124, binary_operator:+; 124, 125; 124, 138; 125, call; 125, 126; 125, 127; 126, identifier:int; 127, argument_list; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:log_e; 130, argument_list; 130, 131; 130, 137; 131, binary_operator:-; 131, 132; 131, 136; 132, call; 132, 133; 132, 134; 133, identifier:len; 134, argument_list; 134, 135; 135, identifier:row1; 136, integer:1; 137, integer:2; 138, integer:1; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:row1; 143, identifier:extend; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:repeat; 147, argument_list; 147, 148; 147, 149; 148, integer:0; 149, binary_operator:-; 149, 150; 149, 151; 150, identifier:size; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:row1; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:tree; 158, list:[row0, row1]; 158, 159; 158, 160; 159, identifier:row0; 160, identifier:row1; 161, while_statement; 161, 162; 161, 171; 162, comparison_operator:>; 162, 163; 162, 170; 163, call; 163, 164; 163, 165; 164, identifier:len; 165, argument_list; 165, 166; 166, subscript; 166, 167; 166, 168; 167, identifier:tree; 168, unary_operator:-; 168, 169; 169, integer:1; 170, integer:1; 171, block; 171, 172; 171, 182; 171, 189; 171, 204; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:head; 175, call; 175, 176; 175, 177; 176, identifier:iter; 177, argument_list; 177, 178; 178, subscript; 178, 179; 178, 180; 179, identifier:tree; 180, unary_operator:-; 180, 181; 181, integer:1; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:tail; 185, call; 185, 186; 185, 187; 186, identifier:iter; 187, argument_list; 187, 188; 188, identifier:head; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:row; 192, call; 192, 193; 192, 194; 193, identifier:list; 194, argument_list; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:starmap; 197, argument_list; 197, 198; 197, 199; 198, identifier:add; 199, call; 199, 200; 199, 201; 200, identifier:zip; 201, argument_list; 201, 202; 201, 203; 202, identifier:head; 203, identifier:tail; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:tree; 208, identifier:append; 209, argument_list; 209, 210; 210, identifier:row; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:reduce; 214, argument_list; 214, 215; 214, 216; 214, 220; 215, identifier:iadd; 216, call; 216, 217; 216, 218; 217, identifier:reversed; 218, argument_list; 218, 219; 219, identifier:tree; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:_index; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:_offset; 228, binary_operator:-; 228, 229; 228, 232; 229, binary_operator:*; 229, 230; 229, 231; 230, identifier:size; 231, integer:2; 232, integer:1
def _build_index(self): """Build an index for indexing the sorted list. Indexes are represented as binary trees in a dense array notation similar to a binary heap. For example, given a _lists representation storing integers: [0]: 1 2 3 [1]: 4 5 [2]: 6 7 8 9 [3]: 10 11 12 13 14 The first transformation maps the sub-lists by their length. The first row of the index is the length of the sub-lists. [0]: 3 2 4 5 Each row after that is the sum of consecutive pairs of the previous row: [1]: 5 9 [2]: 14 Finally, the index is built by concatenating these lists together: _index = 14 5 9 3 2 4 5 An offset storing the start of the first row is also stored: _offset = 3 When built, the index can be used for efficient indexing into the list. See the comment and notes on self._pos for details. """ row0 = list(map(len, self._lists)) if len(row0) == 1: self._index[:] = row0 self._offset = 0 return head = iter(row0) tail = iter(head) row1 = list(starmap(add, zip(head, tail))) if len(row0) & 1: row1.append(row0[-1]) if len(row1) == 1: self._index[:] = row1 + row0 self._offset = 1 return size = 2 ** (int(log_e(len(row1) - 1, 2)) + 1) row1.extend(repeat(0, size - len(row1))) tree = [row0, row1] while len(tree[-1]) > 1: head = iter(tree[-1]) tail = iter(head) row = list(starmap(add, zip(head, tail))) tree.append(row) reduce(iadd, reversed(tree), self._index) self._offset = size * 2 - 1
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_fromset; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:values; 6, default_parameter; 6, 7; 6, 8; 7, identifier:key; 8, None; 9, block; 9, 10; 9, 12; 9, 21; 9, 27; 9, 28; 9, 37; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:sorted_set; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:object; 18, identifier:__new__; 19, argument_list; 19, 20; 20, identifier:cls; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:sorted_set; 25, identifier:_set; 26, identifier:values; 27, comment; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:sorted_set; 32, identifier:__init__; 33, argument_list; 33, 34; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:key; 36, identifier:key; 37, return_statement; 37, 38; 38, identifier:sorted_set
def _fromset(cls, values, key=None): """Initialize sorted set from existing set.""" sorted_set = object.__new__(cls) sorted_set._set = values # pylint: disable=protected-access sorted_set.__init__(key=key) return sorted_set
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_argsort_and_resolve_ties; 3, parameters; 3, 4; 3, 5; 4, identifier:time; 5, identifier:random_state; 6, block; 6, 7; 6, 9; 6, 16; 6, 28; 6, 32; 6, 90; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:n_samples; 12, call; 12, 13; 12, 14; 13, identifier:len; 14, argument_list; 14, 15; 15, identifier:time; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:order; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:numpy; 22, identifier:argsort; 23, argument_list; 23, 24; 23, 25; 24, identifier:time; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:kind; 27, string:"mergesort"; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:i; 31, integer:0; 32, while_statement; 32, 33; 32, 38; 33, comparison_operator:<; 33, 34; 33, 35; 34, identifier:i; 35, binary_operator:-; 35, 36; 35, 37; 36, identifier:n_samples; 37, integer:1; 38, block; 38, 39; 38, 45; 38, 66; 38, 86; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:inext; 42, binary_operator:+; 42, 43; 42, 44; 43, identifier:i; 44, integer:1; 45, while_statement; 45, 46; 45, 61; 46, boolean_operator:and; 46, 47; 46, 50; 47, comparison_operator:<; 47, 48; 47, 49; 48, identifier:inext; 49, identifier:n_samples; 50, comparison_operator:==; 50, 51; 50, 56; 51, subscript; 51, 52; 51, 53; 52, identifier:time; 53, subscript; 53, 54; 53, 55; 54, identifier:order; 55, identifier:i; 56, subscript; 56, 57; 56, 58; 57, identifier:time; 58, subscript; 58, 59; 58, 60; 59, identifier:order; 60, identifier:inext; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, augmented_assignment:+=; 63, 64; 63, 65; 64, identifier:inext; 65, integer:1; 66, if_statement; 66, 67; 66, 72; 66, 73; 67, comparison_operator:!=; 67, 68; 67, 71; 68, binary_operator:+; 68, 69; 68, 70; 69, identifier:i; 70, integer:1; 71, identifier:inext; 72, comment; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:random_state; 78, identifier:shuffle; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:order; 82, slice; 82, 83; 82, 84; 82, 85; 83, identifier:i; 84, colon; 85, identifier:inext; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:i; 89, identifier:inext; 90, return_statement; 90, 91; 91, identifier:order
def _argsort_and_resolve_ties(time, random_state): """Like numpy.argsort, but resolves ties uniformly at random""" n_samples = len(time) order = numpy.argsort(time, kind="mergesort") i = 0 while i < n_samples - 1: inext = i + 1 while inext < n_samples and time[order[i]] == time[order[inext]]: inext += 1 if i + 1 != inext: # resolve ties randomly random_state.shuffle(order[i:inext]) i = inext return order
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:toposort_classes; 3, parameters; 3, 4; 4, identifier:classes; 5, block; 5, 6; 5, 8; 5, 141; 5, 142; 5, 154; 5, 160; 5, 164; 5, 187; 6, expression_statement; 6, 7; 7, comment; 8, function_definition; 8, 9; 8, 10; 8, 15; 9, function_name:get_class_topolist; 10, parameters; 10, 11; 10, 12; 10, 13; 10, 14; 11, identifier:class_name; 12, identifier:name_to_class; 13, identifier:processed_classes; 14, identifier:current_trace; 15, block; 15, 16; 15, 18; 15, 19; 15, 26; 15, 41; 15, 47; 15, 48; 15, 49; 15, 56; 15, 57; 15, 68; 15, 86; 15, 90; 15, 91; 15, 98; 15, 115; 15, 122; 15, 123; 15, 132; 15, 139; 16, expression_statement; 16, 17; 17, comment; 18, comment; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:in; 20, 21; 20, 22; 21, identifier:class_name; 22, identifier:processed_classes; 23, block; 23, 24; 24, return_statement; 24, 25; 25, list:[]; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:class_name; 29, identifier:current_trace; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:AssertionError; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:'Encountered self-reference in dependency chain of {}'; 38, identifier:format; 39, argument_list; 39, 40; 40, identifier:class_name; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:cls; 44, subscript; 44, 45; 44, 46; 45, identifier:name_to_class; 46, identifier:class_name; 47, comment; 48, comment; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:dependencies; 52, call; 52, 53; 52, 54; 53, identifier:_list_superclasses; 54, argument_list; 54, 55; 55, identifier:cls; 56, comment; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:properties; 60, conditional_expression:if; 60, 61; 60, 64; 60, 67; 61, subscript; 61, 62; 61, 63; 62, identifier:cls; 63, string:'properties'; 64, comparison_operator:in; 64, 65; 64, 66; 65, string:'properties'; 66, identifier:cls; 67, list:[]; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:prop; 70, identifier:properties; 71, block; 71, 72; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:in; 73, 74; 73, 75; 74, string:'linkedClass'; 75, identifier:prop; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:dependencies; 81, identifier:append; 82, argument_list; 82, 83; 83, subscript; 83, 84; 83, 85; 84, identifier:prop; 85, string:'linkedClass'; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:class_list; 89, list:[]; 90, comment; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:current_trace; 95, identifier:add; 96, argument_list; 96, 97; 97, identifier:class_name; 98, for_statement; 98, 99; 98, 100; 98, 101; 99, identifier:dependency; 100, identifier:dependencies; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:class_list; 106, identifier:extend; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:get_class_topolist; 110, argument_list; 110, 111; 110, 112; 110, 113; 110, 114; 111, identifier:dependency; 112, identifier:name_to_class; 113, identifier:processed_classes; 114, identifier:current_trace; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:current_trace; 119, identifier:remove; 120, argument_list; 120, 121; 121, identifier:class_name; 122, comment; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:class_list; 127, identifier:append; 128, argument_list; 128, 129; 129, subscript; 129, 130; 129, 131; 130, identifier:name_to_class; 131, identifier:class_name; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:processed_classes; 136, identifier:add; 137, argument_list; 137, 138; 138, identifier:class_name; 139, return_statement; 139, 140; 140, identifier:class_list; 141, comment; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:class_map; 145, dictionary_comprehension; 145, 146; 145, 151; 146, pair; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:c; 149, string:'name'; 150, identifier:c; 151, for_in_clause; 151, 152; 151, 153; 152, identifier:c; 153, identifier:classes; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:seen_classes; 157, call; 157, 158; 157, 159; 158, identifier:set; 159, argument_list; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:toposorted; 163, list:[]; 164, for_statement; 164, 165; 164, 166; 164, 171; 165, identifier:name; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:class_map; 169, identifier:keys; 170, argument_list; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:toposorted; 176, identifier:extend; 177, argument_list; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:get_class_topolist; 180, argument_list; 180, 181; 180, 182; 180, 183; 180, 184; 181, identifier:name; 182, identifier:class_map; 183, identifier:seen_classes; 184, call; 184, 185; 184, 186; 185, identifier:set; 186, argument_list; 187, return_statement; 187, 188; 188, identifier:toposorted
def toposort_classes(classes): """Sort class metadatas so that a superclass is always before the subclass""" def get_class_topolist(class_name, name_to_class, processed_classes, current_trace): """Return a topologically sorted list of this class's dependencies and class itself Args: class_name: string, name of the class to process name_to_class: dict, class_name -> descriptor processed_classes: set of strings, a set of classes that have already been processed current_trace: list of strings, list of classes traversed during the recursion Returns: list of dicts, list of classes sorted in topological order """ # Check if this class has already been handled if class_name in processed_classes: return [] if class_name in current_trace: raise AssertionError( 'Encountered self-reference in dependency chain of {}'.format(class_name)) cls = name_to_class[class_name] # Collect the dependency classes # These are bases and classes from linked properties dependencies = _list_superclasses(cls) # Recursively process linked edges properties = cls['properties'] if 'properties' in cls else [] for prop in properties: if 'linkedClass' in prop: dependencies.append(prop['linkedClass']) class_list = [] # Recursively process superclasses current_trace.add(class_name) for dependency in dependencies: class_list.extend(get_class_topolist( dependency, name_to_class, processed_classes, current_trace)) current_trace.remove(class_name) # Do the bookkeeping class_list.append(name_to_class[class_name]) processed_classes.add(class_name) return class_list # Map names to classes class_map = {c['name']: c for c in classes} seen_classes = set() toposorted = [] for name in class_map.keys(): toposorted.extend(get_class_topolist(name, class_map, seen_classes, set())) return toposorted
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_init_steps; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 22; 5, 29; 5, 33; 5, 60; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_check_old_yaml_format; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:config_steps; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:flow_config; 21, identifier:steps; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_check_infinite_flows; 27, argument_list; 27, 28; 28, identifier:config_steps; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:steps; 32, list:[]; 33, for_statement; 33, 34; 33, 37; 33, 42; 34, pattern_list; 34, 35; 34, 36; 35, identifier:number; 36, identifier:step_config; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:config_steps; 40, identifier:items; 41, argument_list; 42, block; 42, 43; 42, 53; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:specs; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_visit_step; 50, argument_list; 50, 51; 50, 52; 51, identifier:number; 52, identifier:step_config; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:steps; 57, identifier:extend; 58, argument_list; 58, 59; 59, identifier:specs; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:sorted; 63, argument_list; 63, 64; 63, 65; 64, identifier:steps; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:key; 67, call; 67, 68; 67, 69; 68, identifier:attrgetter; 69, argument_list; 69, 70; 70, string:"step_num"
def _init_steps(self,): """ Given the flow config and everything else, create a list of steps to run, sorted by step number. :return: List[StepSpec] """ self._check_old_yaml_format() config_steps = self.flow_config.steps self._check_infinite_flows(config_steps) steps = [] for number, step_config in config_steps.items(): specs = self._visit_step(number, step_config) steps.extend(specs) return sorted(steps, key=attrgetter("step_num"))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:ranker; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:X; 6, identifier:meta; 7, block; 7, 8; 7, 10; 7, 11; 7, 26; 7, 40; 7, 41; 7, 49; 7, 59; 7, 60; 7, 70; 7, 76; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:total_score; 14, call; 14, 15; 14, 25; 15, attribute; 15, 16; 15, 24; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:X; 19, identifier:sum; 20, argument_list; 20, 21; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:axis; 23, integer:1; 24, identifier:transpose; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:total_score; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:np; 32, identifier:squeeze; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:np; 37, identifier:asarray; 38, argument_list; 38, 39; 39, identifier:total_score; 40, comment; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:ranks; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:total_score; 47, identifier:argsort; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:ranks; 52, subscript; 52, 53; 52, 54; 53, identifier:ranks; 54, slice; 54, 55; 54, 56; 54, 57; 55, colon; 56, colon; 57, unary_operator:-; 57, 58; 58, integer:1; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:sorted_meta; 63, list_comprehension; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:meta; 66, identifier:r; 67, for_in_clause; 67, 68; 67, 69; 68, identifier:r; 69, identifier:ranks; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:sorted_X; 73, subscript; 73, 74; 73, 75; 74, identifier:X; 75, identifier:ranks; 76, return_statement; 76, 77; 77, tuple; 77, 78; 77, 79; 78, identifier:sorted_X; 79, identifier:sorted_meta
def ranker(self, X, meta): """ Sort the place features list by the score of its relevance. """ # total score is just a sum of each row total_score = X.sum(axis=1).transpose() total_score = np.squeeze(np.asarray(total_score)) # matrix to array ranks = total_score.argsort() ranks = ranks[::-1] # sort the list of dicts according to ranks sorted_meta = [meta[r] for r in ranks] sorted_X = X[ranks] return (sorted_X, sorted_meta)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:create_pickled_data; 3, parameters; 3, 4; 3, 5; 4, identifier:idevice; 5, identifier:filename; 6, block; 6, 7; 6, 9; 6, 13; 6, 29; 6, 33; 6, 41; 6, 54; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:data; 12, dictionary; 13, for_statement; 13, 14; 13, 15; 13, 18; 14, identifier:x; 15, attribute; 15, 16; 15, 17; 16, identifier:idevice; 17, identifier:content; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:data; 23, identifier:x; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:idevice; 27, identifier:content; 28, identifier:x; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:location; 32, identifier:filename; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:pickle_file; 36, call; 36, 37; 36, 38; 37, identifier:open; 38, argument_list; 38, 39; 38, 40; 39, identifier:location; 40, string:'wb'; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:pickle; 45, identifier:dump; 46, argument_list; 46, 47; 46, 48; 46, 49; 47, identifier:data; 48, identifier:pickle_file; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:protocol; 51, attribute; 51, 52; 51, 53; 52, identifier:pickle; 53, identifier:HIGHEST_PROTOCOL; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:pickle_file; 58, identifier:close; 59, argument_list
def create_pickled_data(idevice, filename): """This helper will output the idevice to a pickled file named after the passed filename. This allows the data to be used without resorting to screen / pipe scrapping. """ data = {} for x in idevice.content: data[x] = idevice.content[x] location = filename pickle_file = open(location, 'wb') pickle.dump(data, pickle_file, protocol=pickle.HIGHEST_PROTOCOL) pickle_file.close()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_html_string; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 19; 7, 44; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:options; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_get_options; 17, argument_list; 17, 18; 18, identifier:kwargs; 19, if_statement; 19, 20; 19, 23; 19, 33; 20, subscript; 20, 21; 20, 22; 21, identifier:options; 22, string:"format"; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:string; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_get_formatted_html_string; 31, argument_list; 31, 32; 32, identifier:options; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:string; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_get_simple_html_string; 42, argument_list; 42, 43; 43, identifier:options; 44, return_statement; 44, 45; 45, identifier:string
def get_html_string(self, **kwargs): """Return string representation of HTML formatted version of table in current state. Arguments: start - index of first data row to include in output end - index of last data row to include in output PLUS ONE (list slice style) fields - names of fields (columns) to include header - print a header showing field names (True or False) border - print a border around the table (True or False) hrules - controls printing of horizontal rules after rows. Allowed values: ALL, FRAME, HEADER, NONE vrules - controls printing of vertical rules between columns. Allowed values: FRAME, ALL, NONE int_format - controls formatting of integer data float_format - controls formatting of floating point data padding_width - number of spaces on either side of column data (only used if left and right paddings are None) left_padding_width - number of spaces on left hand side of column data right_padding_width - number of spaces on right hand side of column data sortby - name of field to sort rows by sort_key - sorting key function, applied to data points before sorting attributes - dictionary of name/value pairs to include as HTML attributes in the <table> tag xhtml - print <br/> tags if True, <br> tags if false""" options = self._get_options(kwargs) if options["format"]: string = self._get_formatted_html_string(options) else: string = self._get_simple_html_string(options) return string
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_last_update_time; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 28; 6, expression_statement; 6, 7; 7, string:''' Gets the time at which each ledger was updated. Can be called at any time to get this information. :return: an ordered dict of outdated ledgers sorted by last update time (from old to new) and then by ledger ID (in case of equal update time) '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:last_updated; 11, dictionary_comprehension; 11, 12; 11, 17; 12, pair; 12, 13; 12, 14; 13, identifier:ledger_id; 14, attribute; 14, 15; 14, 16; 15, identifier:freshness_state; 16, identifier:last_updated; 17, for_in_clause; 17, 18; 17, 21; 18, pattern_list; 18, 19; 18, 20; 19, identifier:ledger_id; 20, identifier:freshness_state; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_ledger_freshness; 26, identifier:items; 27, argument_list; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:OrderedDict; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:sorted; 34, argument_list; 34, 35; 34, 40; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:last_updated; 38, identifier:items; 39, argument_list; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:key; 42, lambda; 42, 43; 42, 45; 43, lambda_parameters; 43, 44; 44, identifier:item; 45, tuple; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:item; 48, integer:1; 49, subscript; 49, 50; 49, 51; 50, identifier:item; 51, integer:0
def get_last_update_time(self): ''' Gets the time at which each ledger was updated. Can be called at any time to get this information. :return: an ordered dict of outdated ledgers sorted by last update time (from old to new) and then by ledger ID (in case of equal update time) ''' last_updated = {ledger_id: freshness_state.last_updated for ledger_id, freshness_state in self._ledger_freshness.items()} return OrderedDict( sorted( last_updated.items(), key=lambda item: (item[1], item[0]) ) )
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_listChunks; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 12; 5, 44; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:chunks; 11, list:[]; 12, for_statement; 12, 13; 12, 14; 12, 22; 13, identifier:fileName; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:os; 17, identifier:listdir; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:dataDir; 22, block; 22, 23; 22, 32; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:index; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:ChunkedFileStore; 29, identifier:_fileNameToChunkIndex; 30, argument_list; 30, 31; 31, identifier:fileName; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:index; 35, None; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:chunks; 41, identifier:append; 42, argument_list; 42, 43; 43, identifier:index; 44, return_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:sorted; 47, argument_list; 47, 48; 48, identifier:chunks
def _listChunks(self): """ Lists stored chunks :return: sorted list of available chunk indices """ chunks = [] for fileName in os.listdir(self.dataDir): index = ChunkedFileStore._fileNameToChunkIndex(fileName) if index is not None: chunks.append(index) return sorted(chunks)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:mostCommonElement; 3, parameters; 3, 4; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:elements; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Iterable; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:T; 12, typed_default_parameter; 12, 13; 12, 14; 12, 16; 13, identifier:to_hashable_f; 14, type; 14, 15; 15, identifier:Callable; 16, None; 17, block; 17, 18; 17, 20; 17, 112; 17, 123; 17, 141; 18, expression_statement; 18, 19; 19, comment; 20, class_definition; 20, 21; 20, 22; 20, 28; 21, identifier:_Hashable; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:collections; 26, identifier:abc; 27, identifier:Hashable; 28, block; 28, 29; 28, 86; 28, 100; 29, function_definition; 29, 30; 29, 31; 29, 34; 30, function_name:__init__; 31, parameters; 31, 32; 31, 33; 32, identifier:self; 33, identifier:orig; 34, block; 34, 35; 34, 41; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:orig; 40, identifier:orig; 41, if_statement; 41, 42; 41, 49; 41, 56; 41, 70; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:orig; 46, attribute; 46, 47; 46, 48; 47, identifier:collections; 48, identifier:Hashable; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:hashable; 55, identifier:orig; 56, elif_clause; 56, 57; 56, 60; 57, comparison_operator:is; 57, 58; 57, 59; 58, identifier:to_hashable_f; 59, None; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:hashable; 66, call; 66, 67; 66, 68; 67, identifier:to_hashable_f; 68, argument_list; 68, 69; 69, identifier:orig; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:hashable; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:json; 80, identifier:dumps; 81, argument_list; 81, 82; 81, 83; 82, identifier:orig; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:sort_keys; 85, True; 86, function_definition; 86, 87; 86, 88; 86, 91; 87, function_name:__eq__; 88, parameters; 88, 89; 88, 90; 89, identifier:self; 90, identifier:other; 91, block; 91, 92; 92, return_statement; 92, 93; 93, comparison_operator:==; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:hashable; 97, attribute; 97, 98; 97, 99; 98, identifier:other; 99, identifier:hashable; 100, function_definition; 100, 101; 100, 102; 100, 104; 101, function_name:__hash__; 102, parameters; 102, 103; 103, identifier:self; 104, block; 104, 105; 105, return_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:hash; 108, argument_list; 108, 109; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:hashable; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:_elements; 115, generator_expression; 115, 116; 115, 120; 116, call; 116, 117; 116, 118; 117, identifier:_Hashable; 118, argument_list; 118, 119; 119, identifier:el; 120, for_in_clause; 120, 121; 120, 122; 121, identifier:el; 122, identifier:elements; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, pattern_list; 125, 126; 125, 127; 126, identifier:most_common; 127, identifier:counter; 128, subscript; 128, 129; 128, 140; 129, call; 129, 130; 129, 136; 130, attribute; 130, 131; 130, 135; 131, call; 131, 132; 131, 133; 132, identifier:Counter; 133, argument_list; 133, 134; 134, identifier:_elements; 135, identifier:most_common; 136, argument_list; 136, 137; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:n; 139, integer:1; 140, integer:0; 141, return_statement; 141, 142; 142, expression_list; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:most_common; 145, identifier:orig; 146, identifier:counter
def mostCommonElement(elements: Iterable[T], to_hashable_f: Callable=None): """ Find the most frequent element of a collection. :param elements: An iterable of elements :param to_hashable_f: (optional) if defined will be used to get hashable presentation for non-hashable elements. Otherwise json.dumps is used with sort_keys=True :return: element which is the most frequent in the collection and the number of its occurrences """ class _Hashable(collections.abc.Hashable): def __init__(self, orig): self.orig = orig if isinstance(orig, collections.Hashable): self.hashable = orig elif to_hashable_f is not None: self.hashable = to_hashable_f(orig) else: self.hashable = json.dumps(orig, sort_keys=True) def __eq__(self, other): return self.hashable == other.hashable def __hash__(self): return hash(self.hashable) _elements = (_Hashable(el) for el in elements) most_common, counter = Counter(_elements).most_common(n=1)[0] return most_common.orig, counter
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:minute_index_to_session_labels; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:index; 6, block; 6, 7; 6, 9; 6, 20; 6, 21; 6, 22; 6, 43; 6, 62; 6, 63; 6, 70; 6, 162; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:index; 13, identifier:is_monotonic_increasing; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:ValueError; 18, argument_list; 18, 19; 19, string:"Non-ordered index passed to minute_index_to_session_labels."; 20, comment; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:prev_opens; 25, parenthesized_expression; 25, 26; 26, binary_operator:-; 26, 27; 26, 42; 27, call; 27, 28; 27, 35; 28, attribute; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_opens; 33, identifier:values; 34, identifier:searchsorted; 35, argument_list; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:index; 38, identifier:values; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:side; 41, string:'right'; 42, integer:1; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:next_closes; 46, parenthesized_expression; 46, 47; 47, call; 47, 48; 47, 55; 48, attribute; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_closes; 53, identifier:values; 54, identifier:searchsorted; 55, argument_list; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:index; 58, identifier:values; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:side; 61, string:'left'; 62, comment; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:mismatches; 66, parenthesized_expression; 66, 67; 67, comparison_operator:!=; 67, 68; 67, 69; 68, identifier:prev_opens; 69, identifier:next_closes; 70, if_statement; 70, 71; 70, 76; 70, 77; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:mismatches; 74, identifier:any; 75, argument_list; 76, comment; 77, block; 77, 78; 77, 89; 77, 95; 77, 101; 77, 113; 77, 127; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:bad_ix; 81, subscript; 81, 82; 81, 88; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:np; 85, identifier:flatnonzero; 86, argument_list; 86, 87; 87, identifier:mismatches; 88, integer:0; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:example; 92, subscript; 92, 93; 92, 94; 93, identifier:index; 94, identifier:bad_ix; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:prev_day; 98, subscript; 98, 99; 98, 100; 99, identifier:prev_opens; 100, identifier:bad_ix; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, pattern_list; 103, 104; 103, 105; 104, identifier:prev_open; 105, identifier:prev_close; 106, subscript; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:schedule; 111, identifier:iloc; 112, identifier:prev_day; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, pattern_list; 115, 116; 115, 117; 116, identifier:next_open; 117, identifier:next_close; 118, subscript; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:schedule; 123, identifier:iloc; 124, binary_operator:+; 124, 125; 124, 126; 125, identifier:prev_day; 126, integer:1; 127, raise_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:ValueError; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 139; 132, attribute; 132, 133; 132, 138; 133, concatenated_string; 133, 134; 133, 135; 133, 136; 133, 137; 134, string:"{num} non-market minutes in minute_index_to_session_labels:\n"; 135, string:"First Bad Minute: {first_bad}\n"; 136, string:"Previous Session: {prev_open} -> {prev_close}\n"; 137, string:"Next Session: {next_open} -> {next_close}"; 138, identifier:format; 139, argument_list; 139, 140; 139, 147; 139, 150; 139, 153; 139, 156; 139, 159; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:num; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:mismatches; 145, identifier:sum; 146, argument_list; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:first_bad; 149, identifier:example; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:prev_open; 152, identifier:prev_open; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:prev_close; 155, identifier:prev_close; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:next_open; 158, identifier:next_open; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:next_close; 161, identifier:next_close; 162, return_statement; 162, 163; 163, subscript; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:schedule; 168, identifier:index; 169, identifier:prev_opens
def minute_index_to_session_labels(self, index): """ Given a sorted DatetimeIndex of market minutes, return a DatetimeIndex of the corresponding session labels. Parameters ---------- index: pd.DatetimeIndex or pd.Series The ordered list of market minutes we want session labels for. Returns ------- pd.DatetimeIndex (UTC) The list of session labels corresponding to the given minutes. """ if not index.is_monotonic_increasing: raise ValueError( "Non-ordered index passed to minute_index_to_session_labels." ) # Find the indices of the previous open and the next close for each # minute. prev_opens = ( self._opens.values.searchsorted(index.values, side='right') - 1 ) next_closes = ( self._closes.values.searchsorted(index.values, side='left') ) # If they don't match, the minute is outside the trading day. Barf. mismatches = (prev_opens != next_closes) if mismatches.any(): # Show the first bad minute in the error message. bad_ix = np.flatnonzero(mismatches)[0] example = index[bad_ix] prev_day = prev_opens[bad_ix] prev_open, prev_close = self.schedule.iloc[prev_day] next_open, next_close = self.schedule.iloc[prev_day + 1] raise ValueError( "{num} non-market minutes in minute_index_to_session_labels:\n" "First Bad Minute: {first_bad}\n" "Previous Session: {prev_open} -> {prev_close}\n" "Next Session: {next_open} -> {next_close}" .format( num=mismatches.sum(), first_bad=example, prev_open=prev_open, prev_close=prev_close, next_open=next_open, next_close=next_close) ) return self.schedule.index[prev_opens]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:aggregate_repeated_calls; 3, parameters; 3, 4; 3, 5; 4, identifier:frame; 5, identifier:options; 6, block; 6, 7; 6, 9; 6, 16; 6, 20; 6, 21; 6, 83; 6, 84; 6, 98; 6, 99; 6, 100; 6, 101; 6, 118; 6, 119; 7, expression_statement; 7, 8; 8, string:''' Converts a timeline into a time-aggregate summary. Adds together calls along the same call stack, so that repeated calls appear as the same frame. Removes time-linearity - frames are sorted according to total time spent. Useful for outputs that display a summary of execution (e.g. text and html outputs) '''; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:frame; 12, None; 13, block; 13, 14; 14, return_statement; 14, 15; 15, None; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:children_by_identifier; 19, dictionary; 20, comment; 21, for_statement; 21, 22; 21, 23; 21, 26; 22, identifier:child; 23, attribute; 23, 24; 23, 25; 24, identifier:frame; 25, identifier:children; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 33; 27, 72; 28, comparison_operator:in; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:child; 31, identifier:identifier; 32, identifier:children_by_identifier; 33, block; 33, 34; 33, 42; 33, 43; 33, 51; 33, 65; 33, 66; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:aggregate_frame; 37, subscript; 37, 38; 37, 39; 38, identifier:children_by_identifier; 39, attribute; 39, 40; 39, 41; 40, identifier:child; 41, identifier:identifier; 42, comment; 43, expression_statement; 43, 44; 44, augmented_assignment:+=; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:aggregate_frame; 47, identifier:self_time; 48, attribute; 48, 49; 48, 50; 49, identifier:child; 50, identifier:self_time; 51, if_statement; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:child; 54, identifier:children; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:aggregate_frame; 60, identifier:add_children; 61, argument_list; 61, 62; 62, attribute; 62, 63; 62, 64; 63, identifier:child; 64, identifier:children; 65, comment; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:child; 70, identifier:remove_from_parent; 71, argument_list; 72, else_clause; 72, 73; 72, 74; 73, comment; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 82; 77, subscript; 77, 78; 77, 79; 78, identifier:children_by_identifier; 79, attribute; 79, 80; 79, 81; 80, identifier:child; 81, identifier:identifier; 82, identifier:child; 83, comment; 84, for_statement; 84, 85; 84, 86; 84, 89; 85, identifier:child; 86, attribute; 86, 87; 86, 88; 87, identifier:frame; 88, identifier:children; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:aggregate_repeated_calls; 93, argument_list; 93, 94; 93, 95; 94, identifier:child; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:options; 97, identifier:options; 98, comment; 99, comment; 100, comment; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:frame; 106, identifier:_children; 107, identifier:sort; 108, argument_list; 108, 109; 108, 115; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:key; 111, call; 111, 112; 111, 113; 112, identifier:methodcaller; 113, argument_list; 113, 114; 114, string:'time'; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:reverse; 117, True; 118, comment; 119, return_statement; 119, 120; 120, identifier:frame
def aggregate_repeated_calls(frame, options): ''' Converts a timeline into a time-aggregate summary. Adds together calls along the same call stack, so that repeated calls appear as the same frame. Removes time-linearity - frames are sorted according to total time spent. Useful for outputs that display a summary of execution (e.g. text and html outputs) ''' if frame is None: return None children_by_identifier = {} # iterate over a copy of the children since it's going to mutate while we're iterating for child in frame.children: if child.identifier in children_by_identifier: aggregate_frame = children_by_identifier[child.identifier] # combine the two frames, putting the children and self_time into the aggregate frame. aggregate_frame.self_time += child.self_time if child.children: aggregate_frame.add_children(child.children) # remove this frame, it's been incorporated into aggregate_frame child.remove_from_parent() else: # never seen this identifier before. It becomes the aggregate frame. children_by_identifier[child.identifier] = child # recurse into the children for child in frame.children: aggregate_repeated_calls(child, options=options) # sort the children by time # it's okay to use the internal _children list, sinde we're not changing the tree # structure. frame._children.sort(key=methodcaller('time'), reverse=True) # pylint: disable=W0212 return frame
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_all_tags_names_as_list; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:admin; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:language; 10, string:"en"; 11, block; 11, 12; 11, 14; 11, 59; 11, 60; 11, 66; 11, 72; 11, 83; 11, 132; 11, 153; 11, 174; 11, 183; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 16; 14, 37; 15, identifier:admin; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 29; 18, boolean_operator:and; 18, 19; 18, 24; 19, comparison_operator:!=; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_all_tags_cache_list_admin; 23, dictionary; 24, comparison_operator:in; 24, 25; 24, 26; 25, identifier:language; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_all_tags_cache_list_admin; 29, block; 29, 30; 29, 36; 30, return_statement; 30, 31; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_all_tags_cache_list_admin; 35, identifier:language; 36, comment; 37, else_clause; 37, 38; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 51; 40, boolean_operator:and; 40, 41; 40, 46; 41, comparison_operator:!=; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_all_tags_cache_list; 45, dictionary; 46, comparison_operator:in; 46, 47; 46, 48; 47, identifier:language; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_all_tags_cache_list; 51, block; 51, 52; 51, 58; 52, return_statement; 52, 53; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_all_tags_cache_list; 57, identifier:language; 58, comment; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:s_stud; 63, call; 63, 64; 63, 65; 64, identifier:set; 65, argument_list; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:s_admin; 69, call; 69, 70; 69, 71; 70, identifier:set; 71, argument_list; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 78; 74, tuple_pattern; 74, 75; 74, 76; 74, 77; 75, identifier:common; 76, identifier:_; 77, identifier:org; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:get_all_tags; 82, argument_list; 83, for_statement; 83, 84; 83, 85; 83, 88; 83, 89; 84, identifier:tag; 85, binary_operator:+; 85, 86; 85, 87; 86, identifier:common; 87, identifier:org; 88, comment; 89, block; 89, 90; 89, 111; 89, 118; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:tag_name_with_translation; 93, conditional_expression:if; 93, 94; 93, 105; 93, 110; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:gettext; 98, argument_list; 98, 99; 98, 100; 99, identifier:language; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:tag; 103, identifier:get_name; 104, argument_list; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:tag; 108, identifier:get_name; 109, argument_list; 110, string:""; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:s_admin; 115, identifier:add; 116, argument_list; 116, 117; 117, identifier:tag_name_with_translation; 118, if_statement; 118, 119; 118, 124; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:tag; 122, identifier:is_visible_for_student; 123, argument_list; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:s_stud; 129, identifier:add; 130, argument_list; 130, 131; 131, identifier:tag_name_with_translation; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 139; 134, subscript; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:_all_tags_cache_list_admin; 138, identifier:language; 139, call; 139, 140; 139, 141; 140, identifier:natsorted; 141, argument_list; 141, 142; 141, 143; 142, identifier:s_admin; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:key; 145, lambda; 145, 146; 145, 148; 146, lambda_parameters; 146, 147; 147, identifier:y; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:y; 151, identifier:lower; 152, argument_list; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 160; 155, subscript; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:_all_tags_cache_list; 159, identifier:language; 160, call; 160, 161; 160, 162; 161, identifier:natsorted; 162, argument_list; 162, 163; 162, 164; 163, identifier:s_stud; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:key; 166, lambda; 166, 167; 166, 169; 167, lambda_parameters; 167, 168; 168, identifier:y; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:y; 172, identifier:lower; 173, argument_list; 174, if_statement; 174, 175; 174, 176; 175, identifier:admin; 176, block; 176, 177; 177, return_statement; 177, 178; 178, subscript; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:_all_tags_cache_list_admin; 182, identifier:language; 183, return_statement; 183, 184; 184, subscript; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:_all_tags_cache_list; 188, identifier:language
def get_all_tags_names_as_list(self, admin=False, language="en"): """ Computes and cache two list containing all tags name sorted by natural order on name """ if admin: if self._all_tags_cache_list_admin != {} and language in self._all_tags_cache_list_admin: return self._all_tags_cache_list_admin[language] #Cache hit else: if self._all_tags_cache_list != {} and language in self._all_tags_cache_list: return self._all_tags_cache_list[language] #Cache hit #Cache miss, computes everything s_stud = set() s_admin = set() (common, _, org) = self.get_all_tags() for tag in common + org: # Is tag_name_with_translation correct by doing that like that ? tag_name_with_translation = self.gettext(language, tag.get_name()) if tag.get_name() else "" s_admin.add(tag_name_with_translation) if tag.is_visible_for_student(): s_stud.add(tag_name_with_translation) self._all_tags_cache_list_admin[language] = natsorted(s_admin, key=lambda y: y.lower()) self._all_tags_cache_list[language] = natsorted(s_stud, key=lambda y: y.lower()) if admin: return self._all_tags_cache_list_admin[language] return self._all_tags_cache_list[language]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_users; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:course; 6, block; 6, 7; 6, 9; 6, 57; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:users; 12, call; 12, 13; 12, 14; 13, identifier:OrderedDict; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 40; 18, call; 18, 19; 18, 20; 19, identifier:list; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 39; 22, attribute; 22, 23; 22, 38; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:user_manager; 28, identifier:get_users_info; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:user_manager; 35, identifier:get_course_registered_users; 36, argument_list; 36, 37; 37, identifier:course; 38, identifier:items; 39, argument_list; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:key; 42, lambda; 42, 43; 42, 45; 43, lambda_parameters; 43, 44; 44, identifier:k; 45, conditional_expression:if; 45, 46; 45, 51; 45, 56; 46, subscript; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:k; 49, integer:1; 50, integer:0; 51, comparison_operator:is; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:k; 54, integer:1; 55, None; 56, string:""; 57, return_statement; 57, 58; 58, identifier:users
def get_users(self, course): """ Returns a sorted list of users """ users = OrderedDict(sorted(list(self.user_manager.get_users_info(self.user_manager.get_course_registered_users(course)).items()), key=lambda k: k[1][0] if k[1] is not None else "")) return users
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:radius_cmp; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:a; 5, identifier:b; 6, identifier:offsets; 7, block; 7, 8; 7, 10; 7, 24; 7, 31; 7, 39; 8, expression_statement; 8, 9; 9, string:'''return +1 or -1 for for sorting'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:diff; 13, binary_operator:-; 13, 14; 13, 19; 14, call; 14, 15; 14, 16; 15, identifier:radius; 16, argument_list; 16, 17; 16, 18; 17, identifier:a; 18, identifier:offsets; 19, call; 19, 20; 19, 21; 20, identifier:radius; 21, argument_list; 21, 22; 21, 23; 22, identifier:b; 23, identifier:offsets; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:>; 25, 26; 25, 27; 26, identifier:diff; 27, integer:0; 28, block; 28, 29; 29, return_statement; 29, 30; 30, integer:1; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:<; 32, 33; 32, 34; 33, identifier:diff; 34, integer:0; 35, block; 35, 36; 36, return_statement; 36, 37; 37, unary_operator:-; 37, 38; 38, integer:1; 39, return_statement; 39, 40; 40, integer:0
def radius_cmp(a, b, offsets): '''return +1 or -1 for for sorting''' diff = radius(a, offsets) - radius(b, offsets) if diff > 0: return 1 if diff < 0: return -1 return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:generate_enums_info; 3, parameters; 3, 4; 3, 5; 4, identifier:enums; 5, identifier:msgs; 6, block; 6, 7; 6, 9; 6, 234; 7, expression_statement; 7, 8; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 12; 10, identifier:enum; 11, identifier:enums; 12, block; 12, 13; 12, 24; 12, 34; 12, 40; 12, 72; 12, 76; 12, 80; 12, 198; 12, 209; 12, 220; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:enum; 17, identifier:swift_name; 18, call; 18, 19; 18, 20; 19, identifier:camel_case_from_underscores; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:enum; 23, identifier:name; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:enum; 28, identifier:raw_value_type; 29, call; 29, 30; 29, 31; 30, identifier:get_enum_raw_type; 31, argument_list; 31, 32; 31, 33; 32, identifier:enum; 33, identifier:msgs; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:enum; 38, identifier:formatted_description; 39, string:""; 40, if_statement; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:enum; 43, identifier:description; 44, block; 44, 45; 44, 62; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:enum; 49, identifier:description; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:" "; 53, identifier:join; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:enum; 59, identifier:description; 60, identifier:split; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:enum; 66, identifier:formatted_description; 67, binary_operator:%; 67, 68; 67, 69; 68, string:"\n/**\n %s\n*/\n"; 69, attribute; 69, 70; 69, 71; 70, identifier:enum; 71, identifier:description; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:all_entities; 75, list:[]; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:entities_info; 79, list:[]; 80, for_statement; 80, 81; 80, 82; 80, 85; 81, identifier:entry; 82, attribute; 82, 83; 82, 84; 83, identifier:enum; 84, identifier:entry; 85, block; 85, 86; 85, 102; 85, 104; 85, 119; 85, 128; 85, 134; 85, 168; 85, 177; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:name; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:entry; 93, identifier:name; 94, identifier:replace; 95, argument_list; 95, 96; 95, 101; 96, binary_operator:+; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:enum; 99, identifier:name; 100, string:'_'; 101, string:''; 102, expression_statement; 102, 103; 103, comment; 104, if_statement; 104, 105; 104, 112; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:name; 109, integer:0; 110, identifier:isdigit; 111, argument_list; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:name; 116, binary_operator:+; 116, 117; 116, 118; 117, string:"MAV_"; 118, identifier:name; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:entry; 123, identifier:swift_name; 124, call; 124, 125; 124, 126; 125, identifier:camel_case_from_underscores; 126, argument_list; 126, 127; 127, identifier:name; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:entry; 132, identifier:formatted_description; 133, string:""; 134, if_statement; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:entry; 137, identifier:description; 138, block; 138, 139; 138, 156; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:entry; 143, identifier:description; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, string:" "; 147, identifier:join; 148, argument_list; 148, 149; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:entry; 153, identifier:description; 154, identifier:split; 155, argument_list; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:entry; 160, identifier:formatted_description; 161, binary_operator:+; 161, 162; 161, 167; 162, binary_operator:+; 162, 163; 162, 164; 163, string:"\n\t/// "; 164, attribute; 164, 165; 164, 166; 165, identifier:entry; 166, identifier:description; 167, string:"\n"; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:all_entities; 172, identifier:append; 173, argument_list; 173, 174; 174, attribute; 174, 175; 174, 176; 175, identifier:entry; 176, identifier:swift_name; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:entities_info; 181, identifier:append; 182, argument_list; 182, 183; 183, binary_operator:%; 183, 184; 183, 185; 184, string:'("%s", "%s")'; 185, tuple; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:entry; 188, identifier:name; 189, call; 189, 190; 189, 195; 190, attribute; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:entry; 193, identifier:description; 194, identifier:replace; 195, argument_list; 195, 196; 195, 197; 196, string:'"'; 197, string:'\\"'; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:enum; 202, identifier:all_entities; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, string:", "; 206, identifier:join; 207, argument_list; 207, 208; 208, identifier:all_entities; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:enum; 213, identifier:entities_info; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, string:", "; 217, identifier:join; 218, argument_list; 218, 219; 219, identifier:entities_info; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:enum; 224, identifier:entity_description; 225, call; 225, 226; 225, 231; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:enum; 229, identifier:description; 230, identifier:replace; 231, argument_list; 231, 232; 231, 233; 232, string:'"'; 233, string:'\\"'; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:enums; 238, identifier:sort; 239, argument_list; 239, 240; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:key; 242, lambda; 242, 243; 242, 245; 243, lambda_parameters; 243, 244; 244, identifier:enum; 245, attribute; 245, 246; 245, 247; 246, identifier:enum; 247, identifier:swift_name
def generate_enums_info(enums, msgs): """Add camel case swift names for enums an entries, descriptions and sort enums alphabetically""" for enum in enums: enum.swift_name = camel_case_from_underscores(enum.name) enum.raw_value_type = get_enum_raw_type(enum, msgs) enum.formatted_description = "" if enum.description: enum.description = " ".join(enum.description.split()) enum.formatted_description = "\n/**\n %s\n*/\n" % enum.description all_entities = [] entities_info = [] for entry in enum.entry: name = entry.name.replace(enum.name + '_', '') """Ensure that enums entry name does not start from digit""" if name[0].isdigit(): name = "MAV_" + name entry.swift_name = camel_case_from_underscores(name) entry.formatted_description = "" if entry.description: entry.description = " ".join(entry.description.split()) entry.formatted_description = "\n\t/// " + entry.description + "\n" all_entities.append(entry.swift_name) entities_info.append('("%s", "%s")' % (entry.name, entry.description.replace('"','\\"'))) enum.all_entities = ", ".join(all_entities) enum.entities_info = ", ".join(entities_info) enum.entity_description = enum.description.replace('"','\\"') enums.sort(key = lambda enum : enum.swift_name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:compare_report_print; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:sorted_list; 5, identifier:scores; 6, identifier:best_name; 7, block; 7, 8; 7, 10; 7, 18; 7, 44; 7, 100; 7, 104; 7, 115; 7, 142; 7, 146; 7, 221; 7, 232; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:title_items; 13, list:["Rank", "Name", "Class-Score", "Overall-Score"]; 13, 14; 13, 15; 13, 16; 13, 17; 14, string:"Rank"; 15, string:"Name"; 16, string:"Class-Score"; 17, string:"Overall-Score"; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:class_scores_len; 21, call; 21, 22; 21, 23; 22, identifier:map; 23, argument_list; 23, 24; 23, 36; 24, lambda; 24, 25; 24, 27; 25, lambda_parameters; 25, 26; 26, identifier:x; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:str; 32, argument_list; 32, 33; 33, subscript; 33, 34; 33, 35; 34, identifier:x; 35, string:"class"; 36, call; 36, 37; 36, 38; 37, identifier:list; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:scores; 42, identifier:values; 43, argument_list; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:shifts; 47, list:["%-" + str(len(sorted_list) + 4) + "s", "%-" + str(max(map(lambda x: len(str(x)), sorted_list)) + 4) + "s", "%-" + str(max(class_scores_len) + 11) + "s"]; 47, 48; 47, 61; 47, 87; 48, binary_operator:+; 48, 49; 48, 60; 49, binary_operator:+; 49, 50; 49, 51; 50, string:"%-"; 51, call; 51, 52; 51, 53; 52, identifier:str; 53, argument_list; 53, 54; 54, binary_operator:+; 54, 55; 54, 59; 55, call; 55, 56; 55, 57; 56, identifier:len; 57, argument_list; 57, 58; 58, identifier:sorted_list; 59, integer:4; 60, string:"s"; 61, binary_operator:+; 61, 62; 61, 86; 62, binary_operator:+; 62, 63; 62, 64; 63, string:"%-"; 64, call; 64, 65; 64, 66; 65, identifier:str; 66, argument_list; 66, 67; 67, binary_operator:+; 67, 68; 67, 85; 68, call; 68, 69; 68, 70; 69, identifier:max; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:map; 73, argument_list; 73, 74; 73, 84; 74, lambda; 74, 75; 74, 77; 75, lambda_parameters; 75, 76; 76, identifier:x; 77, call; 77, 78; 77, 79; 78, identifier:len; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:str; 82, argument_list; 82, 83; 83, identifier:x; 84, identifier:sorted_list; 85, integer:4; 86, string:"s"; 87, binary_operator:+; 87, 88; 87, 99; 88, binary_operator:+; 88, 89; 88, 90; 89, string:"%-"; 90, call; 90, 91; 90, 92; 91, identifier:str; 92, argument_list; 92, 93; 93, binary_operator:+; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:max; 96, argument_list; 96, 97; 97, identifier:class_scores_len; 98, integer:11; 99, string:"s"; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:result; 103, string:""; 104, expression_statement; 104, 105; 105, augmented_assignment:+=; 105, 106; 105, 107; 106, identifier:result; 107, binary_operator:+; 107, 108; 107, 114; 108, binary_operator:+; 108, 109; 108, 110; 109, string:"Best : "; 110, call; 110, 111; 110, 112; 111, identifier:str; 112, argument_list; 112, 113; 113, identifier:best_name; 114, string:"\n\n"; 115, expression_statement; 115, 116; 116, augmented_assignment:+=; 116, 117; 116, 118; 117, identifier:result; 118, binary_operator:+; 118, 119; 118, 141; 119, binary_operator:+; 119, 120; 119, 137; 120, binary_operator:%; 120, 121; 120, 128; 121, parenthesized_expression; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, string:""; 125, identifier:join; 126, argument_list; 126, 127; 127, identifier:shifts; 128, call; 128, 129; 128, 130; 129, identifier:tuple; 130, argument_list; 130, 131; 131, subscript; 131, 132; 131, 133; 132, identifier:title_items; 133, slice; 133, 134; 133, 135; 134, colon; 135, unary_operator:-; 135, 136; 136, integer:1; 137, subscript; 137, 138; 137, 139; 138, identifier:title_items; 139, unary_operator:-; 139, 140; 140, integer:1; 141, string:"\n"; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:prev_rank; 145, integer:0; 146, for_statement; 146, 147; 146, 150; 146, 154; 147, pattern_list; 147, 148; 147, 149; 148, identifier:index; 149, identifier:cm; 150, call; 150, 151; 150, 152; 151, identifier:enumerate; 152, argument_list; 152, 153; 153, identifier:sorted_list; 154, block; 154, 155; 154, 159; 154, 176; 154, 217; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:rank; 158, identifier:index; 159, if_statement; 159, 160; 159, 171; 160, comparison_operator:==; 160, 161; 160, 166; 161, subscript; 161, 162; 161, 163; 162, identifier:scores; 163, subscript; 163, 164; 163, 165; 164, identifier:sorted_list; 165, identifier:rank; 166, subscript; 166, 167; 166, 168; 167, identifier:scores; 168, subscript; 168, 169; 168, 170; 169, identifier:sorted_list; 170, identifier:prev_rank; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:rank; 175, identifier:prev_rank; 176, expression_statement; 176, 177; 177, augmented_assignment:+=; 177, 178; 177, 179; 178, identifier:result; 179, binary_operator:+; 179, 180; 179, 216; 180, binary_operator:+; 180, 181; 180, 208; 181, binary_operator:%; 181, 182; 181, 189; 182, parenthesized_expression; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, string:""; 186, identifier:join; 187, argument_list; 187, 188; 188, identifier:shifts; 189, tuple; 189, 190; 189, 196; 189, 200; 190, call; 190, 191; 190, 192; 191, identifier:str; 192, argument_list; 192, 193; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:rank; 195, integer:1; 196, call; 196, 197; 196, 198; 197, identifier:str; 198, argument_list; 198, 199; 199, identifier:cm; 200, call; 200, 201; 200, 202; 201, identifier:str; 202, argument_list; 202, 203; 203, subscript; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:scores; 206, identifier:cm; 207, string:"class"; 208, call; 208, 209; 208, 210; 209, identifier:str; 210, argument_list; 210, 211; 211, subscript; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:scores; 214, identifier:cm; 215, string:"overall"; 216, string:"\n"; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:prev_rank; 220, identifier:rank; 221, if_statement; 221, 222; 221, 225; 222, comparison_operator:is; 222, 223; 222, 224; 223, identifier:best_name; 224, None; 225, block; 225, 226; 226, expression_statement; 226, 227; 227, augmented_assignment:+=; 227, 228; 227, 229; 228, identifier:result; 229, binary_operator:+; 229, 230; 229, 231; 230, string:"\nWarning: "; 231, identifier:COMPARE_RESULT_WARNING; 232, return_statement; 232, 233; 233, identifier:result
def compare_report_print(sorted_list, scores, best_name): """ Return compare report. :param sorted_list: sorted list of cm's :type sorted_list: list :param scores: scores of cm's :type scores: dict :param best_name: best cm name :type best_name: str :return: printable result as str """ title_items = ["Rank", "Name", "Class-Score", "Overall-Score"] class_scores_len = map(lambda x: len( str(x["class"])), list(scores.values())) shifts = ["%-" + str(len(sorted_list) + 4) + "s", "%-" + str(max(map(lambda x: len(str(x)), sorted_list)) + 4) + "s", "%-" + str(max(class_scores_len) + 11) + "s"] result = "" result += "Best : " + str(best_name) + "\n\n" result += ("".join(shifts) ) % tuple(title_items[:-1]) + title_items[-1] + "\n" prev_rank = 0 for index, cm in enumerate(sorted_list): rank = index if scores[sorted_list[rank]] == scores[sorted_list[prev_rank]]: rank = prev_rank result += ("".join(shifts)) % (str(rank + 1), str(cm), str(scores[cm]["class"])) + str(scores[cm]["overall"]) + "\n" prev_rank = rank if best_name is None: result += "\nWarning: " + COMPARE_RESULT_WARNING return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:replace_cells; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key; 6, identifier:sorted_row_idxs; 7, block; 7, 8; 7, 10; 7, 17; 7, 21; 7, 25; 7, 37; 7, 108; 7, 123; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 16; 12, pattern_list; 12, 13; 12, 14; 12, 15; 13, identifier:row; 14, identifier:col; 15, identifier:tab; 16, identifier:key; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:new_keys; 20, dictionary; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:del_keys; 24, list:[]; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:selection; 28, call; 28, 29; 28, 36; 29, attribute; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:grid; 34, identifier:actions; 35, identifier:get_selection; 36, argument_list; 37, for_statement; 37, 38; 37, 42; 37, 47; 38, pattern_list; 38, 39; 38, 40; 38, 41; 39, identifier:__row; 40, identifier:__col; 41, identifier:__tab; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:grid; 46, identifier:code_array; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 63; 49, boolean_operator:and; 49, 50; 49, 53; 49, 54; 50, comparison_operator:==; 50, 51; 50, 52; 51, identifier:__tab; 52, identifier:tab; 53, line_continuation:\; 54, parenthesized_expression; 54, 55; 55, boolean_operator:or; 55, 56; 55, 58; 56, not_operator; 56, 57; 57, identifier:selection; 58, comparison_operator:in; 58, 59; 58, 62; 59, tuple; 59, 60; 59, 61; 60, identifier:__row; 61, identifier:__col; 62, identifier:selection; 63, block; 63, 64; 63, 73; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:new_row; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:sorted_row_idxs; 70, identifier:index; 71, argument_list; 71, 72; 72, identifier:__row; 73, if_statement; 73, 74; 73, 77; 74, comparison_operator:!=; 74, 75; 74, 76; 75, identifier:__row; 76, identifier:new_row; 77, block; 77, 78; 77, 98; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 86; 79, 87; 80, subscript; 80, 81; 80, 82; 81, identifier:new_keys; 82, tuple; 82, 83; 82, 84; 82, 85; 83, identifier:new_row; 84, identifier:__col; 85, identifier:__tab; 86, line_continuation:\; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:grid; 92, identifier:code_array; 93, argument_list; 93, 94; 94, tuple; 94, 95; 94, 96; 94, 97; 95, identifier:__row; 96, identifier:__col; 97, identifier:__tab; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:del_keys; 102, identifier:append; 103, argument_list; 103, 104; 104, tuple; 104, 105; 104, 106; 104, 107; 105, identifier:__row; 106, identifier:__col; 107, identifier:__tab; 108, for_statement; 108, 109; 108, 110; 108, 111; 109, identifier:key; 110, identifier:del_keys; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 121; 114, attribute; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:grid; 119, identifier:code_array; 120, identifier:pop; 121, argument_list; 121, 122; 122, identifier:key; 123, for_statement; 123, 124; 123, 125; 123, 126; 124, identifier:key; 125, identifier:new_keys; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:CellActions; 131, identifier:set_code; 132, argument_list; 132, 133; 132, 134; 132, 135; 133, identifier:self; 134, identifier:key; 135, subscript; 135, 136; 135, 137; 136, identifier:new_keys; 137, identifier:key
def replace_cells(self, key, sorted_row_idxs): """Replaces cells in current selection so that they are sorted""" row, col, tab = key new_keys = {} del_keys = [] selection = self.grid.actions.get_selection() for __row, __col, __tab in self.grid.code_array: if __tab == tab and \ (not selection or (__row, __col) in selection): new_row = sorted_row_idxs.index(__row) if __row != new_row: new_keys[(new_row, __col, __tab)] = \ self.grid.code_array((__row, __col, __tab)) del_keys.append((__row, __col, __tab)) for key in del_keys: self.grid.code_array.pop(key) for key in new_keys: CellActions.set_code(self, key, new_keys[key])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:OnSortAscending; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:event; 6, block; 6, 7; 6, 9; 6, 64; 7, expression_statement; 7, 8; 8, comment; 9, try_statement; 9, 10; 9, 48; 10, block; 10, 11; 10, 41; 11, with_statement; 11, 12; 11, 23; 12, with_clause; 12, 13; 13, with_item; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:undo; 17, identifier:group; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:_; 21, argument_list; 21, 22; 22, string:"Sort ascending"; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 33; 26, attribute; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:grid; 31, identifier:actions; 32, identifier:sort_ascending; 33, argument_list; 33, 34; 34, attribute; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:grid; 39, identifier:actions; 40, identifier:cursor; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:statustext; 44, call; 44, 45; 44, 46; 45, identifier:_; 46, argument_list; 46, 47; 47, string:u"Sorting complete."; 48, except_clause; 48, 49; 48, 50; 48, 51; 49, identifier:Exception; 50, identifier:err; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:statustext; 55, call; 55, 56; 55, 62; 56, attribute; 56, 57; 56, 61; 57, call; 57, 58; 57, 59; 58, identifier:_; 59, argument_list; 59, 60; 60, string:u"Sorting failed: {}"; 61, identifier:format; 62, argument_list; 62, 63; 63, identifier:err; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:post_command_event; 67, argument_list; 67, 68; 67, 73; 67, 78; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:grid; 72, identifier:main_window; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:grid; 77, identifier:StatusBarMsg; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:text; 80, identifier:statustext
def OnSortAscending(self, event): """Sort ascending event handler""" try: with undo.group(_("Sort ascending")): self.grid.actions.sort_ascending(self.grid.actions.cursor) statustext = _(u"Sorting complete.") except Exception, err: statustext = _(u"Sorting failed: {}").format(err) post_command_event(self.grid.main_window, self.grid.StatusBarMsg, text=statustext)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_font_list; 3, parameters; 4, block; 4, 5; 4, 7; 4, 15; 4, 31; 4, 37; 5, expression_statement; 5, 6; 6, comment; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:font_map; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:pangocairo; 13, identifier:cairo_font_map_get_default; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:font_list; 18, list_comprehension; 18, 19; 18, 24; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:f; 22, identifier:get_name; 23, argument_list; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:f; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:font_map; 29, identifier:list_families; 30, argument_list; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:font_list; 35, identifier:sort; 36, argument_list; 37, return_statement; 37, 38; 38, identifier:font_list
def get_font_list(): """Returns a sorted list of all system font names""" font_map = pangocairo.cairo_font_map_get_default() font_list = [f.get_name() for f in font_map.list_families()] font_list.sort() return font_list
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_sorted_keys; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:keys; 6, identifier:startkey; 7, default_parameter; 7, 8; 7, 9; 8, identifier:reverse; 9, False; 10, block; 10, 11; 10, 13; 10, 26; 10, 73; 10, 86; 10, 100; 10, 114; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:tuple_key; 16, lambda; 16, 17; 16, 19; 17, lambda_parameters; 17, 18; 18, identifier:t; 19, subscript; 19, 20; 19, 21; 20, identifier:t; 21, slice; 21, 22; 21, 23; 21, 24; 22, colon; 23, colon; 24, unary_operator:-; 24, 25; 25, integer:1; 26, if_statement; 26, 27; 26, 28; 26, 50; 27, identifier:reverse; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:tuple_cmp; 32, lambda; 32, 33; 32, 35; 33, lambda_parameters; 33, 34; 34, identifier:t; 35, comparison_operator:>; 35, 36; 35, 43; 36, subscript; 36, 37; 36, 38; 37, identifier:t; 38, slice; 38, 39; 38, 40; 38, 41; 39, colon; 40, colon; 41, unary_operator:-; 41, 42; 42, integer:1; 43, subscript; 43, 44; 43, 45; 44, identifier:startkey; 45, slice; 45, 46; 45, 47; 45, 48; 46, colon; 47, colon; 48, unary_operator:-; 48, 49; 49, integer:1; 50, else_clause; 50, 51; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:tuple_cmp; 55, lambda; 55, 56; 55, 58; 56, lambda_parameters; 56, 57; 57, identifier:t; 58, comparison_operator:<; 58, 59; 58, 66; 59, subscript; 59, 60; 59, 61; 60, identifier:t; 61, slice; 61, 62; 61, 63; 61, 64; 62, colon; 63, colon; 64, unary_operator:-; 64, 65; 65, integer:1; 66, subscript; 66, 67; 66, 68; 67, identifier:startkey; 68, slice; 68, 69; 68, 70; 68, 71; 69, colon; 70, colon; 71, unary_operator:-; 71, 72; 72, integer:1; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:searchkeys; 76, call; 76, 77; 76, 78; 77, identifier:sorted; 78, argument_list; 78, 79; 78, 80; 78, 83; 79, identifier:keys; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:key; 82, identifier:tuple_key; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:reverse; 85, identifier:reverse; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:searchpos; 89, call; 89, 90; 89, 91; 90, identifier:sum; 91, generator_expression; 91, 92; 91, 93; 92, integer:1; 93, for_in_clause; 93, 94; 93, 95; 94, identifier:_; 95, call; 95, 96; 95, 97; 96, identifier:ifilter; 97, argument_list; 97, 98; 97, 99; 98, identifier:tuple_cmp; 99, identifier:searchkeys; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:searchkeys; 103, binary_operator:+; 103, 104; 103, 109; 104, subscript; 104, 105; 104, 106; 105, identifier:searchkeys; 106, slice; 106, 107; 106, 108; 107, identifier:searchpos; 108, colon; 109, subscript; 109, 110; 109, 111; 110, identifier:searchkeys; 111, slice; 111, 112; 111, 113; 112, colon; 113, identifier:searchpos; 114, for_statement; 114, 115; 114, 116; 114, 117; 115, identifier:key; 116, identifier:searchkeys; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, yield; 119, 120; 120, identifier:key
def _sorted_keys(self, keys, startkey, reverse=False): """Generator that yields sorted keys starting with startkey Parameters ---------- keys: Iterable of tuple/list \tKey sequence that is sorted startkey: Tuple/list \tFirst key to be yielded reverse: Bool \tSort direction reversed if True """ tuple_key = lambda t: t[::-1] if reverse: tuple_cmp = lambda t: t[::-1] > startkey[::-1] else: tuple_cmp = lambda t: t[::-1] < startkey[::-1] searchkeys = sorted(keys, key=tuple_key, reverse=reverse) searchpos = sum(1 for _ in ifilter(tuple_cmp, searchkeys)) searchkeys = searchkeys[searchpos:] + searchkeys[:searchpos] for key in searchkeys: yield key
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:stratify; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 30; 5, 38; 5, 76; 5, 92; 5, 112; 5, 131; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 14; 10, pattern_list; 10, 11; 10, 12; 10, 13; 11, identifier:Y; 12, identifier:D; 13, identifier:X; 14, expression_list; 14, 15; 14, 20; 14, 25; 15, subscript; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:raw_data; 19, string:'Y'; 20, subscript; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:raw_data; 24, string:'D'; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:raw_data; 29, string:'X'; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:pscore; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:raw_data; 37, string:'pscore'; 38, if_statement; 38, 39; 38, 46; 38, 57; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:blocks; 45, identifier:int; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:blocks; 50, call; 50, 51; 50, 52; 51, identifier:split_equal_bins; 52, argument_list; 52, 53; 52, 54; 53, identifier:pscore; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:blocks; 57, else_clause; 57, 58; 58, block; 58, 59; 58, 68; 58, 69; 58, 75; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:blocks; 62, subscript; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:blocks; 66, slice; 66, 67; 67, colon; 68, comment; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:blocks; 73, integer:0; 74, integer:0; 75, comment; 76, function_definition; 76, 77; 76, 78; 76, 81; 77, function_name:subset; 78, parameters; 78, 79; 78, 80; 79, identifier:p_low; 80, identifier:p_high; 81, block; 81, 82; 82, return_statement; 82, 83; 83, binary_operator:&; 83, 84; 83, 88; 84, parenthesized_expression; 84, 85; 85, comparison_operator:<; 85, 86; 85, 87; 86, identifier:p_low; 87, identifier:pscore; 88, parenthesized_expression; 88, 89; 89, comparison_operator:<=; 89, 90; 89, 91; 90, identifier:pscore; 91, identifier:p_high; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:subsets; 95, list_comprehension; 95, 96; 95, 101; 96, call; 96, 97; 96, 98; 97, identifier:subset; 98, argument_list; 98, 99; 99, list_splat; 99, 100; 100, identifier:ps; 101, for_in_clause; 101, 102; 101, 103; 102, identifier:ps; 103, call; 103, 104; 103, 105; 104, identifier:zip; 105, argument_list; 105, 106; 105, 107; 106, identifier:blocks; 107, subscript; 107, 108; 107, 109; 108, identifier:blocks; 109, slice; 109, 110; 109, 111; 110, integer:1; 111, colon; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:strata; 115, list_comprehension; 115, 116; 115, 128; 116, call; 116, 117; 116, 118; 117, identifier:CausalModel; 118, argument_list; 118, 119; 118, 122; 118, 125; 119, subscript; 119, 120; 119, 121; 120, identifier:Y; 121, identifier:s; 122, subscript; 122, 123; 122, 124; 123, identifier:D; 124, identifier:s; 125, subscript; 125, 126; 125, 127; 126, identifier:X; 127, identifier:s; 128, for_in_clause; 128, 129; 128, 130; 129, identifier:s; 130, identifier:subsets; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:strata; 136, call; 136, 137; 136, 138; 137, identifier:Strata; 138, argument_list; 138, 139; 138, 140; 138, 141; 139, identifier:strata; 140, identifier:subsets; 141, identifier:pscore
def stratify(self): """ Stratifies the sample based on propensity score. By default the sample is divided into five equal-sized bins. The number of bins can be set by modifying the object attribute named blocks. Alternatively, custom-sized bins can be created by setting blocks equal to a sorted list of numbers between 0 and 1 indicating the bin boundaries. This method should only be executed after the propensity score has been estimated. """ Y, D, X = self.raw_data['Y'], self.raw_data['D'], self.raw_data['X'] pscore = self.raw_data['pscore'] if isinstance(self.blocks, int): blocks = split_equal_bins(pscore, self.blocks) else: blocks = self.blocks[:] # make a copy; should be sorted blocks[0] = 0 # avoids always dropping 1st unit def subset(p_low, p_high): return (p_low < pscore) & (pscore <= p_high) subsets = [subset(*ps) for ps in zip(blocks, blocks[1:])] strata = [CausalModel(Y[s], D[s], X[s]) for s in subsets] self.strata = Strata(strata, subsets, pscore)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 43; 2, function_name:list_current_orders; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 3, 40; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:bet_ids; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:market_ids; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:order_projection; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:customer_order_refs; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:customer_strategy_refs; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:date_range; 22, call; 22, 23; 22, 24; 23, identifier:time_range; 24, argument_list; 25, default_parameter; 25, 26; 25, 27; 26, identifier:order_by; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:sort_dir; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:from_record; 33, None; 34, default_parameter; 34, 35; 34, 36; 35, identifier:record_count; 36, None; 37, default_parameter; 37, 38; 37, 39; 38, identifier:session; 39, None; 40, default_parameter; 40, 41; 40, 42; 41, identifier:lightweight; 42, None; 43, block; 43, 44; 43, 46; 43, 55; 43, 65; 43, 78; 44, expression_statement; 44, 45; 45, comment; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:params; 49, call; 49, 50; 49, 51; 50, identifier:clean_locals; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:locals; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:method; 58, binary_operator:%; 58, 59; 58, 60; 59, string:'%s%s'; 60, tuple; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:URI; 64, string:'listCurrentOrders'; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, tuple_pattern; 67, 68; 67, 69; 68, identifier:response; 69, identifier:elapsed_time; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:request; 74, argument_list; 74, 75; 74, 76; 74, 77; 75, identifier:method; 76, identifier:params; 77, identifier:session; 78, return_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:process_response; 83, argument_list; 83, 84; 83, 85; 83, 88; 83, 89; 84, identifier:response; 85, attribute; 85, 86; 85, 87; 86, identifier:resources; 87, identifier:CurrentOrders; 88, identifier:elapsed_time; 89, identifier:lightweight
def list_current_orders(self, bet_ids=None, market_ids=None, order_projection=None, customer_order_refs=None, customer_strategy_refs=None, date_range=time_range(), order_by=None, sort_dir=None, from_record=None, record_count=None, session=None, lightweight=None): """ Returns a list of your current orders. :param list bet_ids: If you ask for orders, restricts the results to orders with the specified bet IDs :param list market_ids: One or more market ids :param str order_projection: Optionally restricts the results to the specified order status :param list customer_order_refs: Optionally restricts the results to the specified customer order references :param list customer_strategy_refs: Optionally restricts the results to the specified customer strategy references :param dict date_range: Optionally restricts the results to be from/to the specified date, these dates are contextual to the orders being returned and therefore the dates used to filter on will change to placed, matched, voided or settled dates depending on the orderBy :param str order_by: Specifies how the results will be ordered. If no value is passed in, it defaults to BY_BET :param str sort_dir: Specifies the direction the results will be sorted in :param int from_record: Specifies the first record that will be returned :param int record_count: Specifies how many records will be returned from the index position 'fromRecord' :param requests.session session: Requests session object :param bool lightweight: If True will return dict not a resource :rtype: resources.CurrentOrders """ params = clean_locals(locals()) method = '%s%s' % (self.URI, 'listCurrentOrders') (response, elapsed_time) = self.request(method, params, session) return self.process_response(response, resources.CurrentOrders, elapsed_time, lightweight)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:visit_Module; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:node; 6, block; 6, 7; 6, 9; 6, 15; 6, 21; 6, 52; 6, 94; 6, 105; 6, 113; 6, 119; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:newbody; 12, call; 12, 13; 12, 14; 13, identifier:list; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:olddef; 18, call; 18, 19; 18, 20; 19, identifier:list; 20, argument_list; 21, for_statement; 21, 22; 21, 23; 21, 26; 22, identifier:stmt; 23, attribute; 23, 24; 23, 25; 24, identifier:node; 25, identifier:body; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 35; 27, 43; 28, call; 28, 29; 28, 30; 29, identifier:isinstance; 30, argument_list; 30, 31; 30, 32; 31, identifier:stmt; 32, attribute; 32, 33; 32, 34; 33, identifier:ast; 34, identifier:FunctionDef; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:olddef; 40, identifier:append; 41, argument_list; 41, 42; 42, identifier:stmt; 43, else_clause; 43, 44; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:newbody; 49, identifier:append; 50, argument_list; 50, 51; 51, identifier:stmt; 52, try_statement; 52, 53; 52, 82; 53, block; 53, 54; 53, 66; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:newdef; 57, call; 57, 58; 57, 59; 58, identifier:topological_sort; 59, argument_list; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:type_dependencies; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:ordered_global_declarations; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:newdef; 69, list_comprehension; 69, 70; 69, 71; 69, 74; 70, identifier:f; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:f; 73, identifier:newdef; 74, if_clause; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:isinstance; 77, argument_list; 77, 78; 77, 79; 78, identifier:f; 79, attribute; 79, 80; 79, 81; 80, identifier:ast; 81, identifier:FunctionDef; 82, except_clause; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:nx; 86, identifier:exception; 87, identifier:NetworkXUnfeasible; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:PythranSyntaxError; 92, argument_list; 92, 93; 93, string:"Infinite function recursion"; 94, assert_statement; 94, 95; 94, 104; 95, comparison_operator:==; 95, 96; 95, 100; 96, call; 96, 97; 96, 98; 97, identifier:set; 98, argument_list; 98, 99; 99, identifier:newdef; 100, call; 100, 101; 100, 102; 101, identifier:set; 102, argument_list; 102, 103; 103, identifier:olddef; 104, string:"A function have been lost..."; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:node; 109, identifier:body; 110, binary_operator:+; 110, 111; 110, 112; 111, identifier:newbody; 112, identifier:newdef; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:update; 118, True; 119, return_statement; 119, 120; 120, identifier:node
def visit_Module(self, node): """ Keep everything but function definition then add sorted functions. Most of the time, many function sort work so we use function calldepth as a "sort hint" to simplify typing. """ newbody = list() olddef = list() for stmt in node.body: if isinstance(stmt, ast.FunctionDef): olddef.append(stmt) else: newbody.append(stmt) try: newdef = topological_sort( self.type_dependencies, self.ordered_global_declarations) newdef = [f for f in newdef if isinstance(f, ast.FunctionDef)] except nx.exception.NetworkXUnfeasible: raise PythranSyntaxError("Infinite function recursion") assert set(newdef) == set(olddef), "A function have been lost..." node.body = newbody + newdef self.update = True return node
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:qzordered; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:A; 5, identifier:B; 6, default_parameter; 6, 7; 6, 8; 7, identifier:crit; 8, float:1.0; 9, block; 9, 10; 9, 12; 9, 16; 9, 32; 9, 52; 9, 71; 10, expression_statement; 10, 11; 11, string:"Eigenvalues bigger than crit are sorted in the top-left."; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:TOL; 15, float:1e-10; 16, function_definition; 16, 17; 16, 18; 16, 21; 17, function_name:select; 18, parameters; 18, 19; 18, 20; 19, identifier:alpha; 20, identifier:beta; 21, block; 21, 22; 22, return_statement; 22, 23; 23, comparison_operator:>; 23, 24; 23, 27; 24, binary_operator:**; 24, 25; 24, 26; 25, identifier:alpha; 26, integer:2; 27, binary_operator:*; 27, 28; 27, 29; 28, identifier:crit; 29, binary_operator:**; 29, 30; 29, 31; 30, identifier:beta; 31, integer:2; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 41; 34, list_pattern; 34, 35; 34, 36; 34, 37; 34, 38; 34, 39; 34, 40; 35, identifier:S; 36, identifier:T; 37, identifier:alpha; 38, identifier:beta; 39, identifier:U; 40, identifier:V; 41, call; 41, 42; 41, 43; 42, identifier:ordqz; 43, argument_list; 43, 44; 43, 45; 43, 46; 43, 49; 44, identifier:A; 45, identifier:B; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:output; 48, string:'real'; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:sort; 51, identifier:select; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:eigval; 55, call; 55, 56; 55, 57; 56, identifier:abs; 57, argument_list; 57, 58; 58, binary_operator:/; 58, 59; 58, 65; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:numpy; 62, identifier:diag; 63, argument_list; 63, 64; 64, identifier:S; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:numpy; 68, identifier:diag; 69, argument_list; 69, 70; 70, identifier:T; 71, return_statement; 71, 72; 72, list:[S,T,U,V,eigval]; 72, 73; 72, 74; 72, 75; 72, 76; 72, 77; 73, identifier:S; 74, identifier:T; 75, identifier:U; 76, identifier:V; 77, identifier:eigval
def qzordered(A,B,crit=1.0): "Eigenvalues bigger than crit are sorted in the top-left." TOL = 1e-10 def select(alpha, beta): return alpha**2>crit*beta**2 [S,T,alpha,beta,U,V] = ordqz(A,B,output='real',sort=select) eigval = abs(numpy.diag(S)/numpy.diag(T)) return [S,T,U,V,eigval]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:ordqz; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:A; 5, identifier:B; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, string:'lhp'; 9, default_parameter; 9, 10; 9, 11; 10, identifier:output; 11, string:'real'; 12, default_parameter; 12, 13; 12, 14; 13, identifier:overwrite_a; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:overwrite_b; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:check_finite; 20, True; 21, block; 21, 22; 21, 24; 21, 27; 21, 32; 21, 37; 21, 46; 21, 53; 21, 60; 21, 69; 21, 70; 21, 74; 21, 102; 21, 124; 21, 161; 21, 168; 21, 176; 21, 188; 21, 236; 21, 240; 21, 274; 21, 291; 21, 298; 21, 327; 21, 328; 21, 329; 22, expression_statement; 22, 23; 23, comment; 24, import_statement; 24, 25; 25, dotted_name; 25, 26; 26, identifier:warnings; 27, import_statement; 27, 28; 28, aliased_import; 28, 29; 28, 31; 29, dotted_name; 29, 30; 30, identifier:numpy; 31, identifier:np; 32, import_from_statement; 32, 33; 32, 35; 33, dotted_name; 33, 34; 34, identifier:numpy; 35, dotted_name; 35, 36; 36, identifier:asarray_chkfinite; 37, import_from_statement; 37, 38; 37, 42; 37, 44; 38, dotted_name; 38, 39; 38, 40; 38, 41; 39, identifier:scipy; 40, identifier:linalg; 41, identifier:misc; 42, dotted_name; 42, 43; 43, identifier:LinAlgError; 44, dotted_name; 44, 45; 45, identifier:_datacopied; 46, import_from_statement; 46, 47; 46, 51; 47, dotted_name; 47, 48; 47, 49; 47, 50; 48, identifier:scipy; 49, identifier:linalg; 50, identifier:lapack; 51, dotted_name; 51, 52; 52, identifier:get_lapack_funcs; 53, import_from_statement; 53, 54; 53, 58; 54, dotted_name; 54, 55; 54, 56; 54, 57; 55, identifier:scipy; 56, identifier:_lib; 57, identifier:six; 58, dotted_name; 58, 59; 59, identifier:callable; 60, import_from_statement; 60, 61; 60, 65; 60, 67; 61, dotted_name; 61, 62; 61, 63; 61, 64; 62, identifier:scipy; 63, identifier:linalg; 64, identifier:_decomp_qz; 65, dotted_name; 65, 66; 66, identifier:_qz; 67, dotted_name; 67, 68; 68, identifier:_select_function; 69, comment; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:lwork; 73, None; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, pattern_list; 76, 77; 76, 78; 77, identifier:result; 78, identifier:typ; 79, call; 79, 80; 79, 81; 80, identifier:_qz; 81, argument_list; 81, 82; 81, 83; 81, 84; 81, 87; 81, 90; 81, 93; 81, 96; 81, 99; 82, identifier:A; 83, identifier:B; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:output; 86, identifier:output; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:lwork; 89, identifier:lwork; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:sort; 92, None; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:overwrite_a; 95, identifier:overwrite_a; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:overwrite_b; 98, identifier:overwrite_b; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:check_finite; 101, identifier:check_finite; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 109; 104, pattern_list; 104, 105; 104, 106; 104, 107; 104, 108; 105, identifier:AA; 106, identifier:BB; 107, identifier:Q; 108, identifier:Z; 109, expression_list; 109, 110; 109, 113; 109, 116; 109, 120; 110, subscript; 110, 111; 110, 112; 111, identifier:result; 112, integer:0; 113, subscript; 113, 114; 113, 115; 114, identifier:result; 115, integer:1; 116, subscript; 116, 117; 116, 118; 117, identifier:result; 118, unary_operator:-; 118, 119; 119, integer:4; 120, subscript; 120, 121; 120, 122; 121, identifier:result; 122, unary_operator:-; 122, 123; 123, integer:3; 124, if_statement; 124, 125; 124, 128; 124, 147; 125, comparison_operator:not; 125, 126; 125, 127; 126, identifier:typ; 127, string:'cz'; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, pattern_list; 131, 132; 131, 133; 132, identifier:alpha; 133, identifier:beta; 134, expression_list; 134, 135; 134, 144; 135, binary_operator:+; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:result; 138, integer:3; 139, binary_operator:*; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:result; 142, integer:4; 143, float:1.j; 144, subscript; 144, 145; 144, 146; 145, identifier:result; 146, integer:5; 147, else_clause; 147, 148; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, pattern_list; 151, 152; 151, 153; 152, identifier:alpha; 153, identifier:beta; 154, expression_list; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:result; 157, integer:3; 158, subscript; 158, 159; 158, 160; 159, identifier:result; 160, integer:4; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:sfunction; 164, call; 164, 165; 164, 166; 165, identifier:_select_function; 166, argument_list; 166, 167; 167, identifier:sort; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:select; 171, call; 171, 172; 171, 173; 172, identifier:sfunction; 173, argument_list; 173, 174; 173, 175; 174, identifier:alpha; 175, identifier:beta; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 180; 178, pattern_list; 178, 179; 179, identifier:tgsen; 180, call; 180, 181; 180, 182; 181, identifier:get_lapack_funcs; 182, argument_list; 182, 183; 182, 185; 183, tuple; 183, 184; 184, string:'tgsen'; 185, tuple; 185, 186; 185, 187; 186, identifier:AA; 187, identifier:BB; 188, if_statement; 188, 189; 188, 197; 189, boolean_operator:or; 189, 190; 189, 193; 190, comparison_operator:is; 190, 191; 190, 192; 191, identifier:lwork; 192, None; 193, comparison_operator:==; 193, 194; 193, 195; 194, identifier:lwork; 195, unary_operator:-; 195, 196; 196, integer:1; 197, block; 197, 198; 197, 213; 197, 231; 197, 232; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:result; 201, call; 201, 202; 201, 203; 202, identifier:tgsen; 203, argument_list; 203, 204; 203, 205; 203, 206; 203, 207; 203, 208; 203, 209; 204, identifier:select; 205, identifier:AA; 206, identifier:BB; 207, identifier:Q; 208, identifier:Z; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:lwork; 211, unary_operator:-; 211, 212; 212, integer:1; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:lwork; 216, call; 216, 217; 216, 227; 217, attribute; 217, 218; 217, 226; 218, attribute; 218, 219; 218, 225; 219, subscript; 219, 220; 219, 224; 220, subscript; 220, 221; 220, 222; 221, identifier:result; 222, unary_operator:-; 222, 223; 223, integer:3; 224, integer:0; 225, identifier:real; 226, identifier:astype; 227, argument_list; 227, 228; 228, attribute; 228, 229; 228, 230; 229, identifier:np; 230, identifier:int; 231, comment; 232, expression_statement; 232, 233; 233, augmented_assignment:+=; 233, 234; 233, 235; 234, identifier:lwork; 235, integer:1; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:liwork; 239, None; 240, if_statement; 240, 241; 240, 249; 241, boolean_operator:or; 241, 242; 241, 245; 242, comparison_operator:is; 242, 243; 242, 244; 243, identifier:liwork; 244, None; 245, comparison_operator:==; 245, 246; 245, 247; 246, identifier:liwork; 247, unary_operator:-; 247, 248; 248, integer:1; 249, block; 249, 250; 249, 265; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:result; 253, call; 253, 254; 253, 255; 254, identifier:tgsen; 255, argument_list; 255, 256; 255, 257; 255, 258; 255, 259; 255, 260; 255, 261; 256, identifier:select; 257, identifier:AA; 258, identifier:BB; 259, identifier:Q; 260, identifier:Z; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:liwork; 263, unary_operator:-; 263, 264; 264, integer:1; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:liwork; 268, subscript; 268, 269; 268, 273; 269, subscript; 269, 270; 269, 271; 270, identifier:result; 271, unary_operator:-; 271, 272; 272, integer:2; 273, integer:0; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:result; 277, call; 277, 278; 277, 279; 278, identifier:tgsen; 279, argument_list; 279, 280; 279, 281; 279, 282; 279, 283; 279, 284; 279, 285; 279, 288; 280, identifier:select; 281, identifier:AA; 282, identifier:BB; 283, identifier:Q; 284, identifier:Z; 285, keyword_argument; 285, 286; 285, 287; 286, identifier:lwork; 287, identifier:lwork; 288, keyword_argument; 288, 289; 288, 290; 289, identifier:liwork; 290, identifier:liwork; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:info; 294, subscript; 294, 295; 294, 296; 295, identifier:result; 296, unary_operator:-; 296, 297; 297, integer:1; 298, if_statement; 298, 299; 298, 302; 298, 311; 299, comparison_operator:<; 299, 300; 299, 301; 300, identifier:info; 301, integer:0; 302, block; 302, 303; 303, raise_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:ValueError; 306, argument_list; 306, 307; 307, binary_operator:%; 307, 308; 307, 309; 308, string:"Illegal value in argument %d of tgsen"; 309, unary_operator:-; 309, 310; 310, identifier:info; 311, elif_clause; 311, 312; 311, 315; 312, comparison_operator:==; 312, 313; 312, 314; 313, identifier:info; 314, integer:1; 315, block; 315, 316; 316, raise_statement; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:ValueError; 319, argument_list; 319, 320; 320, concatenated_string; 320, 321; 320, 322; 320, 323; 320, 324; 320, 325; 320, 326; 321, string:"Reordering of (A, B) failed because the transformed"; 322, string:" matrix pair (A, B) would be too far from "; 323, string:"generalized Schur form; the problem is very "; 324, string:"ill-conditioned. (A, B) may have been partially "; 325, string:"reorded. If requested, 0 is returned in DIF(*), "; 326, string:"PL, and PR."; 327, comment; 328, comment; 329, if_statement; 329, 330; 329, 335; 329, 366; 329, 367; 329, 368; 330, comparison_operator:in; 330, 331; 330, 332; 331, identifier:typ; 332, list:['f', 'd']; 332, 333; 332, 334; 333, string:'f'; 334, string:'d'; 335, block; 335, 336; 335, 348; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:alpha; 339, binary_operator:+; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:result; 342, integer:2; 343, binary_operator:*; 343, 344; 343, 347; 344, subscript; 344, 345; 344, 346; 345, identifier:result; 346, integer:3; 347, float:1.j; 348, return_statement; 348, 349; 349, tuple; 349, 350; 349, 353; 349, 356; 349, 357; 349, 360; 349, 363; 350, subscript; 350, 351; 350, 352; 351, identifier:result; 352, integer:0; 353, subscript; 353, 354; 353, 355; 354, identifier:result; 355, integer:1; 356, identifier:alpha; 357, subscript; 357, 358; 357, 359; 358, identifier:result; 359, integer:4; 360, subscript; 360, 361; 360, 362; 361, identifier:result; 362, integer:5; 363, subscript; 363, 364; 363, 365; 364, identifier:result; 365, integer:6; 366, comment; 367, comment; 368, else_clause; 368, 369; 369, block; 369, 370; 370, return_statement; 370, 371; 371, expression_list; 371, 372; 371, 375; 371, 378; 371, 381; 371, 384; 371, 387; 372, subscript; 372, 373; 372, 374; 373, identifier:result; 374, integer:0; 375, subscript; 375, 376; 375, 377; 376, identifier:result; 377, integer:1; 378, subscript; 378, 379; 378, 380; 379, identifier:result; 380, integer:2; 381, subscript; 381, 382; 381, 383; 382, identifier:result; 383, integer:3; 384, subscript; 384, 385; 384, 386; 385, identifier:result; 386, integer:4; 387, subscript; 387, 388; 387, 389; 388, identifier:result; 389, integer:5
def ordqz(A, B, sort='lhp', output='real', overwrite_a=False, overwrite_b=False, check_finite=True): """ QZ decomposition for a pair of matrices with reordering. .. versionadded:: 0.17.0 Parameters ---------- A : (N, N) array_like 2d array to decompose B : (N, N) array_like 2d array to decompose sort : {callable, 'lhp', 'rhp', 'iuc', 'ouc'}, optional Specifies whether the upper eigenvalues should be sorted. A callable may be passed that, given a eigenvalue, returns a boolean denoting whether the eigenvalue should be sorted to the top-left (True). For real matrix pairs, the sort function takes three real arguments (alphar, alphai, beta). The eigenvalue ``x = (alphar + alphai*1j)/beta``. For complex matrix pairs or output='complex', the sort function takes two complex arguments (alpha, beta). The eigenvalue ``x = (alpha/beta)``. Alternatively, string parameters may be used: - 'lhp' Left-hand plane (x.real < 0.0) - 'rhp' Right-hand plane (x.real > 0.0) - 'iuc' Inside the unit circle (x*x.conjugate() < 1.0) - 'ouc' Outside the unit circle (x*x.conjugate() > 1.0) output : str {'real','complex'}, optional Construct the real or complex QZ decomposition for real matrices. Default is 'real'. overwrite_a : bool, optional If True, the contents of A are overwritten. overwrite_b : bool, optional If True, the contents of B are overwritten. check_finite : bool, optional If true checks the elements of `A` and `B` are finite numbers. If false does no checking and passes matrix through to underlying algorithm. Returns ------- AA : (N, N) ndarray Generalized Schur form of A. BB : (N, N) ndarray Generalized Schur form of B. alpha : (N,) ndarray alpha = alphar + alphai * 1j. See notes. beta : (N,) ndarray See notes. Q : (N, N) ndarray The left Schur vectors. Z : (N, N) ndarray The right Schur vectors. Notes ----- On exit, ``(ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N``, will be the generalized eigenvalues. ``ALPHAR(j) + ALPHAI(j)*i`` and ``BETA(j),j=1,...,N`` are the diagonals of the complex Schur form (S,T) that would result if the 2-by-2 diagonal blocks of the real generalized Schur form of (A,B) were further reduced to triangular form using complex unitary transformations. If ALPHAI(j) is zero, then the j-th eigenvalue is real; if positive, then the ``j``-th and ``(j+1)``-st eigenvalues are a complex conjugate pair, with ``ALPHAI(j+1)`` negative. See also -------- qz """ import warnings import numpy as np from numpy import asarray_chkfinite from scipy.linalg.misc import LinAlgError, _datacopied from scipy.linalg.lapack import get_lapack_funcs from scipy._lib.six import callable from scipy.linalg._decomp_qz import _qz, _select_function #NOTE: should users be able to set these? lwork = None result, typ = _qz(A, B, output=output, lwork=lwork, sort=None, overwrite_a=overwrite_a, overwrite_b=overwrite_b, check_finite=check_finite) AA, BB, Q, Z = result[0], result[1], result[-4], result[-3] if typ not in 'cz': alpha, beta = result[3] + result[4]*1.j, result[5] else: alpha, beta = result[3], result[4] sfunction = _select_function(sort) select = sfunction(alpha, beta) tgsen, = get_lapack_funcs(('tgsen',), (AA, BB)) if lwork is None or lwork == -1: result = tgsen(select, AA, BB, Q, Z, lwork=-1) lwork = result[-3][0].real.astype(np.int) # looks like wrong value passed to ZTGSYL if not lwork += 1 liwork = None if liwork is None or liwork == -1: result = tgsen(select, AA, BB, Q, Z, liwork=-1) liwork = result[-2][0] result = tgsen(select, AA, BB, Q, Z, lwork=lwork, liwork=liwork) info = result[-1] if info < 0: raise ValueError("Illegal value in argument %d of tgsen" % -info) elif info == 1: raise ValueError("Reordering of (A, B) failed because the transformed" " matrix pair (A, B) would be too far from " "generalized Schur form; the problem is very " "ill-conditioned. (A, B) may have been partially " "reorded. If requested, 0 is returned in DIF(*), " "PL, and PR.") # for real results has a, b, alphar, alphai, beta, q, z, m, pl, pr, dif, # work, iwork, info if typ in ['f', 'd']: alpha = result[2] + result[3] * 1.j return (result[0], result[1], alpha, result[4], result[5], result[6]) # for complex results has a, b, alpha, beta, q, z, m, pl, pr, dif, work, # iwork, info else: return result[0], result[1], result[2], result[3], result[4], result[5]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:inverse_cdf; 3, parameters; 3, 4; 3, 5; 4, identifier:su; 5, identifier:W; 6, block; 6, 7; 6, 9; 6, 13; 6, 19; 6, 27; 6, 37; 6, 67; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:j; 12, integer:0; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:s; 16, subscript; 16, 17; 16, 18; 17, identifier:W; 18, integer:0; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:M; 22, subscript; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:su; 25, identifier:shape; 26, integer:0; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:A; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:np; 33, identifier:empty; 34, argument_list; 34, 35; 34, 36; 35, identifier:M; 36, string:'int'; 37, for_statement; 37, 38; 37, 39; 37, 43; 38, identifier:n; 39, call; 39, 40; 39, 41; 40, identifier:range; 41, argument_list; 41, 42; 42, identifier:M; 43, block; 43, 44; 43, 61; 44, while_statement; 44, 45; 44, 50; 45, comparison_operator:>; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:su; 48, identifier:n; 49, identifier:s; 50, block; 50, 51; 50, 55; 51, expression_statement; 51, 52; 52, augmented_assignment:+=; 52, 53; 52, 54; 53, identifier:j; 54, integer:1; 55, expression_statement; 55, 56; 56, augmented_assignment:+=; 56, 57; 56, 58; 57, identifier:s; 58, subscript; 58, 59; 58, 60; 59, identifier:W; 60, identifier:j; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:A; 65, identifier:n; 66, identifier:j; 67, return_statement; 67, 68; 68, identifier:A
def inverse_cdf(su, W): """Inverse CDF algorithm for a finite distribution. Parameters ---------- su: (M,) ndarray M sorted uniform variates (i.e. M ordered points in [0,1]). W: (N,) ndarray a vector of N normalized weights (>=0 and sum to one) Returns ------- A: (M,) ndarray a vector of M indices in range 0, ..., N-1 """ j = 0 s = W[0] M = su.shape[0] A = np.empty(M, 'int') for n in range(M): while su[n] > s: j += 1 s += W[j] A[n] = j return A
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_items; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:items; 6, default_parameter; 6, 7; 6, 8; 7, identifier:args; 8, False; 9, block; 9, 10; 9, 12; 9, 26; 9, 35; 9, 111; 9, 127; 9, 256; 9, 272; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 24; 13, comparison_operator:==; 13, 14; 13, 23; 14, call; 14, 15; 14, 22; 15, attribute; 15, 16; 15, 21; 16, subscript; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:settings; 20, string:'sort'; 21, identifier:lower; 22, argument_list; 23, string:'src'; 24, block; 24, 25; 25, return_statement; 26, function_definition; 26, 27; 26, 28; 26, 30; 27, function_name:alpha; 28, parameters; 28, 29; 29, identifier:i; 30, block; 30, 31; 31, return_statement; 31, 32; 32, attribute; 32, 33; 32, 34; 33, identifier:i; 34, identifier:name; 35, function_definition; 35, 36; 35, 37; 35, 39; 36, function_name:permission; 37, parameters; 37, 38; 38, identifier:i; 39, block; 39, 40; 39, 79; 39, 88; 39, 95; 39, 102; 39, 109; 40, if_statement; 40, 41; 40, 42; 41, identifier:args; 42, block; 42, 43; 42, 52; 42, 61; 42, 70; 43, if_statement; 43, 44; 43, 49; 44, comparison_operator:==; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:i; 47, identifier:intent; 48, string:'in'; 49, block; 49, 50; 50, return_statement; 50, 51; 51, string:'b'; 52, if_statement; 52, 53; 52, 58; 53, comparison_operator:==; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:i; 56, identifier:intent; 57, string:'inout'; 58, block; 58, 59; 59, return_statement; 59, 60; 60, string:'c'; 61, if_statement; 61, 62; 61, 67; 62, comparison_operator:==; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:i; 65, identifier:intent; 66, string:'out'; 67, block; 67, 68; 68, return_statement; 68, 69; 69, string:'d'; 70, if_statement; 70, 71; 70, 76; 71, comparison_operator:==; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:i; 74, identifier:intent; 75, string:''; 76, block; 76, 77; 77, return_statement; 77, 78; 78, string:'e'; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:perm; 82, call; 82, 83; 82, 84; 83, identifier:getattr; 84, argument_list; 84, 85; 84, 86; 84, 87; 85, identifier:i; 86, string:'permission'; 87, string:''; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:==; 89, 90; 89, 91; 90, identifier:perm; 91, string:'public'; 92, block; 92, 93; 93, return_statement; 93, 94; 94, string:'b'; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:==; 96, 97; 96, 98; 97, identifier:perm; 98, string:'protected'; 99, block; 99, 100; 100, return_statement; 100, 101; 101, string:'c'; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:==; 103, 104; 103, 105; 104, identifier:perm; 105, string:'private'; 106, block; 106, 107; 107, return_statement; 107, 108; 108, string:'d'; 109, return_statement; 109, 110; 110, string:'a'; 111, function_definition; 111, 112; 111, 113; 111, 115; 112, function_name:permission_alpha; 113, parameters; 113, 114; 114, identifier:i; 115, block; 115, 116; 116, return_statement; 116, 117; 117, binary_operator:+; 117, 118; 117, 124; 118, binary_operator:+; 118, 119; 118, 123; 119, call; 119, 120; 119, 121; 120, identifier:permission; 121, argument_list; 121, 122; 122, identifier:i; 123, string:'-'; 124, attribute; 124, 125; 124, 126; 125, identifier:i; 126, identifier:name; 127, function_definition; 127, 128; 127, 129; 127, 131; 128, function_name:itype; 129, parameters; 129, 130; 130, identifier:i; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 138; 132, 209; 132, 250; 133, comparison_operator:==; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:i; 136, identifier:obj; 137, string:'variable'; 138, block; 138, 139; 138, 145; 138, 154; 138, 172; 138, 190; 138, 207; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:retstr; 142, attribute; 142, 143; 142, 144; 143, identifier:i; 144, identifier:vartype; 145, if_statement; 145, 146; 145, 149; 146, comparison_operator:==; 146, 147; 146, 148; 147, identifier:retstr; 148, string:'class'; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:retstr; 153, string:'type'; 154, if_statement; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:i; 157, identifier:kind; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:retstr; 162, binary_operator:+; 162, 163; 162, 166; 163, binary_operator:+; 163, 164; 163, 165; 164, identifier:retstr; 165, string:'-'; 166, call; 166, 167; 166, 168; 167, identifier:str; 168, argument_list; 168, 169; 169, attribute; 169, 170; 169, 171; 170, identifier:i; 171, identifier:kind; 172, if_statement; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:i; 175, identifier:strlen; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:retstr; 180, binary_operator:+; 180, 181; 180, 184; 181, binary_operator:+; 181, 182; 181, 183; 182, identifier:retstr; 183, string:'-'; 184, call; 184, 185; 184, 186; 185, identifier:str; 186, argument_list; 186, 187; 187, attribute; 187, 188; 187, 189; 188, identifier:i; 189, identifier:strlen; 190, if_statement; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:i; 193, identifier:proto; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:retstr; 198, binary_operator:+; 198, 199; 198, 202; 199, binary_operator:+; 199, 200; 199, 201; 200, identifier:retstr; 201, string:'-'; 202, subscript; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:i; 205, identifier:proto; 206, integer:0; 207, return_statement; 207, 208; 208, identifier:retstr; 209, elif_clause; 209, 210; 209, 215; 210, comparison_operator:==; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:i; 213, identifier:obj; 214, string:'proc'; 215, block; 215, 216; 216, if_statement; 216, 217; 216, 222; 216, 231; 217, comparison_operator:!=; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:i; 220, identifier:proctype; 221, string:'Function'; 222, block; 222, 223; 223, return_statement; 223, 224; 224, call; 224, 225; 224, 230; 225, attribute; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:i; 228, identifier:proctype; 229, identifier:lower; 230, argument_list; 231, else_clause; 231, 232; 232, block; 232, 233; 233, return_statement; 233, 234; 234, binary_operator:+; 234, 235; 234, 244; 235, binary_operator:+; 235, 236; 235, 243; 236, call; 236, 237; 236, 242; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:i; 240, identifier:proctype; 241, identifier:lower; 242, argument_list; 243, string:'-'; 244, call; 244, 245; 244, 246; 245, identifier:itype; 246, argument_list; 246, 247; 247, attribute; 247, 248; 247, 249; 248, identifier:i; 249, identifier:retvar; 250, else_clause; 250, 251; 251, block; 251, 252; 252, return_statement; 252, 253; 253, attribute; 253, 254; 253, 255; 254, identifier:i; 255, identifier:obj; 256, function_definition; 256, 257; 256, 258; 256, 260; 257, function_name:itype_alpha; 258, parameters; 258, 259; 259, identifier:i; 260, block; 260, 261; 261, return_statement; 261, 262; 262, binary_operator:+; 262, 263; 262, 269; 263, binary_operator:+; 263, 264; 263, 268; 264, call; 264, 265; 264, 266; 265, identifier:itype; 266, argument_list; 266, 267; 267, identifier:i; 268, string:'-'; 269, attribute; 269, 270; 269, 271; 270, identifier:i; 271, identifier:name; 272, if_statement; 272, 273; 272, 284; 272, 294; 272, 316; 272, 338; 272, 360; 273, comparison_operator:==; 273, 274; 273, 283; 274, call; 274, 275; 274, 282; 275, attribute; 275, 276; 275, 281; 276, subscript; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:settings; 280, string:'sort'; 281, identifier:lower; 282, argument_list; 283, string:'alpha'; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:items; 289, identifier:sort; 290, argument_list; 290, 291; 291, keyword_argument; 291, 292; 291, 293; 292, identifier:key; 293, identifier:alpha; 294, elif_clause; 294, 295; 294, 306; 295, comparison_operator:==; 295, 296; 295, 305; 296, call; 296, 297; 296, 304; 297, attribute; 297, 298; 297, 303; 298, subscript; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:settings; 302, string:'sort'; 303, identifier:lower; 304, argument_list; 305, string:'permission'; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:items; 311, identifier:sort; 312, argument_list; 312, 313; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:key; 315, identifier:permission; 316, elif_clause; 316, 317; 316, 328; 317, comparison_operator:==; 317, 318; 317, 327; 318, call; 318, 319; 318, 326; 319, attribute; 319, 320; 319, 325; 320, subscript; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:settings; 324, string:'sort'; 325, identifier:lower; 326, argument_list; 327, string:'permission-alpha'; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:items; 333, identifier:sort; 334, argument_list; 334, 335; 335, keyword_argument; 335, 336; 335, 337; 336, identifier:key; 337, identifier:permission_alpha; 338, elif_clause; 338, 339; 338, 350; 339, comparison_operator:==; 339, 340; 339, 349; 340, call; 340, 341; 340, 348; 341, attribute; 341, 342; 341, 347; 342, subscript; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:self; 345, identifier:settings; 346, string:'sort'; 347, identifier:lower; 348, argument_list; 349, string:'type'; 350, block; 350, 351; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:items; 355, identifier:sort; 356, argument_list; 356, 357; 357, keyword_argument; 357, 358; 357, 359; 358, identifier:key; 359, identifier:itype; 360, elif_clause; 360, 361; 360, 372; 361, comparison_operator:==; 361, 362; 361, 371; 362, call; 362, 363; 362, 370; 363, attribute; 363, 364; 363, 369; 364, subscript; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:self; 367, identifier:settings; 368, string:'sort'; 369, identifier:lower; 370, argument_list; 371, string:'type-alpha'; 372, block; 372, 373; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:items; 377, identifier:sort; 378, argument_list; 378, 379; 379, keyword_argument; 379, 380; 379, 381; 380, identifier:key; 381, identifier:itype_alpha
def sort_items(self,items,args=False): """ Sort the `self`'s contents, as contained in the list `items` as specified in `self`'s meta-data. """ if self.settings['sort'].lower() == 'src': return def alpha(i): return i.name def permission(i): if args: if i.intent == 'in': return 'b' if i.intent == 'inout': return 'c' if i.intent == 'out': return 'd' if i.intent == '': return 'e' perm = getattr(i, 'permission', '') if perm == 'public': return 'b' if perm == 'protected': return 'c' if perm == 'private': return 'd' return 'a' def permission_alpha(i): return permission(i) + '-' + i.name def itype(i): if i.obj == 'variable': retstr = i.vartype if retstr == 'class': retstr = 'type' if i.kind: retstr = retstr + '-' + str(i.kind) if i.strlen: retstr = retstr + '-' + str(i.strlen) if i.proto: retstr = retstr + '-' + i.proto[0] return retstr elif i.obj == 'proc': if i.proctype != 'Function': return i.proctype.lower() else: return i.proctype.lower() + '-' + itype(i.retvar) else: return i.obj def itype_alpha(i): return itype(i) + '-' + i.name if self.settings['sort'].lower() == 'alpha': items.sort(key=alpha) elif self.settings['sort'].lower() == 'permission': items.sort(key=permission) elif self.settings['sort'].lower() == 'permission-alpha': items.sort(key=permission_alpha) elif self.settings['sort'].lower() == 'type': items.sort(key=itype) elif self.settings['sort'].lower() == 'type-alpha': items.sort(key=itype_alpha)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 23; 5, 38; 5, 53; 5, 68; 5, 83; 5, 98; 5, 113; 5, 128; 5, 143; 5, 158; 5, 173; 5, 188; 5, 203; 5, 218; 6, expression_statement; 6, 7; 7, string:''' Sorts components of the object. '''; 8, if_statement; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:hasattr; 11, argument_list; 11, 12; 11, 13; 12, identifier:self; 13, string:'variables'; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:sort_items; 18, argument_list; 18, 19; 18, 20; 19, identifier:self; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:variables; 23, if_statement; 23, 24; 23, 29; 24, call; 24, 25; 24, 26; 25, identifier:hasattr; 26, argument_list; 26, 27; 26, 28; 27, identifier:self; 28, string:'modules'; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:sort_items; 33, argument_list; 33, 34; 33, 35; 34, identifier:self; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:modules; 38, if_statement; 38, 39; 38, 44; 39, call; 39, 40; 39, 41; 40, identifier:hasattr; 41, argument_list; 41, 42; 41, 43; 42, identifier:self; 43, string:'submodules'; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:sort_items; 48, argument_list; 48, 49; 48, 50; 49, identifier:self; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:submodules; 53, if_statement; 53, 54; 53, 59; 54, call; 54, 55; 54, 56; 55, identifier:hasattr; 56, argument_list; 56, 57; 56, 58; 57, identifier:self; 58, string:'common'; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:sort_items; 63, argument_list; 63, 64; 63, 65; 64, identifier:self; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:common; 68, if_statement; 68, 69; 68, 74; 69, call; 69, 70; 69, 71; 70, identifier:hasattr; 71, argument_list; 71, 72; 71, 73; 72, identifier:self; 73, string:'subroutines'; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:sort_items; 78, argument_list; 78, 79; 78, 80; 79, identifier:self; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:subroutines; 83, if_statement; 83, 84; 83, 89; 84, call; 84, 85; 84, 86; 85, identifier:hasattr; 86, argument_list; 86, 87; 86, 88; 87, identifier:self; 88, string:'modprocedures'; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:sort_items; 93, argument_list; 93, 94; 93, 95; 94, identifier:self; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:modprocedures; 98, if_statement; 98, 99; 98, 104; 99, call; 99, 100; 99, 101; 100, identifier:hasattr; 101, argument_list; 101, 102; 101, 103; 102, identifier:self; 103, string:'functions'; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:sort_items; 108, argument_list; 108, 109; 108, 110; 109, identifier:self; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:functions; 113, if_statement; 113, 114; 113, 119; 114, call; 114, 115; 114, 116; 115, identifier:hasattr; 116, argument_list; 116, 117; 116, 118; 117, identifier:self; 118, string:'interfaces'; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:sort_items; 123, argument_list; 123, 124; 123, 125; 124, identifier:self; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:interfaces; 128, if_statement; 128, 129; 128, 134; 129, call; 129, 130; 129, 131; 130, identifier:hasattr; 131, argument_list; 131, 132; 131, 133; 132, identifier:self; 133, string:'absinterfaces'; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:sort_items; 138, argument_list; 138, 139; 138, 140; 139, identifier:self; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:absinterfaces; 143, if_statement; 143, 144; 143, 149; 144, call; 144, 145; 144, 146; 145, identifier:hasattr; 146, argument_list; 146, 147; 146, 148; 147, identifier:self; 148, string:'types'; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:sort_items; 153, argument_list; 153, 154; 153, 155; 154, identifier:self; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:types; 158, if_statement; 158, 159; 158, 164; 159, call; 159, 160; 159, 161; 160, identifier:hasattr; 161, argument_list; 161, 162; 161, 163; 162, identifier:self; 163, string:'programs'; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:sort_items; 168, argument_list; 168, 169; 168, 170; 169, identifier:self; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:programs; 173, if_statement; 173, 174; 173, 179; 174, call; 174, 175; 174, 176; 175, identifier:hasattr; 176, argument_list; 176, 177; 176, 178; 177, identifier:self; 178, string:'blockdata'; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:sort_items; 183, argument_list; 183, 184; 183, 185; 184, identifier:self; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:blockdata; 188, if_statement; 188, 189; 188, 194; 189, call; 189, 190; 189, 191; 190, identifier:hasattr; 191, argument_list; 191, 192; 191, 193; 192, identifier:self; 193, string:'boundprocs'; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 198; 197, identifier:sort_items; 198, argument_list; 198, 199; 198, 200; 199, identifier:self; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:boundprocs; 203, if_statement; 203, 204; 203, 209; 204, call; 204, 205; 204, 206; 205, identifier:hasattr; 206, argument_list; 206, 207; 206, 208; 207, identifier:self; 208, string:'finalprocs'; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 213; 212, identifier:sort_items; 213, argument_list; 213, 214; 213, 215; 214, identifier:self; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:finalprocs; 218, if_statement; 218, 219; 218, 224; 218, 225; 219, call; 219, 220; 219, 221; 220, identifier:hasattr; 221, argument_list; 221, 222; 221, 223; 222, identifier:self; 223, string:'args'; 224, comment; 225, block; 225, 226; 226, pass_statement
def sort(self): ''' Sorts components of the object. ''' if hasattr(self,'variables'): sort_items(self,self.variables) if hasattr(self,'modules'): sort_items(self,self.modules) if hasattr(self,'submodules'): sort_items(self,self.submodules) if hasattr(self,'common'): sort_items(self,self.common) if hasattr(self,'subroutines'): sort_items(self,self.subroutines) if hasattr(self,'modprocedures'): sort_items(self,self.modprocedures) if hasattr(self,'functions'): sort_items(self,self.functions) if hasattr(self,'interfaces'): sort_items(self,self.interfaces) if hasattr(self,'absinterfaces'): sort_items(self,self.absinterfaces) if hasattr(self,'types'): sort_items(self,self.types) if hasattr(self,'programs'): sort_items(self,self.programs) if hasattr(self,'blockdata'): sort_items(self,self.blockdata) if hasattr(self,'boundprocs'): sort_items(self,self.boundprocs) if hasattr(self,'finalprocs'): sort_items(self,self.finalprocs) if hasattr(self,'args'): #sort_items(self.args,args=True) pass
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_catalogue_chronologically; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 25; 5, 49; 6, expression_statement; 6, 7; 7, string:''' Sorts the catalogue into chronological order '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:dec_time; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:get_decimal_time; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:idx; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:np; 22, identifier:argsort; 23, argument_list; 23, 24; 24, identifier:dec_time; 25, if_statement; 25, 26; 25, 46; 25, 47; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:np; 29, identifier:all; 30, argument_list; 30, 31; 31, comparison_operator:>; 31, 32; 31, 45; 32, parenthesized_expression; 32, 33; 33, binary_operator:-; 33, 34; 33, 39; 34, subscript; 34, 35; 34, 36; 35, identifier:idx; 36, slice; 36, 37; 36, 38; 37, integer:1; 38, colon; 39, subscript; 39, 40; 39, 41; 40, identifier:idx; 41, slice; 41, 42; 41, 43; 42, colon; 43, unary_operator:-; 43, 44; 44, integer:1; 45, float:0.; 46, comment; 47, block; 47, 48; 48, return_statement; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:select_catalogue_events; 54, argument_list; 54, 55; 55, identifier:idx
def sort_catalogue_chronologically(self): ''' Sorts the catalogue into chronological order ''' dec_time = self.get_decimal_time() idx = np.argsort(dec_time) if np.all((idx[1:] - idx[:-1]) > 0.): # Catalogue was already in chronological order return self.select_catalogue_events(idx)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:cmp_mat; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, identifier:b; 6, block; 6, 7; 6, 9; 6, 13; 6, 48; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:c; 12, integer:0; 13, for_statement; 13, 14; 13, 17; 13, 26; 14, pattern_list; 14, 15; 14, 16; 15, identifier:x; 16, identifier:y; 17, call; 17, 18; 17, 19; 18, identifier:zip; 19, argument_list; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:a; 22, identifier:flat; 23, attribute; 23, 24; 23, 25; 24, identifier:b; 25, identifier:flat; 26, block; 26, 27; 26, 41; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:c; 30, call; 30, 31; 30, 32; 31, identifier:cmp; 32, argument_list; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:abs; 35, argument_list; 35, 36; 36, identifier:x; 37, call; 37, 38; 37, 39; 38, identifier:abs; 39, argument_list; 39, 40; 40, identifier:y; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:!=; 42, 43; 42, 44; 43, identifier:c; 44, integer:0; 45, block; 45, 46; 46, return_statement; 46, 47; 47, identifier:c; 48, return_statement; 48, 49; 49, identifier:c
def cmp_mat(a, b): """ Sorts two matrices returning a positive or zero value """ c = 0 for x, y in zip(a.flat, b.flat): c = cmp(abs(x), abs(y)) if c != 0: return c return c
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_dicoms; 3, parameters; 3, 4; 4, identifier:dicoms; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 11; 5, 12; 5, 30; 5, 48; 5, 66; 5, 88; 5, 110; 5, 132; 5, 143; 5, 154; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:dicom_input_sorted_x; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 19; 18, identifier:dicoms; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:key; 21, lambda; 21, 22; 21, 24; 22, lambda_parameters; 22, 23; 23, identifier:x; 24, parenthesized_expression; 24, 25; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:x; 28, identifier:ImagePositionPatient; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:dicom_input_sorted_y; 33, call; 33, 34; 33, 35; 34, identifier:sorted; 35, argument_list; 35, 36; 35, 37; 36, identifier:dicoms; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, lambda; 39, 40; 39, 42; 40, lambda_parameters; 40, 41; 41, identifier:x; 42, parenthesized_expression; 42, 43; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:x; 46, identifier:ImagePositionPatient; 47, integer:1; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:dicom_input_sorted_z; 51, call; 51, 52; 51, 53; 52, identifier:sorted; 53, argument_list; 53, 54; 53, 55; 54, identifier:dicoms; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:key; 57, lambda; 57, 58; 57, 60; 58, lambda_parameters; 58, 59; 59, identifier:x; 60, parenthesized_expression; 60, 61; 61, subscript; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:x; 64, identifier:ImagePositionPatient; 65, integer:2; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:diff_x; 69, call; 69, 70; 69, 71; 70, identifier:abs; 71, argument_list; 71, 72; 72, binary_operator:-; 72, 73; 72, 81; 73, subscript; 73, 74; 73, 80; 74, attribute; 74, 75; 74, 79; 75, subscript; 75, 76; 75, 77; 76, identifier:dicom_input_sorted_x; 77, unary_operator:-; 77, 78; 78, integer:1; 79, identifier:ImagePositionPatient; 80, integer:0; 81, subscript; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:dicom_input_sorted_x; 85, integer:0; 86, identifier:ImagePositionPatient; 87, integer:0; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:diff_y; 91, call; 91, 92; 91, 93; 92, identifier:abs; 93, argument_list; 93, 94; 94, binary_operator:-; 94, 95; 94, 103; 95, subscript; 95, 96; 95, 102; 96, attribute; 96, 97; 96, 101; 97, subscript; 97, 98; 97, 99; 98, identifier:dicom_input_sorted_y; 99, unary_operator:-; 99, 100; 100, integer:1; 101, identifier:ImagePositionPatient; 102, integer:1; 103, subscript; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:dicom_input_sorted_y; 107, integer:0; 108, identifier:ImagePositionPatient; 109, integer:1; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:diff_z; 113, call; 113, 114; 113, 115; 114, identifier:abs; 115, argument_list; 115, 116; 116, binary_operator:-; 116, 117; 116, 125; 117, subscript; 117, 118; 117, 124; 118, attribute; 118, 119; 118, 123; 119, subscript; 119, 120; 119, 121; 120, identifier:dicom_input_sorted_z; 121, unary_operator:-; 121, 122; 122, integer:1; 123, identifier:ImagePositionPatient; 124, integer:2; 125, subscript; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:dicom_input_sorted_z; 129, integer:0; 130, identifier:ImagePositionPatient; 131, integer:2; 132, if_statement; 132, 133; 132, 140; 133, boolean_operator:and; 133, 134; 133, 137; 134, comparison_operator:>=; 134, 135; 134, 136; 135, identifier:diff_x; 136, identifier:diff_y; 137, comparison_operator:>=; 137, 138; 137, 139; 138, identifier:diff_x; 139, identifier:diff_z; 140, block; 140, 141; 141, return_statement; 141, 142; 142, identifier:dicom_input_sorted_x; 143, if_statement; 143, 144; 143, 151; 144, boolean_operator:and; 144, 145; 144, 148; 145, comparison_operator:>=; 145, 146; 145, 147; 146, identifier:diff_y; 147, identifier:diff_x; 148, comparison_operator:>=; 148, 149; 148, 150; 149, identifier:diff_y; 150, identifier:diff_z; 151, block; 151, 152; 152, return_statement; 152, 153; 153, identifier:dicom_input_sorted_y; 154, if_statement; 154, 155; 154, 162; 155, boolean_operator:and; 155, 156; 155, 159; 156, comparison_operator:>=; 156, 157; 156, 158; 157, identifier:diff_z; 158, identifier:diff_x; 159, comparison_operator:>=; 159, 160; 159, 161; 160, identifier:diff_z; 161, identifier:diff_y; 162, block; 162, 163; 163, return_statement; 163, 164; 164, identifier:dicom_input_sorted_z
def sort_dicoms(dicoms): """ Sort the dicoms based om the image possition patient :param dicoms: list of dicoms """ # find most significant axis to use during sorting # the original way of sorting (first x than y than z) does not work in certain border situations # where for exampe the X will only slightly change causing the values to remain equal on multiple slices # messing up the sorting completely) dicom_input_sorted_x = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[0])) dicom_input_sorted_y = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[1])) dicom_input_sorted_z = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[2])) diff_x = abs(dicom_input_sorted_x[-1].ImagePositionPatient[0] - dicom_input_sorted_x[0].ImagePositionPatient[0]) diff_y = abs(dicom_input_sorted_y[-1].ImagePositionPatient[1] - dicom_input_sorted_y[0].ImagePositionPatient[1]) diff_z = abs(dicom_input_sorted_z[-1].ImagePositionPatient[2] - dicom_input_sorted_z[0].ImagePositionPatient[2]) if diff_x >= diff_y and diff_x >= diff_z: return dicom_input_sorted_x if diff_y >= diff_x and diff_y >= diff_z: return dicom_input_sorted_y if diff_z >= diff_x and diff_z >= diff_y: return dicom_input_sorted_z
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_sorted_mosaics; 3, parameters; 3, 4; 4, identifier:dicom_input; 5, block; 5, 6; 5, 8; 5, 9; 5, 24; 5, 58; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sorted_mosaics; 12, call; 12, 13; 12, 14; 13, identifier:sorted; 14, argument_list; 14, 15; 14, 16; 15, identifier:dicom_input; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:key; 18, lambda; 18, 19; 18, 21; 19, lambda_parameters; 19, 20; 20, identifier:x; 21, attribute; 21, 22; 21, 23; 22, identifier:x; 23, identifier:AcquisitionNumber; 24, for_statement; 24, 25; 24, 26; 24, 36; 24, 37; 25, identifier:index; 26, call; 26, 27; 26, 28; 27, identifier:range; 28, argument_list; 28, 29; 28, 30; 29, integer:0; 30, binary_operator:-; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:sorted_mosaics; 35, integer:1; 36, comment; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 52; 39, comparison_operator:>=; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:sorted_mosaics; 43, identifier:index; 44, identifier:AcquisitionNumber; 45, attribute; 45, 46; 45, 51; 46, subscript; 46, 47; 46, 48; 47, identifier:sorted_mosaics; 48, binary_operator:+; 48, 49; 48, 50; 49, identifier:index; 50, integer:1; 51, identifier:AcquisitionNumber; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:ConversionValidationError; 56, argument_list; 56, 57; 57, string:"INCONSISTENT_ACQUISITION_NUMBERS"; 58, return_statement; 58, 59; 59, identifier:sorted_mosaics
def _get_sorted_mosaics(dicom_input): """ Search all mosaics in the dicom directory, sort and validate them """ # Order all dicom files by acquisition number sorted_mosaics = sorted(dicom_input, key=lambda x: x.AcquisitionNumber) for index in range(0, len(sorted_mosaics) - 1): # Validate that there are no duplicate AcquisitionNumber if sorted_mosaics[index].AcquisitionNumber >= sorted_mosaics[index + 1].AcquisitionNumber: raise ConversionValidationError("INCONSISTENT_ACQUISITION_NUMBERS") return sorted_mosaics
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:relate_obs_ids_to_chosen_alts; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:obs_id_array; 5, identifier:alt_id_array; 6, identifier:choice_array; 7, block; 7, 8; 7, 10; 7, 11; 7, 15; 7, 68; 7, 69; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:chosen_alts_to_obs_ids; 14, dictionary; 15, for_statement; 15, 16; 15, 17; 15, 28; 15, 29; 16, identifier:alt_id; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:np; 20, identifier:sort; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:np; 25, identifier:unique; 26, argument_list; 26, 27; 27, identifier:alt_id_array; 28, comment; 29, block; 29, 30; 29, 48; 29, 49; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 31, 34; 32, identifier:selection_condition; 33, line_continuation:\; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:np; 37, identifier:where; 38, argument_list; 38, 39; 39, binary_operator:&; 39, 40; 39, 44; 40, parenthesized_expression; 40, 41; 41, comparison_operator:==; 41, 42; 41, 43; 42, identifier:alt_id_array; 43, identifier:alt_id; 44, parenthesized_expression; 44, 45; 45, comparison_operator:==; 45, 46; 45, 47; 46, identifier:choice_array; 47, integer:1; 48, comment; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 50, 55; 51, subscript; 51, 52; 51, 53; 52, identifier:chosen_alts_to_obs_ids; 53, identifier:alt_id; 54, line_continuation:\; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:np; 58, identifier:sort; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:np; 63, identifier:unique; 64, argument_list; 64, 65; 65, subscript; 65, 66; 65, 67; 66, identifier:obs_id_array; 67, identifier:selection_condition; 68, comment; 69, return_statement; 69, 70; 70, identifier:chosen_alts_to_obs_ids
def relate_obs_ids_to_chosen_alts(obs_id_array, alt_id_array, choice_array): """ Creates a dictionary that relates each unique alternative id to the set of observations ids that chose the given alternative. Parameters ---------- obs_id_array : 1D ndarray of ints. Should be a long-format array of observation ids. Each element should correspond to the unique id of the unit of observation that corresponds to the given row of the long-format data. Note that each unit of observation may have more than one associated choice situation. alt_id_array : 1D ndarray of ints. Should be a long-format array of alternative ids. Each element should denote the unique id of the alternative that corresponds to the given row of the long format data. choice_array : 1D ndarray of ints. Each element should be either a one or a zero, indicating whether the alternative on the given row of the long format data was chosen or not. Returns ------- chosen_alts_to_obs_ids : dict. Each key will be a unique value from `alt_id_array`. Each key's value will be a 1D ndarray that contains the sorted, unique observation ids of those observational units that chose the given alternative. """ # Figure out which units of observation chose each alternative. chosen_alts_to_obs_ids = {} for alt_id in np.sort(np.unique(alt_id_array)): # Determine which observations chose the current alternative. selection_condition =\ np.where((alt_id_array == alt_id) & (choice_array == 1)) # Store the sorted, unique ids that chose the current alternative. chosen_alts_to_obs_ids[alt_id] =\ np.sort(np.unique(obs_id_array[selection_condition])) # Return the desired dictionary. return chosen_alts_to_obs_ids
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:create_estimation_obj; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:model_obj; 5, identifier:init_vals; 6, default_parameter; 6, 7; 6, 8; 7, identifier:mappings; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:ridge; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:constrained_pos; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:weights; 17, None; 18, block; 18, 19; 18, 21; 18, 22; 18, 36; 18, 37; 18, 50; 18, 51; 18, 59; 18, 60; 18, 77; 18, 78; 18, 93; 18, 94; 19, expression_statement; 19, 20; 20, comment; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 23, 26; 24, identifier:mapping_matrices; 25, line_continuation:\; 26, conditional_expression:if; 26, 27; 26, 32; 26, 35; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:model_obj; 30, identifier:get_mappings_for_fit; 31, argument_list; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:mappings; 34, None; 35, identifier:mappings; 36, comment; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:zero_vector; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:np; 43, identifier:zeros; 44, argument_list; 44, 45; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:init_vals; 48, identifier:shape; 49, integer:0; 50, comment; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:internal_model_name; 54, subscript; 54, 55; 54, 56; 55, identifier:display_name_to_model_type; 56, attribute; 56, 57; 56, 58; 57, identifier:model_obj; 58, identifier:model_type; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 61, 66; 62, pattern_list; 62, 63; 62, 64; 63, identifier:estimator_class; 64, identifier:current_split_func; 65, line_continuation:\; 66, tuple; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:model_type_to_resources; 70, identifier:internal_model_name; 71, string:'estimator'; 72, subscript; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:model_type_to_resources; 75, identifier:internal_model_name; 76, string:'split_func'; 77, comment; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:estimation_obj; 81, call; 81, 82; 81, 83; 82, identifier:estimator_class; 83, argument_list; 83, 84; 83, 85; 83, 86; 83, 87; 83, 88; 83, 89; 83, 90; 84, identifier:model_obj; 85, identifier:mapping_matrices; 86, identifier:ridge; 87, identifier:zero_vector; 88, identifier:current_split_func; 89, identifier:constrained_pos; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:weights; 92, identifier:weights; 93, comment; 94, return_statement; 94, 95; 95, identifier:estimation_obj
def create_estimation_obj(model_obj, init_vals, mappings=None, ridge=None, constrained_pos=None, weights=None): """ Should return a model estimation object corresponding to the model type of the `model_obj`. Parameters ---------- model_obj : an instance or sublcass of the MNDC class. init_vals : 1D ndarray. The initial values to start the estimation process with. In the following order, there should be one value for each nest coefficient, shape parameter, outside intercept parameter, or index coefficient that is being estimated. mappings : OrderedDict or None, optional. Keys will be `["rows_to_obs", "rows_to_alts", "chosen_row_to_obs", "rows_to_nests"]`. The value for `rows_to_obs` will map the rows of the `long_form` to the unique observations (on the columns) in their order of appearance. The value for `rows_to_alts` will map the rows of the `long_form` to the unique alternatives which are possible in the dataset (on the columns), in sorted order--not order of appearance. The value for `chosen_row_to_obs`, if not None, will map the rows of the `long_form` that contain the chosen alternatives to the specific observations those rows are associated with (denoted by the columns). The value of `rows_to_nests`, if not None, will map the rows of the `long_form` to the nest (denoted by the column) that contains the row's alternative. Default == None. ridge : int, float, long, or None, optional. Determines whether or not ridge regression is performed. If a scalar is passed, then that scalar determines the ridge penalty for the optimization. The scalar should be greater than or equal to zero. Default `== None`. constrained_pos : list or None, optional. Denotes the positions of the array of estimated parameters that are not to change from their initial values. If a list is passed, the elements are to be integers where no such integer is greater than `init_vals.size.` Default == None. weights : 1D ndarray. Should contain the weights for each corresponding observation for each row of the long format data. """ # Get the mapping matrices for each model mapping_matrices =\ model_obj.get_mappings_for_fit() if mappings is None else mappings # Create the zero vector for each model. zero_vector = np.zeros(init_vals.shape[0]) # Get the internal model name internal_model_name = display_name_to_model_type[model_obj.model_type] # Get the split parameter function and estimator class for this model. estimator_class, current_split_func =\ (model_type_to_resources[internal_model_name]['estimator'], model_type_to_resources[internal_model_name]['split_func']) # Create the estimator instance that is desired. estimation_obj = estimator_class(model_obj, mapping_matrices, ridge, zero_vector, current_split_func, constrained_pos, weights=weights) # Return the created object return estimation_obj
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sequence; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 110; 6, expression_statement; 6, 7; 7, string:''' sort the points in the line with given option '''; 8, if_statement; 8, 9; 8, 20; 9, parenthesized_expression; 9, 10; 10, comparison_operator:==; 10, 11; 10, 19; 11, call; 11, 12; 11, 13; 12, identifier:len; 13, argument_list; 13, 14; 14, subscript; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:Points; 18, integer:0; 19, integer:2; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 34; 21, 60; 21, 99; 22, parenthesized_expression; 22, 23; 23, boolean_operator:or; 23, 24; 23, 29; 24, comparison_operator:==; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:Sort; 28, string:'X'; 29, comparison_operator:==; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:Sort; 33, string:'x'; 34, block; 34, 35; 34, 51; 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:self; 40, identifier:Points; 41, identifier:sort; 42, argument_list; 42, 43; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:key; 45, lambda; 45, 46; 45, 48; 46, lambda_parameters; 46, 47; 47, identifier:x; 48, subscript; 48, 49; 48, 50; 49, identifier:x; 50, integer:0; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:order; 56, argument_list; 56, 57; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:Points; 60, elif_clause; 60, 61; 60, 73; 61, parenthesized_expression; 61, 62; 62, boolean_operator:or; 62, 63; 62, 68; 63, comparison_operator:==; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:Sort; 67, string:'Y'; 68, comparison_operator:==; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:Sort; 72, string:'y'; 73, block; 73, 74; 73, 90; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:Points; 80, identifier:sort; 81, argument_list; 81, 82; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:key; 84, lambda; 84, 85; 84, 87; 85, lambda_parameters; 85, 86; 86, identifier:x; 87, subscript; 87, 88; 87, 89; 88, identifier:x; 89, integer:1; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:order; 95, argument_list; 95, 96; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:Points; 99, else_clause; 99, 100; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:order; 106, argument_list; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:Points; 110, if_statement; 110, 111; 110, 122; 111, parenthesized_expression; 111, 112; 112, comparison_operator:==; 112, 113; 112, 121; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, subscript; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:Points; 120, integer:0; 121, integer:3; 122, block; 122, 123; 123, if_statement; 123, 124; 123, 136; 123, 162; 123, 201; 123, 240; 124, parenthesized_expression; 124, 125; 125, boolean_operator:or; 125, 126; 125, 131; 126, comparison_operator:==; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:Sort; 130, string:'X'; 131, comparison_operator:==; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:Sort; 135, string:'x'; 136, block; 136, 137; 136, 153; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:Points; 143, identifier:sort; 144, argument_list; 144, 145; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:key; 147, lambda; 147, 148; 147, 150; 148, lambda_parameters; 148, 149; 149, identifier:x; 150, subscript; 150, 151; 150, 152; 151, identifier:x; 152, integer:0; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:order; 158, argument_list; 158, 159; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:Points; 162, elif_clause; 162, 163; 162, 175; 163, parenthesized_expression; 163, 164; 164, boolean_operator:or; 164, 165; 164, 170; 165, comparison_operator:==; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:Sort; 169, string:'Y'; 170, comparison_operator:==; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:Sort; 174, string:'y'; 175, block; 175, 176; 175, 192; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:Points; 182, identifier:sort; 183, argument_list; 183, 184; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:key; 186, lambda; 186, 187; 186, 189; 187, lambda_parameters; 187, 188; 188, identifier:x; 189, subscript; 189, 190; 189, 191; 190, identifier:x; 191, integer:1; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:order; 197, argument_list; 197, 198; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:Points; 201, elif_clause; 201, 202; 201, 214; 202, parenthesized_expression; 202, 203; 203, boolean_operator:or; 203, 204; 203, 209; 204, comparison_operator:==; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:Sort; 208, string:'Z'; 209, comparison_operator:==; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:Sort; 213, string:'Z'; 214, block; 214, 215; 214, 231; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 222; 217, attribute; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:Points; 221, identifier:sort; 222, argument_list; 222, 223; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:key; 225, lambda; 225, 226; 225, 228; 226, lambda_parameters; 226, 227; 227, identifier:x; 228, subscript; 228, 229; 228, 230; 229, identifier:x; 230, integer:2; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:order; 236, argument_list; 236, 237; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:Points; 240, else_clause; 240, 241; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:order; 247, argument_list; 247, 248; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:Points
def sequence(self): ''' sort the points in the line with given option ''' if (len(self.Points[0]) == 2): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) else: self.order(self.Points) if (len(self.Points[0]) == 3): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) elif (self.Sort == 'Z' or self.Sort == 'Z'): self.Points.sort(key=lambda x: x[2]) self.order(self.Points) else: self.order(self.Points)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_pos; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:key; 6, block; 6, 7; 6, 9; 6, 26; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:p; 12, call; 12, 13; 12, 14; 13, identifier:bisect; 14, argument_list; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:runtime; 19, identifier:_keys; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:hashi; 24, argument_list; 24, 25; 25, identifier:key; 26, if_statement; 26, 27; 26, 37; 26, 40; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:p; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:runtime; 36, identifier:_keys; 37, block; 37, 38; 38, return_statement; 38, 39; 39, integer:0; 40, else_clause; 40, 41; 41, block; 41, 42; 42, return_statement; 42, 43; 43, identifier:p
def _get_pos(self, key): """Get the index of the given key in the sorted key list. We return the position with the nearest hash based on the provided key unless we reach the end of the continuum/ring in which case we return the 0 (beginning) index position. :param key: the key to hash and look for. """ p = bisect(self.runtime._keys, self.hashi(key)) if p == len(self.runtime._keys): return 0 else: return p
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:lapmod; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 4, identifier:n; 5, identifier:cc; 6, identifier:ii; 7, identifier:kk; 8, default_parameter; 8, 9; 8, 10; 9, identifier:fast; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:return_cost; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:fp_version; 16, identifier:FP_DYNAMIC; 17, block; 17, 18; 17, 20; 17, 21; 17, 29; 17, 269; 18, expression_statement; 18, 19; 19, comment; 20, comment; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:check_cost; 24, argument_list; 24, 25; 24, 26; 24, 27; 24, 28; 25, identifier:n; 26, identifier:cc; 27, identifier:ii; 28, identifier:kk; 29, if_statement; 29, 30; 29, 33; 29, 34; 29, 50; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:fast; 32, True; 33, comment; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, pattern_list; 37, 38; 37, 39; 38, identifier:x; 39, identifier:y; 40, call; 40, 41; 40, 42; 41, identifier:_lapmod; 42, argument_list; 42, 43; 42, 44; 42, 45; 42, 46; 42, 47; 43, identifier:n; 44, identifier:cc; 45, identifier:ii; 46, identifier:kk; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:fp_version; 49, identifier:fp_version; 50, else_clause; 50, 51; 51, block; 51, 52; 51, 66; 51, 80; 51, 94; 51, 109; 51, 124; 51, 139; 51, 154; 51, 155; 51, 169; 51, 170; 51, 171; 51, 200; 51, 254; 51, 255; 51, 268; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:cc; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:np; 58, identifier:ascontiguousarray; 59, argument_list; 59, 60; 59, 61; 60, identifier:cc; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:dtype; 63, attribute; 63, 64; 63, 65; 64, identifier:np; 65, identifier:float64; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:ii; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:ascontiguousarray; 73, argument_list; 73, 74; 73, 75; 74, identifier:ii; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:dtype; 77, attribute; 77, 78; 77, 79; 78, identifier:np; 79, identifier:int32; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:kk; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:np; 86, identifier:ascontiguousarray; 87, argument_list; 87, 88; 87, 89; 88, identifier:kk; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:dtype; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:int32; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:x; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:np; 100, identifier:empty; 101, argument_list; 101, 102; 101, 104; 102, tuple; 102, 103; 103, identifier:n; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:dtype; 106, attribute; 106, 107; 106, 108; 107, identifier:np; 108, identifier:int32; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:y; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:np; 115, identifier:empty; 116, argument_list; 116, 117; 116, 119; 117, tuple; 117, 118; 118, identifier:n; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:dtype; 121, attribute; 121, 122; 121, 123; 122, identifier:np; 123, identifier:int32; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:v; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:np; 130, identifier:empty; 131, argument_list; 131, 132; 131, 134; 132, tuple; 132, 133; 133, identifier:n; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:dtype; 136, attribute; 136, 137; 136, 138; 137, identifier:np; 138, identifier:float64; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:free_rows; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:np; 145, identifier:empty; 146, argument_list; 146, 147; 146, 149; 147, tuple; 147, 148; 148, identifier:n; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:dtype; 151, attribute; 151, 152; 151, 153; 152, identifier:np; 153, identifier:int32; 154, comment; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:n_free_rows; 158, call; 158, 159; 158, 160; 159, identifier:_pycrrt; 160, argument_list; 160, 161; 160, 162; 160, 163; 160, 164; 160, 165; 160, 166; 160, 167; 160, 168; 161, identifier:n; 162, identifier:cc; 163, identifier:ii; 164, identifier:kk; 165, identifier:free_rows; 166, identifier:x; 167, identifier:y; 168, identifier:v; 169, comment; 170, comment; 171, if_statement; 171, 172; 171, 175; 171, 176; 172, comparison_operator:==; 172, 173; 172, 174; 173, identifier:n_free_rows; 174, integer:0; 175, comment; 176, block; 176, 177; 177, if_statement; 177, 178; 177, 181; 177, 194; 178, comparison_operator:is; 178, 179; 178, 180; 179, identifier:return_cost; 180, True; 181, block; 181, 182; 182, return_statement; 182, 183; 183, expression_list; 183, 184; 183, 192; 183, 193; 184, call; 184, 185; 184, 186; 185, identifier:get_cost; 186, argument_list; 186, 187; 186, 188; 186, 189; 186, 190; 186, 191; 187, identifier:n; 188, identifier:cc; 189, identifier:ii; 190, identifier:kk; 191, identifier:x; 192, identifier:x; 193, identifier:y; 194, else_clause; 194, 195; 195, block; 195, 196; 196, return_statement; 196, 197; 197, expression_list; 197, 198; 197, 199; 198, identifier:x; 199, identifier:y; 200, for_statement; 200, 201; 200, 202; 200, 206; 200, 207; 201, identifier:it; 202, call; 202, 203; 202, 204; 203, identifier:range; 204, argument_list; 204, 205; 205, integer:2; 206, comment; 207, block; 207, 208; 207, 223; 207, 224; 207, 225; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:n_free_rows; 211, call; 211, 212; 211, 213; 212, identifier:_pyarr; 213, argument_list; 213, 214; 213, 215; 213, 216; 213, 217; 213, 218; 213, 219; 213, 220; 213, 221; 213, 222; 214, identifier:n; 215, identifier:cc; 216, identifier:ii; 217, identifier:kk; 218, identifier:n_free_rows; 219, identifier:free_rows; 220, identifier:x; 221, identifier:y; 222, identifier:v; 223, comment; 224, comment; 225, if_statement; 225, 226; 225, 229; 225, 230; 226, comparison_operator:==; 226, 227; 226, 228; 227, identifier:n_free_rows; 228, integer:0; 229, comment; 230, block; 230, 231; 231, if_statement; 231, 232; 231, 235; 231, 248; 232, comparison_operator:is; 232, 233; 232, 234; 233, identifier:return_cost; 234, True; 235, block; 235, 236; 236, return_statement; 236, 237; 237, expression_list; 237, 238; 237, 246; 237, 247; 238, call; 238, 239; 238, 240; 239, identifier:get_cost; 240, argument_list; 240, 241; 240, 242; 240, 243; 240, 244; 240, 245; 241, identifier:n; 242, identifier:cc; 243, identifier:ii; 244, identifier:kk; 245, identifier:x; 246, identifier:x; 247, identifier:y; 248, else_clause; 248, 249; 249, block; 249, 250; 250, return_statement; 250, 251; 251, expression_list; 251, 252; 251, 253; 252, identifier:x; 253, identifier:y; 254, comment; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:_pya; 258, argument_list; 258, 259; 258, 260; 258, 261; 258, 262; 258, 263; 258, 264; 258, 265; 258, 266; 258, 267; 259, identifier:n; 260, identifier:cc; 261, identifier:ii; 262, identifier:kk; 263, identifier:n_free_rows; 264, identifier:free_rows; 265, identifier:x; 266, identifier:y; 267, identifier:v; 268, comment; 269, if_statement; 269, 270; 269, 273; 269, 286; 270, comparison_operator:is; 270, 271; 270, 272; 271, identifier:return_cost; 272, True; 273, block; 273, 274; 274, return_statement; 274, 275; 275, expression_list; 275, 276; 275, 284; 275, 285; 276, call; 276, 277; 276, 278; 277, identifier:get_cost; 278, argument_list; 278, 279; 278, 280; 278, 281; 278, 282; 278, 283; 279, identifier:n; 280, identifier:cc; 281, identifier:ii; 282, identifier:kk; 283, identifier:x; 284, identifier:x; 285, identifier:y; 286, else_clause; 286, 287; 287, block; 287, 288; 288, return_statement; 288, 289; 289, expression_list; 289, 290; 289, 291; 290, identifier:x; 291, identifier:y
def lapmod(n, cc, ii, kk, fast=True, return_cost=True, fp_version=FP_DYNAMIC): """Solve sparse linear assignment problem using Jonker-Volgenant algorithm. n: number of rows of the assignment cost matrix cc: 1D array of all finite elements of the assignement cost matrix ii: 1D array of indices of the row starts in cc. The following must hold: ii[0] = 0 and ii[n+1] = len(cc). kk: 1D array of the column indices so that: cost[i, kk[ii[i] + k]] == cc[ii[i] + k]. Indices within one row must be sorted. extend_cost: whether or not extend a non-square matrix [default: False] cost_limit: an upper limit for a cost of a single assignment [default: np.inf] return_cost: whether or not to return the assignment cost Returns (opt, x, y) where: opt: cost of the assignment x: vector of columns assigned to rows y: vector of rows assigned to columns or (x, y) if return_cost is not True. When extend_cost and/or cost_limit is set, all unmatched entries will be marked by -1 in x/y. """ # log = logging.getLogger('lapmod') check_cost(n, cc, ii, kk) if fast is True: # log.debug('[----CR & RT & ARR & augmentation ----]') x, y = _lapmod(n, cc, ii, kk, fp_version=fp_version) else: cc = np.ascontiguousarray(cc, dtype=np.float64) ii = np.ascontiguousarray(ii, dtype=np.int32) kk = np.ascontiguousarray(kk, dtype=np.int32) x = np.empty((n,), dtype=np.int32) y = np.empty((n,), dtype=np.int32) v = np.empty((n,), dtype=np.float64) free_rows = np.empty((n,), dtype=np.int32) # log.debug('[----Column reduction & reduction transfer----]') n_free_rows = _pycrrt(n, cc, ii, kk, free_rows, x, y, v) # log.debug( # 'free, x, y, v: %s %s %s %s', free_rows[:n_free_rows], x, y, v) if n_free_rows == 0: # log.info('Reduction solved it.') if return_cost is True: return get_cost(n, cc, ii, kk, x), x, y else: return x, y for it in range(2): # log.debug('[---Augmenting row reduction (iteration: %d)---]', it) n_free_rows = _pyarr( n, cc, ii, kk, n_free_rows, free_rows, x, y, v) # log.debug( # 'free, x, y, v: %s %s %s %s', free_rows[:n_free_rows], x, y, v) if n_free_rows == 0: # log.info('Augmenting row reduction solved it.') if return_cost is True: return get_cost(n, cc, ii, kk, x), x, y else: return x, y # log.info('[----Augmentation----]') _pya(n, cc, ii, kk, n_free_rows, free_rows, x, y, v) # log.debug('x, y, v: %s %s %s', x, y, v) if return_cost is True: return get_cost(n, cc, ii, kk, x), x, y else: return x, y
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_items; 3, parameters; 3, 4; 4, identifier:items; 5, block; 5, 6; 5, 8; 5, 12; 5, 50; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:sorted_items; 11, dictionary; 12, for_statement; 12, 13; 12, 14; 12, 15; 13, identifier:item; 14, identifier:items; 15, block; 15, 16; 15, 25; 15, 41; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:category; 19, call; 19, 20; 19, 21; 20, identifier:lookup; 21, argument_list; 21, 22; 21, 23; 21, 24; 22, identifier:item; 23, string:'itemCategory'; 24, string:'categoryCode'; 25, if_statement; 25, 26; 25, 34; 26, comparison_operator:is; 26, 27; 26, 33; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:sorted_items; 30, identifier:get; 31, argument_list; 31, 32; 32, identifier:category; 33, None; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:sorted_items; 39, identifier:category; 40, list:[]; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:sorted_items; 46, identifier:category; 47, identifier:append; 48, argument_list; 48, 49; 49, identifier:item; 50, return_statement; 50, 51; 51, identifier:sorted_items
def sort_items(items): """sorts the items into a dictionary of categories, with a list of items""" sorted_items = {} for item in items: category = lookup(item, 'itemCategory', 'categoryCode') if sorted_items.get(category) is None: sorted_items[category] = [] sorted_items[category].append(item) return sorted_items
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_user_permissions; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:user_id; 6, block; 6, 7; 6, 9; 6, 22; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:permissions; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:user_service; 17, identifier:getPermissions; 18, argument_list; 18, 19; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:id; 21, identifier:user_id; 22, return_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 25, 27; 26, identifier:permissions; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:key; 29, call; 29, 30; 29, 31; 30, identifier:itemgetter; 31, argument_list; 31, 32; 32, string:'keyName'
def get_user_permissions(self, user_id): """Returns a sorted list of a users permissions""" permissions = self.user_service.getPermissions(id=user_id) return sorted(permissions, key=itemgetter('keyName'))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:transformChildrenToNative; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, for_statement; 8, 9; 8, 10; 8, 23; 9, identifier:childArray; 10, generator_expression; 10, 11; 10, 16; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:contents; 15, identifier:k; 16, for_in_clause; 16, 17; 16, 18; 17, identifier:k; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:sortChildKeys; 22, argument_list; 23, block; 23, 24; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:child; 26, identifier:childArray; 27, block; 27, 28; 27, 36; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:child; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:child; 34, identifier:transformToNative; 35, argument_list; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:child; 40, identifier:transformChildrenToNative; 41, argument_list
def transformChildrenToNative(self): """ Recursively replace children with their native representation. Sort to get dependency order right, like vtimezone before vevent. """ for childArray in (self.contents[k] for k in self.sortChildKeys()): for child in childArray: child = child.transformToNative() child.transformChildrenToNative()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_candidate_pairs; 3, parameters; 3, 4; 3, 5; 4, identifier:pairs; 5, identifier:ice_controlling; 6, block; 6, 7; 6, 9; 6, 26; 7, expression_statement; 7, 8; 8, comment; 9, function_definition; 9, 10; 9, 11; 9, 13; 10, function_name:pair_priority; 11, parameters; 11, 12; 12, identifier:pair; 13, block; 13, 14; 14, return_statement; 14, 15; 15, unary_operator:-; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:candidate_pair_priority; 18, argument_list; 18, 19; 18, 22; 18, 25; 19, attribute; 19, 20; 19, 21; 20, identifier:pair; 21, identifier:local_candidate; 22, attribute; 22, 23; 22, 24; 23, identifier:pair; 24, identifier:remote_candidate; 25, identifier:ice_controlling; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:pairs; 30, identifier:sort; 31, argument_list; 31, 32; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:key; 34, identifier:pair_priority
def sort_candidate_pairs(pairs, ice_controlling): """ Sort a list of candidate pairs. """ def pair_priority(pair): return -candidate_pair_priority(pair.local_candidate, pair.remote_candidate, ice_controlling) pairs.sort(key=pair_priority)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:order_by_refs; 3, parameters; 3, 4; 4, identifier:envs; 5, block; 5, 6; 5, 8; 5, 25; 5, 37; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:topology; 11, dictionary_comprehension; 11, 12; 11, 22; 12, pair; 12, 13; 12, 16; 13, subscript; 13, 14; 13, 15; 14, identifier:env; 15, string:'name'; 16, call; 16, 17; 16, 18; 17, identifier:set; 18, argument_list; 18, 19; 19, subscript; 19, 20; 19, 21; 20, identifier:env; 21, string:'refs'; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:env; 24, identifier:envs; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:by_name; 28, dictionary_comprehension; 28, 29; 28, 34; 29, pair; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:env; 32, string:'name'; 33, identifier:env; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:env; 36, identifier:envs; 37, return_statement; 37, 38; 38, list_comprehension; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:by_name; 41, identifier:name; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:name; 44, call; 44, 45; 44, 46; 45, identifier:toposort_flatten; 46, argument_list; 46, 47; 47, identifier:topology
def order_by_refs(envs): """ Return topologicaly sorted list of environments. I.e. all referenced environments are placed before their references. """ topology = { env['name']: set(env['refs']) for env in envs } by_name = { env['name']: env for env in envs } return [ by_name[name] for name in toposort_flatten(topology) ]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:merged_packages; 3, parameters; 3, 4; 3, 5; 4, identifier:env_packages; 5, identifier:names; 6, block; 6, 7; 6, 9; 6, 32; 6, 36; 6, 42; 6, 80; 6, 113; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:combined_packages; 12, call; 12, 13; 12, 14; 13, identifier:sorted; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:itertools; 19, identifier:chain; 20, identifier:from_iterable; 21, generator_expression; 21, 22; 21, 29; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:env_packages; 26, identifier:name; 27, identifier:items; 28, argument_list; 29, for_in_clause; 29, 30; 29, 31; 30, identifier:name; 31, identifier:names; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:result; 35, dictionary; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:errors; 39, call; 39, 40; 39, 41; 40, identifier:set; 41, argument_list; 42, for_statement; 42, 43; 42, 46; 42, 47; 43, pattern_list; 43, 44; 43, 45; 44, identifier:name; 45, identifier:version; 46, identifier:combined_packages; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 52; 48, 72; 49, comparison_operator:in; 49, 50; 49, 51; 50, identifier:name; 51, identifier:result; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 59; 54, comparison_operator:!=; 54, 55; 54, 58; 55, subscript; 55, 56; 55, 57; 56, identifier:result; 57, identifier:name; 58, identifier:version; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:errors; 64, identifier:add; 65, argument_list; 65, 66; 66, tuple; 66, 67; 66, 68; 66, 69; 67, identifier:name; 68, identifier:version; 69, subscript; 69, 70; 69, 71; 70, identifier:result; 71, identifier:name; 72, else_clause; 72, 73; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:result; 78, identifier:name; 79, identifier:version; 80, if_statement; 80, 81; 80, 82; 81, identifier:errors; 82, block; 82, 83; 82, 108; 83, for_statement; 83, 84; 83, 85; 83, 89; 84, identifier:error; 85, call; 85, 86; 85, 87; 86, identifier:sorted; 87, argument_list; 87, 88; 88, identifier:errors; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:logger; 94, identifier:error; 95, argument_list; 95, 96; 95, 99; 95, 102; 95, 105; 96, concatenated_string; 96, 97; 96, 98; 97, string:"Package %s was resolved to different "; 98, string:"versions in different environments: %s and %s"; 99, subscript; 99, 100; 99, 101; 100, identifier:error; 101, integer:0; 102, subscript; 102, 103; 102, 104; 103, identifier:error; 104, integer:1; 105, subscript; 105, 106; 105, 107; 106, identifier:error; 107, integer:2; 108, raise_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:RuntimeError; 111, argument_list; 111, 112; 112, string:"Please add constraints for the package version listed above"; 113, return_statement; 113, 114; 114, identifier:result
def merged_packages(env_packages, names): """ Return union set of environment packages with given names >>> sorted(merged_packages( ... { ... 'a': {'x': 1, 'y': 2}, ... 'b': {'y': 2, 'z': 3}, ... 'c': {'z': 3, 'w': 4} ... }, ... ['a', 'b'] ... ).items()) [('x', 1), ('y', 2), ('z', 3)] """ combined_packages = sorted(itertools.chain.from_iterable( env_packages[name].items() for name in names )) result = {} errors = set() for name, version in combined_packages: if name in result: if result[name] != version: errors.add((name, version, result[name])) else: result[name] = version if errors: for error in sorted(errors): logger.error( "Package %s was resolved to different " "versions in different environments: %s and %s", error[0], error[1], error[2], ) raise RuntimeError( "Please add constraints for the package version listed above" ) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:recursive_refs; 3, parameters; 3, 4; 3, 5; 4, identifier:envs; 5, identifier:name; 6, block; 6, 7; 6, 9; 6, 26; 6, 32; 6, 65; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:refs_by_name; 12, dictionary_comprehension; 12, 13; 12, 23; 13, pair; 13, 14; 13, 17; 14, subscript; 14, 15; 14, 16; 15, identifier:env; 16, string:'name'; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 19, 20; 20, subscript; 20, 21; 20, 22; 21, identifier:env; 22, string:'refs'; 23, for_in_clause; 23, 24; 23, 25; 24, identifier:env; 25, identifier:envs; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:refs; 29, subscript; 29, 30; 29, 31; 30, identifier:refs_by_name; 31, identifier:name; 32, if_statement; 32, 33; 32, 34; 32, 57; 33, identifier:refs; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:indirect_refs; 38, call; 38, 39; 38, 40; 39, identifier:set; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:itertools; 45, identifier:chain; 46, identifier:from_iterable; 47, argument_list; 47, 48; 48, list_comprehension; 48, 49; 48, 54; 49, call; 49, 50; 49, 51; 50, identifier:recursive_refs; 51, argument_list; 51, 52; 51, 53; 52, identifier:envs; 53, identifier:ref; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:ref; 56, identifier:refs; 57, else_clause; 57, 58; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:indirect_refs; 62, call; 62, 63; 62, 64; 63, identifier:set; 64, argument_list; 65, return_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:set; 69, identifier:union; 70, argument_list; 70, 71; 70, 72; 71, identifier:refs; 72, identifier:indirect_refs
def recursive_refs(envs, name): """ Return set of recursive refs for given env name >>> local_refs = sorted(recursive_refs([ ... {'name': 'base', 'refs': []}, ... {'name': 'test', 'refs': ['base']}, ... {'name': 'local', 'refs': ['test']}, ... ], 'local')) >>> local_refs == ['base', 'test'] True """ refs_by_name = { env['name']: set(env['refs']) for env in envs } refs = refs_by_name[name] if refs: indirect_refs = set(itertools.chain.from_iterable([ recursive_refs(envs, ref) for ref in refs ])) else: indirect_refs = set() return set.union(refs, indirect_refs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:reference_cluster; 3, parameters; 3, 4; 3, 5; 4, identifier:envs; 5, identifier:name; 6, block; 6, 7; 6, 9; 6, 29; 6, 43; 6, 89; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:edges; 12, list_comprehension; 12, 13; 12, 21; 12, 24; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 15, 16; 16, list:[env['name'], ref]; 16, 17; 16, 20; 17, subscript; 17, 18; 17, 19; 18, identifier:env; 19, string:'name'; 20, identifier:ref; 21, for_in_clause; 21, 22; 21, 23; 22, identifier:env; 23, identifier:envs; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:ref; 26, subscript; 26, 27; 26, 28; 27, identifier:env; 28, string:'refs'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, pattern_list; 31, 32; 31, 33; 32, identifier:prev; 33, identifier:cluster; 34, expression_list; 34, 35; 34, 38; 35, call; 35, 36; 35, 37; 36, identifier:set; 37, argument_list; 38, call; 38, 39; 38, 40; 39, identifier:set; 40, argument_list; 40, 41; 41, list:[name]; 41, 42; 42, identifier:name; 43, while_statement; 43, 44; 43, 47; 43, 48; 44, comparison_operator:!=; 44, 45; 44, 46; 45, identifier:prev; 46, identifier:cluster; 47, comment; 48, block; 48, 49; 48, 56; 48, 60; 48, 85; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:prev; 52, call; 52, 53; 52, 54; 53, identifier:set; 54, argument_list; 54, 55; 55, identifier:cluster; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:to_visit; 59, list:[]; 60, for_statement; 60, 61; 60, 62; 60, 63; 61, identifier:edge; 62, identifier:edges; 63, block; 63, 64; 64, if_statement; 64, 65; 64, 68; 64, 69; 64, 74; 65, binary_operator:&; 65, 66; 65, 67; 66, identifier:cluster; 67, identifier:edge; 68, comment; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, augmented_assignment:|=; 71, 72; 71, 73; 72, identifier:cluster; 73, identifier:edge; 74, else_clause; 74, 75; 74, 76; 74, 77; 75, comment; 76, comment; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:to_visit; 82, identifier:append; 83, argument_list; 83, 84; 84, identifier:edge; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:edges; 88, identifier:to_visit; 89, return_statement; 89, 90; 90, identifier:cluster
def reference_cluster(envs, name): """ Return set of all env names referencing or referenced by given name. >>> cluster = sorted(reference_cluster([ ... {'name': 'base', 'refs': []}, ... {'name': 'test', 'refs': ['base']}, ... {'name': 'local', 'refs': ['test']}, ... ], 'test')) >>> cluster == ['base', 'local', 'test'] True """ edges = [ set([env['name'], ref]) for env in envs for ref in env['refs'] ] prev, cluster = set(), set([name]) while prev != cluster: # While cluster grows prev = set(cluster) to_visit = [] for edge in edges: if cluster & edge: # Add adjacent nodes: cluster |= edge else: # Leave only edges that are out # of cluster for the next round: to_visit.append(edge) edges = to_visit return cluster
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:offset; 11, integer:100; 12, default_parameter; 12, 13; 12, 14; 13, identifier:page; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:aquarius_url; 17, None; 18, block; 18, 19; 18, 21; 18, 26; 18, 33; 19, expression_statement; 19, 20; 20, comment; 21, assert_statement; 21, 22; 21, 25; 22, comparison_operator:>=; 22, 23; 22, 24; 23, identifier:page; 24, integer:1; 25, string:f'Invalid page value {page}. Required page >= 1.'; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:logger; 30, identifier:info; 31, argument_list; 31, 32; 32, string:f'Searching asset containing: {text}'; 33, return_statement; 33, 34; 34, list_comprehension; 34, 35; 34, 41; 35, call; 35, 36; 35, 37; 36, identifier:DDO; 37, argument_list; 37, 38; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:dictionary; 40, identifier:ddo_dict; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:ddo_dict; 43, subscript; 43, 44; 43, 58; 44, call; 44, 45; 44, 53; 45, attribute; 45, 46; 45, 52; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_get_aquarius; 50, argument_list; 50, 51; 51, identifier:aquarius_url; 52, identifier:text_search; 53, argument_list; 53, 54; 53, 55; 53, 56; 53, 57; 54, identifier:text; 55, identifier:sort; 56, identifier:offset; 57, identifier:page; 58, string:'results'
def search(self, text, sort=None, offset=100, page=1, aquarius_url=None): """ Search an asset in oceanDB using aquarius. :param text: String with the value that you are searching :param sort: Dictionary to choose order base in some value :param offset: Number of elements shows by page :param page: Page number :param aquarius_url: Url of the aquarius where you want to search. If there is not provided take the default :return: List of assets that match with the query """ assert page >= 1, f'Invalid page value {page}. Required page >= 1.' logger.info(f'Searching asset containing: {text}') return [DDO(dictionary=ddo_dict) for ddo_dict in self._get_aquarius(aquarius_url).text_search(text, sort, offset, page)['results']]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:query; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:offset; 11, integer:100; 12, default_parameter; 12, 13; 12, 14; 13, identifier:page; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:aquarius_url; 17, None; 18, block; 18, 19; 18, 21; 18, 28; 18, 37; 19, expression_statement; 19, 20; 20, comment; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:logger; 25, identifier:info; 26, argument_list; 26, 27; 27, string:f'Searching asset query: {query}'; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:aquarius; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_get_aquarius; 35, argument_list; 35, 36; 36, identifier:aquarius_url; 37, return_statement; 37, 38; 38, list_comprehension; 38, 39; 38, 45; 39, call; 39, 40; 39, 41; 40, identifier:DDO; 41, argument_list; 41, 42; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:dictionary; 44, identifier:ddo_dict; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:ddo_dict; 47, subscript; 47, 48; 47, 57; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:aquarius; 51, identifier:query_search; 52, argument_list; 52, 53; 52, 54; 52, 55; 52, 56; 53, identifier:query; 54, identifier:sort; 55, identifier:offset; 56, identifier:page; 57, string:'results'
def query(self, query, sort=None, offset=100, page=1, aquarius_url=None): """ Search an asset in oceanDB using search query. :param query: dict with query parameters (e.g.) https://github.com/oceanprotocol/aquarius/blob/develop/docs/for_api_users/API.md :param sort: Dictionary to choose order base in some value :param offset: Number of elements shows by page :param page: Page number :param aquarius_url: Url of the aquarius where you want to search. If there is not provided take the default :return: List of assets that match with the query. """ logger.info(f'Searching asset query: {query}') aquarius = self._get_aquarius(aquarius_url) return [DDO(dictionary=ddo_dict) for ddo_dict in aquarius.query_search(query, sort, offset, page)['results']]