sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '29']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '22']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '19'], 'value': 'and'}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_keys'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'KeyValue'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '38']}, {'id': '31', 'type': 'attribute', 'children': ['32', '37']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'CliTable'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42', '45']}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sort(self, cmp=None, key=None, reverse=False): if not key and self._keys: key = self.KeyValue super(CliTable, self).sort(cmp=cmp, key=key, reverse=reverse)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '58', '64', '74', '86', '98', '107', '116']}, {'id': '15', 'type': 'function_definition', 'children': ['16', '17', '19']}; {'id': '16', 'type': 'function_name', 'children': [], 'value': '_DefaultKey'}, {'id': '17', 'type': 'parameters', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '19', 'type': 'block', 'children': ['20', '24', '56']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '23', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '29']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'try_statement', 'children': ['31', '44']}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'except_clause', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '63'], 'value': 'or'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_DefaultKey'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'new_table'}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_table'}, {'id': '71', 'type': 'slice', 'children': ['72', '73']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '73', 'type': 'colon', 'children': []}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'new_table'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '95']}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_table'}, {'id': '103', 'type': 'list', 'children': ['104'], 'value': '[self.header]'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '114']}, {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '_table'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'new_table'}; {'id': '116', 'type': 'for_statement', 'children': ['117', '120', '126']}, {'id': '117', 'type': 'pattern_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': '_table'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'row'}
def sort(self, cmp=None, key=None, reverse=False): def _DefaultKey(value): result = [] for key in self.header: try: result.append(float(value[key])) except ValueError: result.append(value[key]) return result key = key or _DefaultKey new_table = self._table[1:] if cmp is not None: key = cmp_to_key(cmp) new_table.sort(key=key, reverse=reverse) self._table = [self.header] self._table.extend(new_table) for index, row in enumerate(self._table): row.row = index
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_order'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '5', 'type': 'block', 'children': ['6', '8']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Do a topological sort on the dependency graph dict.\n '''"}; {'id': '8', 'type': 'while_statement', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '10', 'type': 'block', 'children': ['11', '28', '39', '45']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'leftmost'}; {'id': '14', 'type': 'list_comprehension', 'children': ['15', '16', '25']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '20']}, {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'if_clause', 'children': ['26']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '31']}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'leftmost'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '%'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'Dependency cycle detected! %s'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'leftmost'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'leftmost'}; {'id': '48', 'type': 'block', 'children': ['49', '52', '59']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'yield', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '66']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'bset'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'bset'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'discard'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'result'}
def find_order(graph): ''' Do a topological sort on the dependency graph dict. ''' while graph: leftmost = [l for l, s in graph.items() if not s] if not leftmost: raise ValueError('Dependency cycle detected! %s' % graph) leftmost.sort() for result in leftmost: yield result graph.pop(result) for bset in graph.values(): bset.discard(result)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '41']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '12', '35']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']}; {'id': '14', 'type': 'function_name', 'children': [], 'value': 'sort_func'}, {'id': '15', 'type': 'parameters', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '17', 'type': 'block', 'children': ['18', '33']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort_func'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}
def do_sort(value, case_sensitive=False): if not case_sensitive: def sort_func(item): if isinstance(item, basestring): item = item.lower() return item else: sort_func = None return sorted(seq, key=sort_func)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dedupe'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'contains_dupes'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'threshold'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '70'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'scorer'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'fuzz'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'token_set_ratio'}, {'id': '13', 'type': 'block', 'children': ['14', '18', '118', '122', '132', '140']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'extractor'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'contains_dupes'}, {'id': '21', 'type': 'block', 'children': ['22', '36', '50']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'extract'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30', '33']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'contains_dupes'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'scorer'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'scorer'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'filtered'}, {'id': '39', 'type': 'list_comprehension', 'children': ['40', '41', '44']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '44', 'type': 'if_clause', 'children': ['45']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '>'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '57', '69']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '56'], 'value': '=='}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'filtered'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'extractor'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'filtered'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71', '86', '107']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'filtered'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'filtered'}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '80', 'type': 'lambda', 'children': ['81', '83']}, {'id': '81', 'type': 'lambda_parameters', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'filter_sort'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93', '104']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'filtered'}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'lambda', 'children': ['96', '98']}; {'id': '96', 'type': 'lambda_parameters', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '106', 'type': 'True', 'children': []}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'extractor'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'subscript', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'filter_sort'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '121', 'type': 'dictionary', 'children': []}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'extractor'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'extractor'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '139', 'type': 'argument_list', 'children': []}; {'id': '140', 'type': 'if_statement', 'children': ['141', '150', '153']}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '146'], 'value': '=='}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'extractor'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'contains_dupes'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'contains_dupes'}, {'id': '153', 'type': 'else_clause', 'children': ['154']}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'return_statement', 'children': ['156']}
def dedupe(contains_dupes, threshold=70, scorer=fuzz.token_set_ratio): extractor = [] for item in contains_dupes: matches = extract(item, contains_dupes, limit=None, scorer=scorer) filtered = [x for x in matches if x[1] > threshold] if len(filtered) == 1: extractor.append(filtered[0][0]) else: filtered = sorted(filtered, key=lambda x: x[0]) filter_sort = sorted(filtered, key=lambda x: len(x[0]), reverse=True) extractor.append(filter_sort[0][0]) keys = {} for e in extractor: keys[e] = 1 extractor = keys.keys() if len(extractor) == len(contains_dupes): return contains_dupes else: return extractor
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_and_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'full_process'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '25', '33', '45']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '13', 'type': 'conditional_expression', 'children': ['14', '23', '24'], 'value': 'if'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'full_process'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'full_process'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted_string'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': 'u" "'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'tokens'}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted_string'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'strip'}
def _process_and_sort(s, force_ascii, full_process=True): ts = utils.full_process(s, force_ascii=force_ascii) if full_process else s tokens = ts.split() sorted_string = u" ".join(sorted(tokens)) return sorted_string.strip()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'token_sort_ratio'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's2'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_token_sort'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19', '22', '25']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 's2'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'full_process'}
def token_sort_ratio(s1, s2, force_ascii=True, full_process=True): return _token_sort(s1, s2, partial=False, force_ascii=force_ascii, full_process=full_process)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'partial_token_sort_ratio'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's2'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_token_sort'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19', '22', '25']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 's2'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '21', 'type': 'True', 'children': []}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'full_process'}
def partial_token_sort_ratio(s1, s2, force_ascii=True, full_process=True): return _token_sort(s1, s2, partial=True, force_ascii=force_ascii, full_process=full_process)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'WRatio'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's2'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '50', '61', '72', '76', '80', '84', '92', '121', '130', '139']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '15', '40']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '15', 'type': 'block', 'children': ['16', '28']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'p1'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 's1'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's2'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'force_ascii'}; {'id': '40', 'type': 'else_clause', 'children': ['41']}, {'id': '41', 'type': 'block', 'children': ['42', '46']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'p1'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 's2'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '58']}, {'id': '51', 'type': 'not_operator', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'validate_string'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '69']}; {'id': '62', 'type': 'not_operator', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'validate_string'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'try_partial'}, {'id': '75', 'type': 'True', 'children': []}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'unbase_scale'}, {'id': '79', 'type': 'float', 'children': [], 'value': '.95'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'partial_scale'}, {'id': '83', 'type': 'float', 'children': [], 'value': '.90'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ratio'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'p1'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len_ratio'}, {'id': '95', 'type': 'binary_operator', 'children': ['96', '110'], 'value': '/'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '106']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '117']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'p1'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '121', 'type': 'if_statement', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '<'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'len_ratio'}; {'id': '124', 'type': 'float', 'children': [], 'value': '1.5'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'try_partial'}, {'id': '129', 'type': 'False', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '134']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '>'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'len_ratio'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'partial_scale'}; {'id': '138', 'type': 'float', 'children': [], 'value': '.6'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '141', '197']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'try_partial'}, {'id': '141', 'type': 'block', 'children': ['142', '152', '168', '184']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '151'], 'value': '*'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'partial_ratio'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'partial_scale'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ptsor'}, {'id': '155', 'type': 'binary_operator', 'children': ['156', '167'], 'value': '*'}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '165', '166'], 'value': '*'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'partial_token_sort_ratio'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'p1'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'full_process'}; {'id': '164', 'type': 'False', 'children': []}, {'id': '165', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'unbase_scale'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'partial_scale'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ptser'}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '183'], 'value': '*'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '181', '182'], 'value': '*'}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'partial_token_set_ratio'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'p1'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'full_process'}; {'id': '180', 'type': 'False', 'children': []}, {'id': '181', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'unbase_scale'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'partial_scale'}; {'id': '184', 'type': 'return_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'intr'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194', '195', '196']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'ptsor'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ptser'}, {'id': '197', 'type': 'else_clause', 'children': ['198']}; {'id': '198', 'type': 'block', 'children': ['199', '212', '225']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'tsor'}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '211'], 'value': '*'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'token_sort_ratio'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'p1'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'full_process'}; {'id': '210', 'type': 'False', 'children': []}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'unbase_scale'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'tser'}, {'id': '215', 'type': 'binary_operator', 'children': ['216', '224'], 'value': '*'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'token_set_ratio'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '220', '221']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'full_process'}, {'id': '223', 'type': 'False', 'children': []}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'unbase_scale'}, {'id': '225', 'type': 'return_statement', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'intr'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'tsor'}
def WRatio(s1, s2, force_ascii=True, full_process=True): if full_process: p1 = utils.full_process(s1, force_ascii=force_ascii) p2 = utils.full_process(s2, force_ascii=force_ascii) else: p1 = s1 p2 = s2 if not utils.validate_string(p1): return 0 if not utils.validate_string(p2): return 0 try_partial = True unbase_scale = .95 partial_scale = .90 base = ratio(p1, p2) len_ratio = float(max(len(p1), len(p2))) / min(len(p1), len(p2)) if len_ratio < 1.5: try_partial = False if len_ratio > 8: partial_scale = .6 if try_partial: partial = partial_ratio(p1, p2) * partial_scale ptsor = partial_token_sort_ratio(p1, p2, full_process=False) \ * unbase_scale * partial_scale ptser = partial_token_set_ratio(p1, p2, full_process=False) \ * unbase_scale * partial_scale return utils.intr(max(base, partial, ptsor, ptser)) else: tsor = token_sort_ratio(p1, p2, full_process=False) * unbase_scale tser = token_set_ratio(p1, p2, full_process=False) * unbase_scale return utils.intr(max(base, tsor, tser))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_depth'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '28', '44']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'lst'}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '19']}, {'id': '13', 'type': 'list', 'children': ['14', '18'], 'value': '[float(price), quantity]'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'price'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'quantity'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '23']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'price'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'quantity'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lst'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '41']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'lst'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'lst'}
def sort_depth(vals, reverse=False): lst = [[float(price), quantity] for price, quantity in vals.items()] lst = sorted(lst, key=itemgetter(0), reverse=reverse) return lst
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_fields'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'field_class'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ordered'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '34', '47', '66']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '20', '28']}, {'id': '17', 'type': 'tuple', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'field_value'}; {'id': '20', 'type': 'for_in_clause', 'children': ['21', '24']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'field_value'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '28', 'type': 'if_clause', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'is_instance_or_subclass'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'field_value'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'field_class'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'for_statement', 'children': ['38', '41', '42']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'delete_statement', 'children': ['44']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ordered'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '58', 'type': 'lambda', 'children': ['59', '61']}, {'id': '59', 'type': 'lambda_parameters', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pair'}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_creation_index'}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'fields'}
def _get_fields(attrs, field_class, pop=False, ordered=False): fields = [ (field_name, field_value) for field_name, field_value in iteritems(attrs) if is_instance_or_subclass(field_value, field_class) ] if pop: for field_name, _ in fields: del attrs[field_name] if ordered: fields.sort(key=lambda pair: pair[1]._creation_index) return fields
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '66']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_features'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '28', '33', '38', '43', '48', '53', '58', '63']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'column_id'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'column_sort'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'column_kind'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'column_value'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'chunksize'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'CHUNKSIZE'}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'N_PROCESSES'}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'show_warnings'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'SHOW_WARNINGS'}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'disable_progressbar'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'DISABLE_PROGRESSBAR'}, {'id': '43', 'type': 'default_parameter', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'impute_function'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'IMPUTE_FUNCTION'}; {'id': '48', 'type': 'default_parameter', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'PROFILING'}, {'id': '53', 'type': 'default_parameter', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'profiling_filename'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PROFILING_FILENAME'}; {'id': '58', 'type': 'default_parameter', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'profiling_sorting'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'PROFILING_SORTING'}, {'id': '63', 'type': 'default_parameter', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'distributor'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '95', '123', '134', '209', '225']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '74', '75']}, {'id': '69', 'type': 'pattern_list', 'children': ['70', '71', '72', '73']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'df_melt'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'column_id'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'column_kind'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'column_value'}; {'id': '74', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dataframe_functions'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_normalize_input_to_internal_representation'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '83', '86', '89', '92']}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'column_id'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'column_id'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'column_kind'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'column_kind'}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'column_sort'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'column_sort'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'column_value'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'column_value'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '103', '110']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '100'], 'value': 'and'}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}, {'id': '99', 'type': 'None', 'children': []}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}; {'id': '102', 'type': 'None', 'children': []}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ComprehensiveFCParameters'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '118']}, {'id': '111', 'type': 'boolean_operator', 'children': ['112', '115'], 'value': 'and'}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}; {'id': '114', 'type': 'None', 'children': []}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}, {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}; {'id': '122', 'type': 'dictionary', 'children': []}, {'id': '123', 'type': 'if_statement', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'profiler'}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'profiling'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'start_profiling'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'with_statement', 'children': ['135', '142']}, {'id': '135', 'type': 'with_clause', 'children': ['136']}; {'id': '136', 'type': 'with_item', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'catch_warnings'}, {'id': '141', 'type': 'argument_list', 'children': []}; {'id': '142', 'type': 'block', 'children': ['143', '163', '199']}, {'id': '143', 'type': 'if_statement', 'children': ['144', '146', '154']}; {'id': '144', 'type': 'not_operator', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'show_warnings'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'simplefilter'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'string', 'children': [], 'value': '"ignore"'}; {'id': '154', 'type': 'else_clause', 'children': ['155']}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'simplefilter'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': '"default"'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': '_do_extraction'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '172', '175', '178', '181', '184', '187', '190', '193', '196']}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'df_melt'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'column_id'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'column_id'}, {'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'column_value'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'column_value'}; {'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'column_kind'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'column_kind'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}; {'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'chunk_size'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'chunksize'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'disable_progressbar'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'disable_progressbar'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}, {'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}; {'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'distributor'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'distributor'}, {'id': '199', 'type': 'if_statement', 'children': ['200', '203']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'is'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'impute_function'}; {'id': '202', 'type': 'None', 'children': []}, {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'impute_function'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '209', 'type': 'if_statement', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'profiling'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'end_profiling'}, {'id': '217', 'type': 'argument_list', 'children': ['218', '219', '222']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'profiler'}, {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'profiling_filename'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'profiling_sorting'}, {'id': '225', 'type': 'return_statement', 'children': ['226']}
def extract_features(timeseries_container, default_fc_parameters=None, kind_to_fc_parameters=None, column_id=None, column_sort=None, column_kind=None, column_value=None, chunksize=defaults.CHUNKSIZE, n_jobs=defaults.N_PROCESSES, show_warnings=defaults.SHOW_WARNINGS, disable_progressbar=defaults.DISABLE_PROGRESSBAR, impute_function=defaults.IMPUTE_FUNCTION, profile=defaults.PROFILING, profiling_filename=defaults.PROFILING_FILENAME, profiling_sorting=defaults.PROFILING_SORTING, distributor=None): df_melt, column_id, column_kind, column_value = \ dataframe_functions._normalize_input_to_internal_representation( timeseries_container=timeseries_container, column_id=column_id, column_kind=column_kind, column_sort=column_sort, column_value=column_value) if default_fc_parameters is None and kind_to_fc_parameters is None: default_fc_parameters = ComprehensiveFCParameters() elif default_fc_parameters is None and kind_to_fc_parameters is not None: default_fc_parameters = {} if profile: profiler = profiling.start_profiling() with warnings.catch_warnings(): if not show_warnings: warnings.simplefilter("ignore") else: warnings.simplefilter("default") result = _do_extraction(df=df_melt, column_id=column_id, column_value=column_value, column_kind=column_kind, n_jobs=n_jobs, chunk_size=chunksize, disable_progressbar=disable_progressbar, default_fc_parameters=default_fc_parameters, kind_to_fc_parameters=kind_to_fc_parameters, distributor=distributor) if impute_function is not None: impute_function(result) if profile: profiling.end_profiling(profiler, filename=profiling_filename, sorting=profiling_sorting) return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert_to_output_format'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '5', 'type': 'block', 'children': ['6', '34']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}, {'id': '7', 'type': 'function_name', 'children': [], 'value': 'add_parenthesis_if_string_value'}; {'id': '8', 'type': 'parameters', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '17', '27']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '26'], 'value': '+'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '+'}, {'id': '21', 'type': 'string', 'children': [], 'value': '\'"\''}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '26', 'type': 'string', 'children': [], 'value': '\'"\''}, {'id': '27', 'type': 'else_clause', 'children': ['28']}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"__"'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '39', 'type': 'generator_expression', 'children': ['40', '53']}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '47'], 'value': '+'}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '46'], 'value': '+'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'string', 'children': [], 'value': '"_"'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'add_parenthesis_if_string_value'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'keys'}
def convert_to_output_format(param): def add_parenthesis_if_string_value(x): if isinstance(x, string_types): return '"' + str(x) + '"' else: return str(x) return "__".join(str(key) + "_" + add_parenthesis_if_string_value(param[key]) for key in sorted(param.keys()))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'end_profiling'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'profiler'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '24', '41', '47']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'profiler'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'disable'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'StringIO'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '27', 'type': 'call', 'children': ['28', '39']}; {'id': '28', 'type': 'attribute', 'children': ['29', '38']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pstats'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Stats'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'profiler'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort_stats'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'print_stats'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'with_statement', 'children': ['48', '58']}; {'id': '48', 'type': 'with_clause', 'children': ['49']}, {'id': '49', 'type': 'with_item', 'children': ['50']}; {'id': '50', 'type': 'as_pattern', 'children': ['51', '56']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"w+"'}; {'id': '56', 'type': 'as_pattern_target', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '58', 'type': 'block', 'children': ['59', '66']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_logger'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'string', 'children': [], 'value': '"[calculate_ts_features] Finished profiling of time series feature extraction"'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'getvalue'}
def end_profiling(profiler, filename, sorting=None): profiler.disable() s = six.StringIO() ps = pstats.Stats(profiler, stream=s).sort_stats(sorting) ps.print_stats() with open(filename, "w+") as f: _logger.info("[calculate_ts_features] Finished profiling of time series feature extraction") f.write(s.getvalue())
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '95']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_relevant_features'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '32', '37', '42', '47', '52', '57', '62', '67', '72', '77', '82', '87', '92']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'column_id'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'column_sort'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'column_kind'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'column_value'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'show_warnings'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'SHOW_WARNINGS'}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'disable_progressbar'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'DISABLE_PROGRESSBAR'}, {'id': '37', 'type': 'default_parameter', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'PROFILING'}; {'id': '42', 'type': 'default_parameter', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'profiling_filename'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'PROFILING_FILENAME'}, {'id': '47', 'type': 'default_parameter', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'profiling_sorting'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'PROFILING_SORTING'}; {'id': '52', 'type': 'default_parameter', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'test_for_binary_target_binary_feature'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'TEST_FOR_BINARY_TARGET_BINARY_FEATURE'}, {'id': '57', 'type': 'default_parameter', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'test_for_binary_target_real_feature'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'TEST_FOR_BINARY_TARGET_REAL_FEATURE'}; {'id': '62', 'type': 'default_parameter', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'test_for_real_target_binary_feature'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'TEST_FOR_REAL_TARGET_BINARY_FEATURE'}, {'id': '67', 'type': 'default_parameter', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'test_for_real_target_real_feature'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'TEST_FOR_REAL_TARGET_REAL_FEATURE'}; {'id': '72', 'type': 'default_parameter', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'fdr_level'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'FDR_LEVEL'}, {'id': '77', 'type': 'default_parameter', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'hypotheses_independent'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'HYPOTHESES_INDEPENDENT'}; {'id': '82', 'type': 'default_parameter', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'N_PROCESSES'}, {'id': '87', 'type': 'default_parameter', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'chunksize'}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'CHUNKSIZE'}; {'id': '92', 'type': 'default_parameter', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ml_task'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'auto'"}, {'id': '95', 'type': 'block', 'children': ['96', '113', '124', '140', '152', '161', '214', '260', '295', '325']}; {'id': '96', 'type': 'assert_statement', 'children': ['97', '104']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'Series'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"y needs to be a pandas.Series, received type: {}."'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '113', 'type': 'assert_statement', 'children': ['114', '123']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '122'], 'value': '>'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '123', 'type': 'string', 'children': [], 'value': '"Feature selection is only possible if more than 1 label/class is provided"'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'restrict_input_to_index'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'column_id'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'ids_container'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'get_ids'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '149']}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'df_or_dict'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}, {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'column_id'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'column_id'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ids_y'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '161', 'type': 'if_statement', 'children': ['162', '165']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '!='}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'ids_container'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ids_y'}, {'id': '165', 'type': 'block', 'children': ['166', '190']}; {'id': '166', 'type': 'if_statement', 'children': ['167', '175']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '174'], 'value': '>'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '-'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ids_container'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ids_y'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'raise_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '186']}, {'id': '181', 'type': 'attribute', 'children': ['182', '185']}; {'id': '182', 'type': 'concatenated_string', 'children': ['183', '184']}, {'id': '183', 'type': 'string', 'children': [], 'value': '"The following ids are in the time series container but are missing in y: "'}; {'id': '184', 'type': 'string', 'children': [], 'value': '"{}"'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '-'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ids_container'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ids_y'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '199']}, {'id': '191', 'type': 'comparison_operator', 'children': ['192', '198'], 'value': '>'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '-'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ids_y'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'ids_container'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'raise_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '210']}, {'id': '205', 'type': 'attribute', 'children': ['206', '209']}; {'id': '206', 'type': 'concatenated_string', 'children': ['207', '208']}, {'id': '207', 'type': 'string', 'children': [], 'value': '"The following ids are in y but are missing inside the time series container: "'}; {'id': '208', 'type': 'string', 'children': [], 'value': '"{}"'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '-'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'ids_y'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'ids_container'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'X_ext'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'extract_features'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '221', '224', '227', '230', '233', '236', '239', '242', '245', '248', '251', '254', '257']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'timeseries_container'}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'default_fc_parameters'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'kind_to_fc_parameters'}, {'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'show_warnings'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'show_warnings'}; {'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'disable_progressbar'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'disable_progressbar'}, {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'profiling_filename'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'profiling_filename'}, {'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'profiling_sorting'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'profiling_sorting'}; {'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}, {'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'column_id'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'column_id'}; {'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'column_sort'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'column_sort'}, {'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'column_kind'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'column_kind'}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'column_value'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'column_value'}, {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'impute_function'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'impute'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'X_sel'}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'select_features'}, {'id': '265', 'type': 'argument_list', 'children': ['266', '267', '268', '271', '274', '277', '280', '283', '286', '289', '292']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'X_ext'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'test_for_binary_target_binary_feature'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'test_for_binary_target_binary_feature'}, {'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'test_for_binary_target_real_feature'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'test_for_binary_target_real_feature'}; {'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'test_for_real_target_binary_feature'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'test_for_real_target_binary_feature'}, {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'test_for_real_target_real_feature'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'test_for_real_target_real_feature'}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'fdr_level'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'fdr_level'}, {'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'hypotheses_independent'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'hypotheses_independent'}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'n_jobs'}, {'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'chunksize'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'chunksize'}; {'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'ml_task'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'ml_task'}, {'id': '295', 'type': 'if_statement', 'children': ['296', '299', '304']}; {'id': '296', 'type': 'comparison_operator', 'children': ['297', '298'], 'value': 'is'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '298', 'type': 'None', 'children': []}, {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'X_sel'}; {'id': '304', 'type': 'else_clause', 'children': ['305']}, {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'merge'}, {'id': '313', 'type': 'argument_list', 'children': ['314', '315', '316', '319', '322']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'X_sel'}; {'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'left_index'}; {'id': '318', 'type': 'True', 'children': []}, {'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'right_index'}, {'id': '321', 'type': 'True', 'children': []}; {'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'how'}; {'id': '324', 'type': 'string', 'children': [], 'value': '"left"'}, {'id': '325', 'type': 'return_statement', 'children': ['326']}
def extract_relevant_features(timeseries_container, y, X=None, default_fc_parameters=None, kind_to_fc_parameters=None, column_id=None, column_sort=None, column_kind=None, column_value=None, show_warnings=defaults.SHOW_WARNINGS, disable_progressbar=defaults.DISABLE_PROGRESSBAR, profile=defaults.PROFILING, profiling_filename=defaults.PROFILING_FILENAME, profiling_sorting=defaults.PROFILING_SORTING, test_for_binary_target_binary_feature=defaults.TEST_FOR_BINARY_TARGET_BINARY_FEATURE, test_for_binary_target_real_feature=defaults.TEST_FOR_BINARY_TARGET_REAL_FEATURE, test_for_real_target_binary_feature=defaults.TEST_FOR_REAL_TARGET_BINARY_FEATURE, test_for_real_target_real_feature=defaults.TEST_FOR_REAL_TARGET_REAL_FEATURE, fdr_level=defaults.FDR_LEVEL, hypotheses_independent=defaults.HYPOTHESES_INDEPENDENT, n_jobs=defaults.N_PROCESSES, chunksize=defaults.CHUNKSIZE, ml_task='auto'): assert isinstance(y, pd.Series), "y needs to be a pandas.Series, received type: {}.".format(type(y)) assert len(set(y)) > 1, "Feature selection is only possible if more than 1 label/class is provided" if X is not None: timeseries_container = restrict_input_to_index(timeseries_container, column_id, X.index) ids_container = get_ids(df_or_dict=timeseries_container, column_id=column_id) ids_y = set(y.index) if ids_container != ids_y: if len(ids_container - ids_y) > 0: raise ValueError("The following ids are in the time series container but are missing in y: " "{}".format(ids_container - ids_y)) if len(ids_y - ids_container) > 0: raise ValueError("The following ids are in y but are missing inside the time series container: " "{}".format(ids_y - ids_container)) X_ext = extract_features(timeseries_container, default_fc_parameters=default_fc_parameters, kind_to_fc_parameters=kind_to_fc_parameters, show_warnings=show_warnings, disable_progressbar=disable_progressbar, profile=profile, profiling_filename=profiling_filename, profiling_sorting=profiling_sorting, n_jobs=n_jobs, column_id=column_id, column_sort=column_sort, column_kind=column_kind, column_value=column_value, impute_function=impute) X_sel = select_features(X_ext, y, test_for_binary_target_binary_feature=test_for_binary_target_binary_feature, test_for_binary_target_real_feature=test_for_binary_target_real_feature, test_for_real_target_binary_feature=test_for_real_target_binary_feature, test_for_real_target_real_feature=test_for_real_target_real_feature, fdr_level=fdr_level, hypotheses_independent=hypotheses_independent, n_jobs=n_jobs, chunksize=chunksize, ml_task=ml_task) if X is None: X = X_sel else: X = pd.merge(X, X_sel, left_index=True, right_index=True, how="left") return X
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'user_agents'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'parenthesized_expression', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '58']}, {'id': '9', 'type': 'attribute', 'children': ['10', '57']}; {'id': '10', 'type': 'call', 'children': ['11', '44']}, {'id': '11', 'type': 'attribute', 'children': ['12', '43']}; {'id': '12', 'type': 'call', 'children': ['13', '37']}, {'id': '13', 'type': 'attribute', 'children': ['14', '36']}; {'id': '14', 'type': 'call', 'children': ['15', '22']}, {'id': '15', 'type': 'attribute', 'children': ['16', '21']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_query'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '28']}, {'id': '23', 'type': 'subscript', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'PageView'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'User-Agent'"}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Count'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'PageView'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'group_by'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'PageView'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'User-Agent'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '56']}; {'id': '46', 'type': 'attribute', 'children': ['47', '55']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'Count'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'PageView'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tuples'}
def user_agents(self): return (self.get_query() .select( PageView.headers['User-Agent'], fn.Count(PageView.id)) .group_by(PageView.headers['User-Agent']) .order_by(fn.Count(PageView.id).desc()) .tuples())
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'languages'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '31']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'language'}, {'id': '9', 'type': 'subscript', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'PageView'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'Accept-Language'"}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'first_language'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'SubStr'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'language'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'StrPos'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'language'}; {'id': '30', 'type': 'string', 'children': [], 'value': "';'"}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'parenthesized_expression', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '75']}; {'id': '34', 'type': 'attribute', 'children': ['35', '74']}, {'id': '35', 'type': 'call', 'children': ['36', '61']}; {'id': '36', 'type': 'attribute', 'children': ['37', '60']}, {'id': '37', 'type': 'call', 'children': ['38', '58']}; {'id': '38', 'type': 'attribute', 'children': ['39', '57']}, {'id': '39', 'type': 'call', 'children': ['40', '47']}; {'id': '40', 'type': 'attribute', 'children': ['41', '46']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_query'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'select'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'first_language'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Count'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'PageView'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'group_by'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'first_language'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '73']}, {'id': '63', 'type': 'attribute', 'children': ['64', '72']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Count'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'PageView'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'tuples'}, {'id': '75', 'type': 'argument_list', 'children': []}
def languages(self): language = PageView.headers['Accept-Language'] first_language = fn.SubStr( language, 1, fn.StrPos(language, ';')) return (self.get_query() .select(first_language, fn.Count(PageView.id)) .group_by(first_language) .order_by(fn.Count(PageView.id).desc()) .tuples())
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'error_router'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'original_handler'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '7', 'type': 'block', 'children': ['8', '28']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_has_fr_route'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'try_statement', 'children': ['16', '24']}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'handle_error'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '24', 'type': 'except_clause', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'pass_statement', 'children': []}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'original_handler'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}
def error_router(self, original_handler, e): if self._has_fr_route(): try: return self.handle_error(e) except Exception: pass return original_handler(e)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'smooth_knn_dist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'distances'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'n_iter'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '64'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'local_connectivity'}, {'id': '11', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'bandwidth'}; {'id': '14', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '15', 'type': 'block', 'children': ['16', '27', '40', '53', '370']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '26'], 'value': '*'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'log2'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'bandwidth'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'rho'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'distances'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'distances'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '63']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'subscript', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'distances'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'block', 'children': ['64', '68', '72', '76', '82', '90', '186', '301', '307']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '67', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'NPY_INFINITY'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '75', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ith_distances'}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'distances'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ith_distances'}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '>'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ith_distances'}, {'id': '89', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '98', '166']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '97'], 'value': '>='}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'local_connectivity'}; {'id': '98', 'type': 'block', 'children': ['99', '111', '117']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'local_connectivity'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'interpolation'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '-'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'local_connectivity'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '117', 'type': 'if_statement', 'children': ['118', '121', '154']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '>'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'block', 'children': ['122', '132']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'rho'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '-'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '>'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'interpolation'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'SMOOTH_K_TOLERANCE'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'augmented_assignment', 'children': ['139', '142'], 'value': '+='}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'rho'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '*'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'interpolation'}; {'id': '144', 'type': 'parenthesized_expression', 'children': ['145']}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '149'], 'value': '-'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '-'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '154', 'type': 'else_clause', 'children': ['155']}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'rho'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '*'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'interpolation'}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'elif_clause', 'children': ['167', '174']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '173'], 'value': '>'}; {'id': '168', 'type': 'subscript', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'rho'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'non_zero_dists'}; {'id': '186', 'type': 'for_statement', 'children': ['187', '188', '192']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'n_iter'}; {'id': '192', 'type': 'block', 'children': ['193', '197', '244', '257']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'psum'}; {'id': '196', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '197', 'type': 'for_statement', 'children': ['198', '199', '208']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '203']}; {'id': '202', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '203', 'type': 'subscript', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'distances'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '207', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '208', 'type': 'block', 'children': ['209', '220']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '217'], 'value': '-'}, {'id': '213', 'type': 'subscript', 'children': ['214', '215', '216']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'distances'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'rho'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '220', 'type': 'if_statement', 'children': ['221', '224', '238']}, {'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': '>'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'augmented_assignment', 'children': ['227', '228'], 'value': '+='}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'psum'}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'unary_operator', 'children': ['234'], 'value': '-'}; {'id': '234', 'type': 'parenthesized_expression', 'children': ['235']}, {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '/'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '238', 'type': 'else_clause', 'children': ['239']}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'augmented_assignment', 'children': ['242', '243'], 'value': '+='}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'psum'}, {'id': '243', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '244', 'type': 'if_statement', 'children': ['245', '255']}, {'id': '245', 'type': 'comparison_operator', 'children': ['246', '254'], 'value': '<'}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'fabs'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '-'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'psum'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'SMOOTH_K_TOLERANCE'}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'break_statement', 'children': []}, {'id': '257', 'type': 'if_statement', 'children': ['258', '261', '275']}; {'id': '258', 'type': 'comparison_operator', 'children': ['259', '260'], 'value': '>'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'psum'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '261', 'type': 'block', 'children': ['262', '266']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '269', 'type': 'binary_operator', 'children': ['270', '274'], 'value': '/'}; {'id': '270', 'type': 'parenthesized_expression', 'children': ['271']}, {'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '+'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '274', 'type': 'float', 'children': [], 'value': '2.0'}, {'id': '275', 'type': 'else_clause', 'children': ['276']}; {'id': '276', 'type': 'block', 'children': ['277', '281']}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '281', 'type': 'if_statement', 'children': ['282', '285', '290']}; {'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': '=='}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'NPY_INFINITY'}, {'id': '285', 'type': 'block', 'children': ['286']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'augmented_assignment', 'children': ['288', '289'], 'value': '*='}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '289', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '290', 'type': 'else_clause', 'children': ['291']}, {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '295', 'type': 'binary_operator', 'children': ['296', '300'], 'value': '/'}; {'id': '296', 'type': 'parenthesized_expression', 'children': ['297']}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '+'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '300', 'type': 'float', 'children': [], 'value': '2.0'}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '306']}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '307', 'type': 'if_statement', 'children': ['308', '313', '341']}; {'id': '308', 'type': 'comparison_operator', 'children': ['309', '312'], 'value': '>'}, {'id': '309', 'type': 'subscript', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'rho'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '312', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '313', 'type': 'block', 'children': ['314']}; {'id': '314', 'type': 'if_statement', 'children': ['315', '327']}, {'id': '315', 'type': 'comparison_operator', 'children': ['316', '319'], 'value': '<'}; {'id': '316', 'type': 'subscript', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '319', 'type': 'binary_operator', 'children': ['320', '321'], 'value': '*'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'MIN_K_DIST_SCALE'}, {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'ith_distances'}, {'id': '327', 'type': 'block', 'children': ['328']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '333']}; {'id': '330', 'type': 'subscript', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '333', 'type': 'binary_operator', 'children': ['334', '335'], 'value': '*'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'MIN_K_DIST_SCALE'}, {'id': '335', 'type': 'call', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'ith_distances'}, {'id': '341', 'type': 'else_clause', 'children': ['342']}; {'id': '342', 'type': 'block', 'children': ['343']}, {'id': '343', 'type': 'if_statement', 'children': ['344', '356']}; {'id': '344', 'type': 'comparison_operator', 'children': ['345', '348'], 'value': '<'}, {'id': '345', 'type': 'subscript', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '348', 'type': 'binary_operator', 'children': ['349', '350'], 'value': '*'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'MIN_K_DIST_SCALE'}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'distances'}; {'id': '356', 'type': 'block', 'children': ['357']}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '362']}, {'id': '359', 'type': 'subscript', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '362', 'type': 'binary_operator', 'children': ['363', '364'], 'value': '*'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'MIN_K_DIST_SCALE'}; {'id': '364', 'type': 'call', 'children': ['365', '368']}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'distances'}; {'id': '370', 'type': 'return_statement', 'children': ['371']}, {'id': '371', 'type': 'expression_list', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'rho'}
def smooth_knn_dist(distances, k, n_iter=64, local_connectivity=1.0, bandwidth=1.0): target = np.log2(k) * bandwidth rho = np.zeros(distances.shape[0]) result = np.zeros(distances.shape[0]) for i in range(distances.shape[0]): lo = 0.0 hi = NPY_INFINITY mid = 1.0 ith_distances = distances[i] non_zero_dists = ith_distances[ith_distances > 0.0] if non_zero_dists.shape[0] >= local_connectivity: index = int(np.floor(local_connectivity)) interpolation = local_connectivity - index if index > 0: rho[i] = non_zero_dists[index - 1] if interpolation > SMOOTH_K_TOLERANCE: rho[i] += interpolation * (non_zero_dists[index] - non_zero_dists[index - 1]) else: rho[i] = interpolation * non_zero_dists[0] elif non_zero_dists.shape[0] > 0: rho[i] = np.max(non_zero_dists) for n in range(n_iter): psum = 0.0 for j in range(1, distances.shape[1]): d = distances[i, j] - rho[i] if d > 0: psum += np.exp(-(d / mid)) else: psum += 1.0 if np.fabs(psum - target) < SMOOTH_K_TOLERANCE: break if psum > target: hi = mid mid = (lo + hi) / 2.0 else: lo = mid if hi == NPY_INFINITY: mid *= 2 else: mid = (lo + hi) / 2.0 result[i] = mid if rho[i] > 0.0: if result[i] < MIN_K_DIST_SCALE * np.mean(ith_distances): result[i] = MIN_K_DIST_SCALE * np.mean(ith_distances) else: if result[i] < MIN_K_DIST_SCALE * np.mean(distances): result[i] = MIN_K_DIST_SCALE * np.mean(distances) return result, rho
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_visible_units'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '43']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '20']}, {'id': '11', 'type': 'attribute', 'children': ['12', '19']}; {'id': '12', 'type': 'attribute', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_obs'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'observation'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'raw_data'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'lambda', 'children': ['23', '25']}, {'id': '23', 'type': 'lambda_parameters', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '25', 'type': 'tuple', 'children': ['26', '31', '36', '40']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'z'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': '!='}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'owner'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'yield', 'children': ['46']}; {'id': '46', 'type': 'expression_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'point'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Point'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'build'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pos'}
def _visible_units(self): for u in sorted(self._obs.observation.raw_data.units, key=lambda u: (u.pos.z, u.owner != 16, -u.radius, u.tag)): yield u, point.Point.build(u.pos)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'linear'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'dictionary', 'children': []}, {'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'coords_kwargs'}, {'id': '19', 'type': 'block', 'children': ['20', '43', '67']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '28']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '27'], 'value': 'not'}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'uifc'"}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'concatenated_string', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'interp only works for a numeric type array. '"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'Given {}.'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ds'}; {'id': '46', 'type': 'call', 'children': ['47', '54']}, {'id': '47', 'type': 'attribute', 'children': ['48', '53']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_to_temp_dataset'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'interp'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '59', '62', '65']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}, {'id': '65', 'type': 'dictionary_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'coords_kwargs'}, {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': '_from_temp_dataset'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ds'}
def interp(self, coords=None, method='linear', assume_sorted=False, kwargs={}, **coords_kwargs): if self.dtype.kind not in 'uifc': raise TypeError('interp only works for a numeric type array. ' 'Given {}.'.format(self.dtype)) ds = self._to_temp_dataset().interp( coords, method=method, kwargs=kwargs, assume_sorted=assume_sorted, **coords_kwargs) return self._from_temp_dataset(ds)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interp_like'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'linear'"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'dictionary', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '39', '61']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '24']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '23'], 'value': 'not'}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '23', 'type': 'string', 'children': [], 'value': "'uifc'"}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'raise_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'concatenated_string', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'interp only works for a numeric type array. '"}, {'id': '33', 'type': 'string', 'children': [], 'value': "'Given {}.'"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ds'}; {'id': '42', 'type': 'call', 'children': ['43', '50']}, {'id': '43', 'type': 'attribute', 'children': ['44', '49']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_to_temp_dataset'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'interp_like'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55', '58']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_from_temp_dataset'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ds'}
def interp_like(self, other, method='linear', assume_sorted=False, kwargs={}): if self.dtype.kind not in 'uifc': raise TypeError('interp only works for a numeric type array. ' 'Given {}.'.format(self.dtype)) ds = self._to_temp_dataset().interp_like( other, method=method, kwargs=kwargs, assume_sorted=assume_sorted) return self._from_temp_dataset(ds)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_uniform_spaced'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '9', 'type': 'block', 'children': ['10', '22', '31']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'diffs'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isclose'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '45', '50']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'diffs'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'diffs'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'dictionary_splat', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def is_uniform_spaced(arr, **kwargs) -> bool: arr = np.array(arr, dtype=float) diffs = np.diff(arr) return bool(np.isclose(diffs.min(), diffs.max(), **kwargs))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'broadcast_variables'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '21']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dims_map'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_unified_dims'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dims_tuple'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dims_map'}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '24', 'type': 'generator_expression', 'children': ['25', '38']}, {'id': '25', 'type': 'conditional_expression', 'children': ['26', '32', '37'], 'value': 'if'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'set_dims'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dims_map'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': '!='}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dims_tuple'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '38', 'type': 'for_in_clause', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'var'}
def broadcast_variables(*variables): dims_map = _unified_dims(variables) dims_tuple = tuple(dims_map) return tuple(var.set_dims(dims_map) if var.dims != dims_tuple else var for var in variables)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'linear'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'dictionary', 'children': []}, {'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'coords_kwargs'}, {'id': '19', 'type': 'block', 'children': ['20', '25', '34', '46', '62', '93', '133', '139', '229', '243', '267', '284', '291', '320', '332', '339', '346', '366']}; {'id': '20', 'type': 'import_from_statement', 'children': ['21', '23']}, {'id': '21', 'type': 'relative_import', 'children': ['22']}; {'id': '22', 'type': 'import_prefix', 'children': []}, {'id': '23', 'type': 'dotted_name', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'missing'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'either_dict_or_kwargs'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'coords_kwargs'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'interp'"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'indexers'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_validate_indexers'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '49', 'type': 'conditional_expression', 'children': ['50', '51', '52'], 'value': 'if'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sortby'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'list_comprehension', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '62', 'type': 'function_definition', 'children': ['63', '64', '67']}, {'id': '63', 'type': 'function_name', 'children': [], 'value': 'maybe_variable'}; {'id': '64', 'type': 'parameters', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'try_statement', 'children': ['69', '76']}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_variables'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '76', 'type': 'except_clause', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'as_variable'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'tuple', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'subscript', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '93', 'type': 'function_definition', 'children': ['94', '95', '98']}; {'id': '94', 'type': 'function_name', 'children': [], 'value': '_validate_interp_indexer'}, {'id': '95', 'type': 'parameters', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'new_x'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'if_statement', 'children': ['100', '111', '127']}; {'id': '100', 'type': 'parenthesized_expression', 'children': ['101']}, {'id': '101', 'type': 'boolean_operator', 'children': ['102', '106'], 'value': 'and'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': '_contains_datetime_like_objects'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '106', 'type': 'not_operator', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_contains_datetime_like_objects'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'new_x'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'raise_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '125']}, {'id': '117', 'type': 'attribute', 'children': ['118', '124']}; {'id': '118', 'type': 'concatenated_string', 'children': ['119', '120', '121', '122', '123']}, {'id': '119', 'type': 'string', 'children': [], 'value': "'When interpolating over a datetime-like '"}; {'id': '120', 'type': 'string', 'children': [], 'value': "'coordinate, the coordinates to '"}, {'id': '121', 'type': 'string', 'children': [], 'value': "'interpolate to must be either datetime '"}; {'id': '122', 'type': 'string', 'children': [], 'value': "'strings or datetimes. '"}, {'id': '123', 'type': 'string', 'children': [], 'value': "'Instead got\\n{}'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_x'}, {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'tuple', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'new_x'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'for_statement', 'children': ['140', '143', '150']}; {'id': '140', 'type': 'pattern_list', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '143', 'type': 'call', 'children': ['144', '149']}; {'id': '144', 'type': 'attribute', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': '_variables'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'if_statement', 'children': ['152', '155']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'not'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'indexers'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '164', '210']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '163'], 'value': 'in'}; {'id': '158', 'type': 'attribute', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '163', 'type': 'string', 'children': [], 'value': "'uifc'"}; {'id': '164', 'type': 'block', 'children': ['165', '195']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'var_indexers'}; {'id': '168', 'type': 'dictionary_comprehension', 'children': ['169', '180', '189']}, {'id': '169', 'type': 'pair', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_validate_interp_indexer'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '179']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'maybe_variable'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '180', 'type': 'for_in_clause', 'children': ['181', '184']}, {'id': '181', 'type': 'pattern_list', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'indexers'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '188', 'type': 'argument_list', 'children': []}, {'id': '189', 'type': 'if_clause', 'children': ['190']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'in'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'missing'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'interp'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '208']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'var_indexers'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '208', 'type': 'dictionary_splat', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '210', 'type': 'elif_clause', 'children': ['211', '222']}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '213', 'type': 'generator_expression', 'children': ['214', '217']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'not'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'indexers'}, {'id': '217', 'type': 'for_in_clause', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '228']}, {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'coord_names'}; {'id': '232', 'type': 'call', 'children': ['233', '239']}, {'id': '233', 'type': 'attribute', 'children': ['234', '238']}; {'id': '234', 'type': 'call', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': '_coord_names'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '248', 'type': 'generator_expression', 'children': ['249', '252', '263']}, {'id': '249', 'type': 'tuple', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '252', 'type': 'for_in_clause', 'children': ['253', '256']}, {'id': '253', 'type': 'pattern_list', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '256', 'type': 'call', 'children': ['257', '262']}, {'id': '257', 'type': 'attribute', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '262', 'type': 'argument_list', 'children': []}, {'id': '263', 'type': 'if_clause', 'children': ['264']}; {'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': 'not'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'indexers'}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'selected'}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': '_replace_with_new_dims'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '280', '281']}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '279', 'type': 'argument_list', 'children': []}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'coord_names'}, {'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'indexers'}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '296', 'type': 'generator_expression', 'children': ['297', '304', '313']}, {'id': '297', 'type': 'tuple', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'to_index'}, {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'for_in_clause', 'children': ['305', '308']}, {'id': '305', 'type': 'pattern_list', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'indexers'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '312', 'type': 'argument_list', 'children': []}, {'id': '313', 'type': 'if_clause', 'children': ['314']}; {'id': '314', 'type': 'comparison_operator', 'children': ['315', '318'], 'value': '=='}, {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '318', 'type': 'tuple', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '325']}; {'id': '322', 'type': 'pattern_list', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'coord_vars'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'new_indexes'}, {'id': '325', 'type': 'parenthesized_expression', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'selected'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': '_get_indexers_coords_and_indexes'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'coord_vars'}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'call', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'new_indexes'}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}, {'id': '347', 'type': 'assignment', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'coord_names'}, {'id': '349', 'type': 'parenthesized_expression', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '364']}, {'id': '351', 'type': 'attribute', 'children': ['352', '363']}; {'id': '352', 'type': 'call', 'children': ['353', '359']}, {'id': '353', 'type': 'attribute', 'children': ['354', '358']}; {'id': '354', 'type': 'call', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '356', 'type': 'argument_list', 'children': ['357']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': '_coord_names'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'coord_vars'}; {'id': '366', 'type': 'return_statement', 'children': ['367']}, {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': '_replace_with_new_dims'}, {'id': '371', 'type': 'argument_list', 'children': ['372', '373', '374']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'coord_names'}; {'id': '374', 'type': 'keyword_argument', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'indexes'}
def interp(self, coords=None, method='linear', assume_sorted=False, kwargs={}, **coords_kwargs): from . import missing coords = either_dict_or_kwargs(coords, coords_kwargs, 'interp') indexers = OrderedDict(self._validate_indexers(coords)) obj = self if assume_sorted else self.sortby([k for k in coords]) def maybe_variable(obj, k): try: return obj._variables[k] except KeyError: return as_variable((k, range(obj.dims[k]))) def _validate_interp_indexer(x, new_x): if (_contains_datetime_like_objects(x) and not _contains_datetime_like_objects(new_x)): raise TypeError('When interpolating over a datetime-like ' 'coordinate, the coordinates to ' 'interpolate to must be either datetime ' 'strings or datetimes. ' 'Instead got\n{}'.format(new_x)) else: return (x, new_x) variables = OrderedDict() for name, var in obj._variables.items(): if name not in indexers: if var.dtype.kind in 'uifc': var_indexers = { k: _validate_interp_indexer(maybe_variable(obj, k), v) for k, v in indexers.items() if k in var.dims } variables[name] = missing.interp( var, var_indexers, method, **kwargs) elif all(d not in indexers for d in var.dims): variables[name] = var coord_names = set(variables).intersection(obj._coord_names) indexes = OrderedDict( (k, v) for k, v in obj.indexes.items() if k not in indexers) selected = self._replace_with_new_dims( variables.copy(), coord_names, indexes=indexes) variables.update(indexers) indexes.update( (k, v.to_index()) for k, v in indexers.items() if v.dims == (k,) ) coord_vars, new_indexes = ( selected._get_indexers_coords_and_indexes(coords)) variables.update(coord_vars) indexes.update(new_indexes) coord_names = (set(variables) .intersection(obj._coord_names) .union(coord_vars)) return self._replace_with_new_dims( variables, coord_names, indexes=indexes)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interp_like'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'linear'"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'dictionary', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '26', '32', '38', '71', '75', '87']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'alignment'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'reindex_like_indexers'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'numeric_coords'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'object_coords'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'for_statement', 'children': ['39', '42', '47']}, {'id': '39', 'type': 'pattern_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '56', '63']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '55'], 'value': 'in'}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'uifcMm'"}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '62']}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'numeric_coords'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '70']}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'object_coords'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ds'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'if_statement', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'object_coords'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ds'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'reindex'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'object_coords'}, {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ds'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'interp'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94', '95', '96']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'numeric_coords'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'}
def interp_like(self, other, method='linear', assume_sorted=False, kwargs={}): coords = alignment.reindex_like_indexers(self, other) numeric_coords = OrderedDict() object_coords = OrderedDict() for k, v in coords.items(): if v.dtype.kind in 'uifcMm': numeric_coords[k] = v else: object_coords[k] = v ds = self if object_coords: ds = self.reindex(object_coords) return ds.interp(numeric_coords, method, assume_sorted, kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'transpose'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '7', 'type': 'block', 'children': ['8', '40', '48', '90']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '23']}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '17'], 'value': '^'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'raise_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '32'], 'value': '%'}, {'id': '29', 'type': 'concatenated_string', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'arguments to transpose (%s) must be '"}, {'id': '31', 'type': 'string', 'children': [], 'value': "'permuted dataset dimensions (%s)'"}; {'id': '32', 'type': 'tuple', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ds'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'for_statement', 'children': ['49', '52', '59']}, {'id': '49', 'type': 'pattern_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '52', 'type': 'call', 'children': ['53', '58']}, {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_variables'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'block', 'children': ['60', '76']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'var_dims'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '65', 'type': 'generator_expression', 'children': ['66', '67', '70']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '67', 'type': 'for_in_clause', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '70', 'type': 'if_clause', 'children': ['71']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '83']}; {'id': '78', 'type': 'subscript', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ds'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_variables'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'transpose'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'list_splat', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'var_dims'}; {'id': '90', 'type': 'return_statement', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ds'}
def transpose(self, *dims): if dims: if set(dims) ^ set(self.dims): raise ValueError('arguments to transpose (%s) must be ' 'permuted dataset dimensions (%s)' % (dims, tuple(self.dims))) ds = self.copy() for name, var in self._variables.items(): var_dims = tuple(dim for dim in dims if dim in var.dims) ds._variables[name] = var.transpose(*var_dims) return ds
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_dask_dataframe'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'dim_order'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '18', '24', '69', '85', '92', '110', '119', '123', '233', '245', '281']}; {'id': '12', 'type': 'import_statement', 'children': ['13']}, {'id': '13', 'type': 'aliased_import', 'children': ['14', '17']}; {'id': '14', 'type': 'dotted_name', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dask'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '18', 'type': 'import_statement', 'children': ['19']}, {'id': '19', 'type': 'aliased_import', 'children': ['20', '23']}; {'id': '20', 'type': 'dotted_name', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dask'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dataframe'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dd'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28', '38']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dim_order'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dim_order'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '38', 'type': 'elif_clause', 'children': ['39', '50']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '!='}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dim_order'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'concatenated_string', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'dim_order {} does not match the set of dimensions on this '"}, {'id': '59', 'type': 'string', 'children': [], 'value': "'Dataset: {}'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dim_order'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ordered_dims'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '74', 'type': 'generator_expression', 'children': ['75', '82']}, {'id': '75', 'type': 'tuple', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '77', 'type': 'subscript', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'dim_order'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ordered_dims'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '97', 'type': 'generator_expression', 'children': ['98', '99', '104']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '104', 'type': 'if_clause', 'children': ['105']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'not'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'data_vars'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'series_list'}; {'id': '122', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '126', 'type': 'block', 'children': ['127', '174', '189', '207', '226']}, {'id': '127', 'type': 'try_statement', 'children': ['128', '137']}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '132', 'type': 'subscript', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '137', 'type': 'except_clause', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '139', 'type': 'block', 'children': ['140', '148', '165']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '143', 'type': 'subscript', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157', '160']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'chunks'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'int64'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'Variable'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '173']}, {'id': '171', 'type': 'tuple', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '180']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'IndexVariable'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'to_base_variable'}; {'id': '188', 'type': 'argument_list', 'children': []}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'dask_array'}; {'id': '192', 'type': 'attribute', 'children': ['193', '206']}, {'id': '193', 'type': 'call', 'children': ['194', '202']}; {'id': '194', 'type': 'attribute', 'children': ['195', '201']}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'set_dims'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ordered_dims'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'series'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'dd'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'from_array'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '222']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'dask_array'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'unary_operator', 'children': ['221'], 'value': '-'}, {'id': '221', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '224', 'type': 'list', 'children': ['225'], 'value': '[name]'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'series_list'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'series'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'dd'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'series_list'}; {'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '245', 'type': 'if_statement', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'set_index'}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'if_statement', 'children': ['249', '255', '270']}, {'id': '249', 'type': 'comparison_operator', 'children': ['250', '254'], 'value': '=='}; {'id': '250', 'type': 'call', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'dim_order'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '255', 'type': 'block', 'children': ['256', '261']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '260']}; {'id': '258', 'type': 'tuple_pattern', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'dim_order'}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '264', 'type': 'call', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '270', 'type': 'else_clause', 'children': ['271']}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'set_index'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'dim_order'}, {'id': '281', 'type': 'return_statement', 'children': ['282']}
def to_dask_dataframe(self, dim_order=None, set_index=False): import dask.array as da import dask.dataframe as dd if dim_order is None: dim_order = list(self.dims) elif set(dim_order) != set(self.dims): raise ValueError( 'dim_order {} does not match the set of dimensions on this ' 'Dataset: {}'.format(dim_order, list(self.dims))) ordered_dims = OrderedDict((k, self.dims[k]) for k in dim_order) columns = list(ordered_dims) columns.extend(k for k in self.coords if k not in self.dims) columns.extend(self.data_vars) series_list = [] for name in columns: try: var = self.variables[name] except KeyError: size = self.dims[name] data = da.arange(size, chunks=size, dtype=np.int64) var = Variable((name,), data) if isinstance(var, IndexVariable): var = var.to_base_variable() dask_array = var.set_dims(ordered_dims).chunk(self.chunks).data series = dd.from_array(dask_array.reshape(-1), columns=[name]) series_list.append(series) df = dd.concat(series_list, axis=1) if set_index: if len(dim_order) == 1: (dim,) = dim_order df = df.set_index(dim) else: df = df.set_index(dim_order) return df
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'indexes_coords'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '20', '37', '49', '56', '72', '80', '94', '100', '113', '132', '145', '151', '184']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '13']}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'indexes_coords'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'in'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '23', 'type': 'list', 'children': ['24', '25'], 'value': "['linear', 'nearest']"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'linear'"}, {'id': '25', 'type': 'string', 'children': [], 'value': "'nearest'"}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}, {'id': '29', 'type': 'pattern_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'indexes_coords'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_localize'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'indexes_coords'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}, {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'bounds_error'"}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': "'bounds_error'"}; {'id': '48', 'type': 'False', 'children': []}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'indexes_coords'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'pattern_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'new_x'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'list_splat', 'children': ['65']}, {'id': '65', 'type': 'list_comprehension', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'indexes_coords'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'destination'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'broadcast_variables'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'list_splat', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'new_x'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'broadcast_dims'}, {'id': '83', 'type': 'list_comprehension', 'children': ['84', '85', '90']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '85', 'type': 'for_in_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '90', 'type': 'if_clause', 'children': ['91']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'not'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'original_dims'}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'broadcast_dims'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'new_dims'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '+'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'broadcast_dims'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'destination'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'interped'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'interp_func'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '128', '129', '130', '131']}, {'id': '119', 'type': 'attribute', 'children': ['120', '127']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'transpose'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'list_splat', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'original_dims'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'Variable'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'new_dims'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'interped'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'out_dims'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'OrderedSet'}; {'id': '150', 'type': 'argument_list', 'children': []}, {'id': '151', 'type': 'for_statement', 'children': ['152', '153', '156']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'if_statement', 'children': ['158', '161', '175']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'in'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'out_dims'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'attribute', 'children': ['169', '174']}, {'id': '169', 'type': 'subscript', 'children': ['170', '173']}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'indexes_coords'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '175', 'type': 'else_clause', 'children': ['176']}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'out_dims'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '184', 'type': 'return_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'transpose'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'list_splat', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}
def interp(var, indexes_coords, method, **kwargs): if not indexes_coords: return var.copy() if method in ['linear', 'nearest']: var, indexes_coords = _localize(var, indexes_coords) kwargs['bounds_error'] = kwargs.get('bounds_error', False) dims = list(indexes_coords) x, new_x = zip(*[indexes_coords[d] for d in dims]) destination = broadcast_variables(*new_x) broadcast_dims = [d for d in var.dims if d not in dims] original_dims = broadcast_dims + dims new_dims = broadcast_dims + list(destination[0].dims) interped = interp_func(var.transpose(*original_dims).data, x, destination, method, kwargs) result = Variable(new_dims, interped, attrs=var.attrs) out_dims = OrderedSet() for d in var.dims: if d in dims: out_dims.update(indexes_coords[d][1].dims) else: out_dims.add(d) return result.transpose(*tuple(out_dims))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'coerce_pandas_values'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '20', '24', '102']}; {'id': '6', 'type': 'import_from_statement', 'children': ['7', '11']}, {'id': '7', 'type': 'relative_import', 'children': ['8', '9']}; {'id': '8', 'type': 'import_prefix', 'children': []}, {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dataset'}, {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Dataset'}, {'id': '13', 'type': 'import_from_statement', 'children': ['14', '18']}; {'id': '14', 'type': 'relative_import', 'children': ['15', '16']}, {'id': '15', 'type': 'import_prefix', 'children': []}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dataarray'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'DataArray'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '23', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '27', 'type': 'block', 'children': ['28', '95']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '34', '39']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41', '47', '65']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'if_statement', 'children': ['48', '53']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'PANDAS_TYPES'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'for_statement', 'children': ['66', '69', '74']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75', '89']}, {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'PANDAS_TYPES'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'DataArray'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '94']}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'out'}
def coerce_pandas_values(objects): from .dataset import Dataset from .dataarray import DataArray out = [] for obj in objects: if isinstance(obj, Dataset): variables = obj else: variables = OrderedDict() if isinstance(obj, PANDAS_TYPES): obj = OrderedDict(obj.iteritems()) for k, v in obj.items(): if isinstance(v, PANDAS_TYPES): v = DataArray(v) variables[k] = v out.append(variables) return out
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique_value_groups'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ar'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23', '37', '60']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '14']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'inverse'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'factorize'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ar'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '26', 'type': 'list_comprehension', 'children': ['27', '28']}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '37', 'type': 'for_statement', 'children': ['38', '41', '45']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'inverse'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '>='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '58']}, {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'expression_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'groups'}
def unique_value_groups(ar, sort=True): inverse, values = pd.factorize(ar, sort=sort) groups = [[] for _ in range(len(values))] for n, g in enumerate(inverse): if g >= 0: groups[g].append(n) return values, groups
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '46']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10', '36']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'st'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'STAGES'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '21', 'type': 'block', 'children': ['22', '35']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '25', 'type': 'tuple', 'children': ['26', '32']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'STAGES'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '35', 'type': 'break_statement', 'children': []}; {'id': '36', 'type': 'else_clause', 'children': ['37']}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '41', 'type': 'tuple', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'STAGES'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '67'], 'value': '+'}; {'id': '48', 'type': 'tuple', 'children': ['49', '55', '61']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'major'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'minor'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'patch'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'stage'}
def order(self): if self.stage: for st in STAGES: if st in self.stage: stage = (STAGES.index(st), self.stage) break else: stage = (len(STAGES),) return (int(self.major), int(self.minor), int(self.patch)) + stage
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zadd'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'nx'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'xx'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ch'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'incr'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20', '29', '39', '56', '60', '64', '79', '94', '109', '130', '155']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '23']}, {'id': '21', 'type': 'not_operator', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'raise_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'DataError'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"ZADD requires at least one element/score pair"'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '32'], 'value': 'and'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'xx'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'raise_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'DataError'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"ZADD allows either \'nx\' or \'xx\', not both"'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '48']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '42'], 'value': 'and'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'incr'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '47'], 'value': '!='}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'raise_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'DataError'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'concatenated_string', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': '"ZADD option \'incr\' only works when passing a "'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"single element/score pair"'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pieces'}, {'id': '59', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '63', 'type': 'dictionary', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'pieces'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Token'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'get_token'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'NX'"}, {'id': '79', 'type': 'if_statement', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'xx'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'Token'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_token'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'XX'"}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'ch'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pieces'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'Token'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_token'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'CH'"}, {'id': '109', 'type': 'if_statement', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'incr'}, {'id': '111', 'type': 'block', 'children': ['112', '124']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'Token'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'get_token'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'INCR'"}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'as_score'"}, {'id': '129', 'type': 'True', 'children': []}; {'id': '130', 'type': 'for_statement', 'children': ['131', '132', '136']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '136', 'type': 'block', 'children': ['137', '146']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'pieces'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pair'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '155', 'type': 'return_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162', '163', '165']}, {'id': '161', 'type': 'string', 'children': [], 'value': "'ZADD'"}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '163', 'type': 'list_splat', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'pieces'}, {'id': '165', 'type': 'dictionary_splat', 'children': ['166']}
def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False): if not mapping: raise DataError("ZADD requires at least one element/score pair") if nx and xx: raise DataError("ZADD allows either 'nx' or 'xx', not both") if incr and len(mapping) != 1: raise DataError("ZADD option 'incr' only works when passing a " "single element/score pair") pieces = [] options = {} if nx: pieces.append(Token.get_token('NX')) if xx: pieces.append(Token.get_token('XX')) if ch: pieces.append(Token.get_token('CH')) if incr: pieces.append(Token.get_token('INCR')) options['as_score'] = True for pair in iteritems(mapping): pieces.append(pair[1]) pieces.append(pair[0]) return self.execute_command('ZADD', name, *pieces, **options)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zincrby'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '8', 'type': 'block', 'children': ['9', '11']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': '"Increment the score of ``value`` in sorted set ``name`` by ``amount``"'}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19', '20']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'ZINCRBY'"}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'amount'}
def zincrby(self, name, amount, value): "Increment the score of ``value`` in sorted set ``name`` by ``amount``" return self.execute_command('ZINCRBY', name, amount, value)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zinterstore'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'aggregate'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_zaggregate'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19', '20']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'ZINTERSTORE'"}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dest'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'keys'}
def zinterstore(self, dest, keys, aggregate=None): return self._zaggregate('ZINTERSTORE', dest, keys, aggregate)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zlexcount'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17', '18']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'ZLEXCOUNT'"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'min'}
def zlexcount(self, name, min, max): return self.execute_command('ZLEXCOUNT', name, min, max)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zpopmax'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '22', '29']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '21'], 'value': 'or'}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '19'], 'value': 'and'}, {'id': '15', 'type': 'parenthesized_expression', 'children': ['16']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'list', 'children': ['20'], 'value': '[count]'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '25', 'type': 'dictionary', 'children': ['26']}; {'id': '26', 'type': 'pair', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': "'withscores'"}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37', '39']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'ZPOPMAX'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '37', 'type': 'list_splat', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '39', 'type': 'dictionary_splat', 'children': ['40']}
def zpopmax(self, name, count=None): args = (count is not None) and [count] or [] options = { 'withscores': True } return self.execute_command('ZPOPMAX', name, *args, **options)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zpopmin'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '22', '29']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '21'], 'value': 'or'}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '19'], 'value': 'and'}, {'id': '15', 'type': 'parenthesized_expression', 'children': ['16']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'list', 'children': ['20'], 'value': '[count]'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '25', 'type': 'dictionary', 'children': ['26']}; {'id': '26', 'type': 'pair', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': "'withscores'"}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37', '39']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'ZPOPMIN'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '37', 'type': 'list_splat', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '39', 'type': 'dictionary_splat', 'children': ['40']}
def zpopmin(self, name, count=None): args = (count is not None) and [count] or [] options = { 'withscores': True } return self.execute_command('ZPOPMIN', name, *args, **options)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bzpopmax'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'block', 'children': ['10', '19', '27', '34']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'list_or_args'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'execute_command'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'BZPOPMAX'"}, {'id': '41', 'type': 'list_splat', 'children': ['42']}
def bzpopmax(self, keys, timeout=0): if timeout is None: timeout = 0 keys = list_or_args(keys, None) keys.append(timeout) return self.execute_command('BZPOPMAX', *keys)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bzpopmin'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'block', 'children': ['10', '19', '27', '34']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'list_or_args'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'execute_command'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'BZPOPMIN'"}, {'id': '41', 'type': 'list_splat', 'children': ['42']}
def bzpopmin(self, keys, timeout=0): if timeout is None: timeout = 0 keys = list_or_args(keys, None) keys.append(timeout) return self.execute_command('BZPOPMIN', *keys)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebylex'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17', '18']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'ZREMRANGEBYLEX'"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'min'}
def zremrangebylex(self, name, min, max): return self.execute_command('ZREMRANGEBYLEX', name, min, max)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebyrank'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17', '18']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'ZREMRANGEBYRANK'"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'min'}
def zremrangebyrank(self, name, min, max): return self.execute_command('ZREMRANGEBYRANK', name, min, max)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort_k_smallest'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '43', '57', '63']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'intp'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '35']}, {'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'or'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '>='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '46', 'type': 'subscript', 'children': ['47', '54']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'argpartition'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '54', 'type': 'slice', 'children': ['55', '56']}, {'id': '55', 'type': 'colon', 'children': []}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'values'}
def argsort_k_smallest(x, k): if k == 0: return np.array([], dtype=np.intp) if k is None or k >= len(x): return np.argsort(x) indices = np.argpartition(x, k)[:k] values = x[indices] return indices[np.argsort(values)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'lookup'}, {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source_id'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'schema_id'}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'try_statement', 'children': ['14', '157']}; {'id': '14', 'type': 'block', 'children': ['15', '25', '62', '74', '86', '103', '112', '125', '133', '141', '149', '155']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Schema'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23', '24']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'source_id'}; {'id': '22', 'type': 'string', 'children': [], 'value': "''"}, {'id': '23', 'type': 'string', 'children': [], 'value': "''"}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '34']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Schema'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'lookup'}, {'id': '33', 'type': 'string', 'children': [], 'value': '"cb"'}; {'id': '34', 'type': 'block', 'children': ['35', '44']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"vcx_schema_get_attributes: Creating callback"'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Schema'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cb'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'create_cb'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'CFUNCTYPE'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59', '60', '61']}, {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'c_uint32'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'c_uint32'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'c_uint32'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'c_char_p'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'c_source_id'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'c_char_p'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'source_id'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'c_schema_id'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'c_char_p'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'schema_id'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '91']}; {'id': '88', 'type': 'pattern_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '91', 'type': 'await', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'do_call'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97', '98']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'vcx_schema_get_attributes'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'c_source_id'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'c_schema_id'}; {'id': '98', 'type': 'attribute', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'Schema'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'cb'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '110']}, {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'string', 'children': [], 'value': '"created schema object"'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'schema_result'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'loads'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '124', 'type': 'argument_list', 'children': []}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'schema_result'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'schema_result'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'schema_result'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'version'"}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'handle'}, {'id': '155', 'type': 'return_statement', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '157', 'type': 'except_clause', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'raise_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'VcxError'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ErrorCode'}
async def lookup(source_id: str, schema_id: str): try: schema = Schema(source_id, '', '', []) if not hasattr(Schema.lookup, "cb"): schema.logger.debug("vcx_schema_get_attributes: Creating callback") Schema.lookup.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) c_source_id = c_char_p(source_id.encode('utf-8')) c_schema_id = c_char_p(schema_id.encode('utf-8')) handle, data = await do_call('vcx_schema_get_attributes', c_source_id, c_schema_id, Schema.lookup.cb) schema.logger.debug("created schema object") schema_result = json.loads(data.decode()) schema.attrs = schema_result['data'] schema.name = schema_result['name'] schema.version = schema_result['version'] schema.handle = handle return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interleave_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '6', 'type': 'block', 'children': ['7', '30']}, {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'interleave'}, {'id': '9', 'type': 'parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'string', 'children': [], 'value': "''"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'list_comprehension', 'children': ['19', '20', '27']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'list_splat', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '52']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "''"}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'interleave'}, {'id': '41', 'type': 'generator_expression', 'children': ['42', '47']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'016b'"}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '49', 'type': 'tuple', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'base'}
def interleave_keys(a, b): def interleave(args): return ''.join([x for t in zip(*args) for x in t]) return int(''.join(interleave(format(x, '016b') for x in (a, b))), base=2)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pool'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'batch_size_fn'}, {'id': '9', 'type': 'lambda', 'children': ['10', '14']}; {'id': '10', 'type': 'lambda_parameters', 'children': ['11', '12', '13']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sofar'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'random_shuffler'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'shuffle'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort_within_batch'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '36']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'random_shuffler'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'random_shuffler'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'shuffle'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '46']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'batch'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42', '45']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '*'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '100'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'batch_size_fn'}; {'id': '46', 'type': 'block', 'children': ['47', '72']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'p_batch'}; {'id': '50', 'type': 'conditional_expression', 'children': ['51', '63', '64', '65', '66'], 'value': 'if'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'batch'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '61', '62']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'batch_size_fn'}, {'id': '63', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort_within_batch'}, {'id': '65', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'batch'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'batch_size'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'batch_size_fn'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '74', '88']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'shuffle'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '84']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'random_shuffler'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'p_batch'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'yield', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '88', 'type': 'else_clause', 'children': ['89']}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'for_statement', 'children': ['91', '92', '96']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'p_batch'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'yield', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'b'}
def pool(data, batch_size, key, batch_size_fn=lambda new, count, sofar: count, random_shuffler=None, shuffle=False, sort_within_batch=False): if random_shuffler is None: random_shuffler = random.shuffle for p in batch(data, batch_size * 100, batch_size_fn): p_batch = batch(sorted(p, key=key), batch_size, batch_size_fn) \ if sort_within_batch \ else batch(p, batch_size, batch_size_fn) if shuffle: for b in random_shuffler(list(p_batch)): yield b else: for b in list(p_batch): yield b
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'data'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '63']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10', '25', '55']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'xs'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '25', 'type': 'elif_clause', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'shuffle'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'xs'}, {'id': '33', 'type': 'list_comprehension', 'children': ['34', '39']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'random_shuffler'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dataset'}, {'id': '55', 'type': 'else_clause', 'children': ['56']}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'xs'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dataset'}, {'id': '63', 'type': 'return_statement', 'children': ['64']}
def data(self): if self.sort: xs = sorted(self.dataset, key=self.sort_key) elif self.shuffle: xs = [self.dataset[i] for i in self.random_shuffler(range(len(self.dataset)))] else: xs = self.dataset return xs
{'id': '0', 'type': 'module', 'children': ['1', '302']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'color_table'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'inline'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'as_html'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '181', '243', '251']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '27', '52', '141']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '27', 'type': 'block', 'children': ['28', '32', '43']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'c_'}, {'id': '31', 'type': 'string', 'children': [], 'value': "''"}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'rgb_tup'}, {'id': '35', 'type': 'list_comprehension', 'children': ['36', '40']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'normalize'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'rgb_tup'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'elif_clause', 'children': ['53', '58']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '58', 'type': 'block', 'children': ['59', '63', '92', '128']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '62', 'type': 'string', 'children': [], 'value': "''"}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '80']}, {'id': '67', 'type': 'tuple', 'children': ['68', '69', '73']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'normalize'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'hex_to_hsv'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'normalize'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '80', 'type': 'for_in_clause', 'children': ['81', '84']}, {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'if_statement', 'children': ['93', '94', '110']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort_values'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'rgb_tup'}, {'id': '131', 'type': 'list_comprehension', 'children': ['132', '135']}; {'id': '132', 'type': 'tuple', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '135', 'type': 'for_in_clause', 'children': ['136', '140']}; {'id': '136', 'type': 'pattern_list', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143', '150']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'normalize'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '154', '174']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '>'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'rgb_tup'}; {'id': '158', 'type': 'subscript', 'children': ['159', '169']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'color_range'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '169', 'type': 'slice', 'children': ['170', '171', '172']}; {'id': '170', 'type': 'colon', 'children': []}, {'id': '171', 'type': 'colon', 'children': []}; {'id': '172', 'type': 'unary_operator', 'children': ['173'], 'value': '-'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'else_clause', 'children': ['175']}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'rgb_tup'}, {'id': '179', 'type': 'list', 'children': ['180'], 'value': '[c_]'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'c_'}, {'id': '181', 'type': 'function_definition', 'children': ['182', '183', '185']}; {'id': '182', 'type': 'function_name', 'children': [], 'value': '_color'}, {'id': '183', 'type': 'parameters', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '185', 'type': 'block', 'children': ['186', '216', '238']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '195', '207']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '194'], 'value': '<'}; {'id': '188', 'type': 'subscript', 'children': ['189', '193']}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'hex_to_hsv'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '193', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '194', 'type': 'float', 'children': [], 'value': '.5'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199', '200']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '199', 'type': 'ERROR', 'children': []}; {'id': '200', 'type': 'assignment', 'children': ['201', '202', '206']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'shadow'}; {'id': '202', 'type': 'ERROR', 'children': ['203', '204', '205']}, {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'px'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '207', 'type': 'else_clause', 'children': ['208']}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212', '213']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '212', 'type': 'ERROR', 'children': []}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'shadow'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'0 1px 0 rgba(255,255,255,0.6)'"}; {'id': '216', 'type': 'if_statement', 'children': ['217', '220', '232']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '=='}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'border'}; {'id': '224', 'type': 'ERROR', 'children': []}, {'id': '225', 'type': 'assignment', 'children': ['226', '227', '230']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'border'}, {'id': '227', 'type': 'ERROR', 'children': ['228', '229']}; {'id': '228', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'px'}; {'id': '230', 'type': 'type', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'solid'}; {'id': '232', 'type': 'else_clause', 'children': ['233']}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'border'}, {'id': '237', 'type': 'string', 'children': [], 'value': "''"}; {'id': '238', 'type': 'return_statement', 'children': ['239']}, {'id': '239', 'type': 'expression_list', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'shadow'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'border'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '246', 'type': 'conditional_expression', 'children': ['247', '248', '250'], 'value': 'if'}, {'id': '247', 'type': 'string', 'children': [], 'value': '\'<ul style="list-style-type: none;">\''}; {'id': '248', 'type': 'not_operator', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'inline'}; {'id': '250', 'type': 'string', 'children': [], 'value': "''"}, {'id': '251', 'type': 'for_statement', 'children': ['252', '253', '254']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'rgb_tup'}; {'id': '254', 'type': 'block', 'children': ['255', '278']}, {'id': '255', 'type': 'if_statement', 'children': ['256', '261', '272']}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '261', 'type': 'block', 'children': ['262', '268']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '267']}; {'id': '264', 'type': 'pattern_list', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'augmented_assignment', 'children': ['270', '271'], 'value': '+='}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '271', 'type': 'string', 'children': [], 'value': "' : '"}; {'id': '272', 'type': 'else_clause', 'children': ['273']}, {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '277', 'type': 'string', 'children': [], 'value': "''"}; {'id': '278', 'type': 'if_statement', 'children': ['279', '280', '290']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'inline'}; {'id': '280', 'type': 'block', 'children': ['281']}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'augmented_assignment', 'children': ['283', '284'], 'value': '+='}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '284', 'type': 'call', 'children': ['285', '288']}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'string', 'children': [], 'value': '\'<div style="background-color:{0};height:20px;width:20px;display:inline-block;"></div>\''}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '290', 'type': 'else_clause', 'children': ['291']}, {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '298']}; {'id': '294', 'type': 'pattern_list', 'children': ['295', '296', '297']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'shadow'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'border'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': '_color'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '302', 'type': 'ERROR', 'children': ['303', '304', '327', '328']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '304', 'type': 'binary_operator', 'children': ['305', '325', '326'], 'value': '+'}, {'id': '305', 'type': 'binary_operator', 'children': ['306', '320'], 'value': '+'}; {'id': '306', 'type': 'binary_operator', 'children': ['307', '319'], 'value': '+'}, {'id': '307', 'type': 'binary_operator', 'children': ['308', '318'], 'value': '+'}; {'id': '308', 'type': 'binary_operator', 'children': ['309', '317'], 'value': '+'}, {'id': '309', 'type': 'binary_operator', 'children': ['310', '316'], 'value': '+'}; {'id': '310', 'type': 'binary_operator', 'children': ['311', '315'], 'value': '+'}, {'id': '311', 'type': 'binary_operator', 'children': ['312', '314'], 'value': '+'}; {'id': '312', 'type': 'unary_operator', 'children': ['313'], 'value': '+'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'border'}; {'id': '314', 'type': 'comment', 'children': []}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '316', 'type': 'comment', 'children': []}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '318', 'type': 'comment', 'children': []}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '320', 'type': 'call', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '324', 'type': 'argument_list', 'children': []}, {'id': '325', 'type': 'ERROR', 'children': []}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'span'}, {'id': '327', 'type': 'ERROR', 'children': []}
def color_table(color, N=1, sort=False, sort_values=False, inline=False, as_html=False): if isinstance(color, list): c_ = '' rgb_tup = [normalize(c) for c in color] if sort: rgb_tup.sort() elif isinstance(color, dict): c_ = '' items = [(k, normalize(v), hex_to_hsv(normalize(v))) for k, v in list(color.items())] if sort_values: items = sorted(items, key=operator.itemgetter(2)) elif sort: items = sorted(items, key=operator.itemgetter(0)) rgb_tup = [(k, v) for k, v, _ in items] else: c_ = normalize(color) if N > 1: rgb_tup = np.array(color_range(c_, N))[::-1] else: rgb_tup = [c_] def _color(c): if hex_to_hsv(c)[2] < .5: color = " shadow = '0 1px 0 else: color = " shadow = '0 1px 0 rgba(255,255,255,0.6)' if c == c_: border = " border: 1px solid else: border = '' return color, shadow, border s = '<ul style="list-style-type: none;">' if not inline else '' for c in rgb_tup: if isinstance(c, tuple): k, c = c k += ' : ' else: k = '' if inline: s += '<div style="background-color:{0};height:20px;width:20px;display:inline-block;"></div>'.format( c) else: color, shadow, border = _color(c) s += + border + """line-height:30px;background-color:""" + c + """;"> <span style=" text-shadow:; color:""" + color + """;">""" + k + c.upper() + """</span> </li>
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_nearest_edge'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'point'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '28', '43', '69', '84', '92', '99', '119']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'gdf'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'graph_to_gdfs'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '25']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '24', 'type': 'False', 'children': []}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fill_edge_geometry'}, {'id': '27', 'type': 'True', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'graph_edges'}, {'id': '31', 'type': 'call', 'children': ['32', '42']}; {'id': '32', 'type': 'attribute', 'children': ['33', '41']}, {'id': '33', 'type': 'attribute', 'children': ['34', '40']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'gdf'}; {'id': '36', 'type': 'list', 'children': ['37', '38', '39'], 'value': '["geometry", "u", "v"]'}, {'id': '37', 'type': 'string', 'children': [], 'value': '"geometry"'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"u"'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"v"'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'edges_with_distances'}; {'id': '46', 'type': 'list_comprehension', 'children': ['47', '66']}, {'id': '47', 'type': 'tuple', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'graph_edge'}, {'id': '49', 'type': 'call', 'children': ['50', '62']}; {'id': '50', 'type': 'attribute', 'children': ['51', '61']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Point'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'point'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'distance'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'graph_edge'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'graph_edge'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'graph_edges'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'edges_with_distances'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'edges_with_distances'}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '78', 'type': 'lambda', 'children': ['79', '81']}, {'id': '79', 'type': 'lambda_parameters', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'closest_edge_to_point'}, {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'edges_with_distances'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '98']}; {'id': '94', 'type': 'pattern_list', 'children': ['95', '96', '97']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'geometry'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'closest_edge_to_point'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'Found nearest edge ({}) to point {} in {:,.2f} seconds'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '111', '112']}; {'id': '108', 'type': 'tuple', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'point'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '118'], 'value': '-'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'expression_list', 'children': ['121', '122', '123']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'geometry'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'v'}
def get_nearest_edge(G, point): start_time = time.time() gdf = graph_to_gdfs(G, nodes=False, fill_edge_geometry=True) graph_edges = gdf[["geometry", "u", "v"]].values.tolist() edges_with_distances = [ ( graph_edge, Point(tuple(reversed(point))).distance(graph_edge[0]) ) for graph_edge in graph_edges ] edges_with_distances = sorted(edges_with_distances, key=lambda x: x[1]) closest_edge_to_point = edges_with_distances[0][0] geometry, u, v = closest_edge_to_point log('Found nearest edge ({}) to point {} in {:,.2f} seconds'.format((u, v), point, time.time() - start_time)) return geometry, u, v
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_http_headers'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'user_agent'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'referer'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'accept_language'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '25', '36', '47', '57', '73']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'user_agent'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'user_agent'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'default_user_agent'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'referer'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'referer'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'default_referer'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'accept_language'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'accept_language'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'default_accept_language'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '50', 'type': 'call', 'children': ['51', '56']}, {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'default_headers'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'dictionary', 'children': ['64', '67', '70']}; {'id': '64', 'type': 'pair', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'User-Agent'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'user_agent'}, {'id': '67', 'type': 'pair', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'referer'"}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'referer'}; {'id': '70', 'type': 'pair', 'children': ['71', '72']}, {'id': '71', 'type': 'string', 'children': [], 'value': "'Accept-Language'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'accept_language'}, {'id': '73', 'type': 'return_statement', 'children': ['74']}
def get_http_headers(user_agent=None, referer=None, accept_language=None): if user_agent is None: user_agent = settings.default_user_agent if referer is None: referer = settings.default_referer if accept_language is None: accept_language = settings.default_accept_language headers = requests.utils.default_headers() headers.update({'User-Agent': user_agent, 'referer': referer, 'Accept-Language': accept_language}) return headers
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_has_sorted_sa_indices'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's_indices'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'a_indices'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '60']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 's_indices'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '22']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '-'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '22', 'type': 'block', 'children': ['23', '36']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '33']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '>'}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 's_indices'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 's_indices'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '+'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '46']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '=='}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 's_indices'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 's_indices'}, {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'if_statement', 'children': ['48', '57']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '52'], 'value': '>='}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'a_indices'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'a_indices'}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '+'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'False', 'children': []}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'True', 'children': []}
def _has_sorted_sa_indices(s_indices, a_indices): L = len(s_indices) for i in range(L-1): if s_indices[i] > s_indices[i+1]: return False if s_indices[i] == s_indices[i+1]: if a_indices[i] >= a_indices[i+1]: return False return True
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_generate_a_indptr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'num_states'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's_indices'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '18', '47']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'subscript', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '26']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '-'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'num_states'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'block', 'children': ['27', '39']}, {'id': '27', 'type': 'while_statement', 'children': ['28', '34']}; {'id': '28', 'type': 'parenthesized_expression', 'children': ['29']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 's_indices'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'augmented_assignment', 'children': ['37', '38'], 'value': '+='}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '46']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '52']}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'num_states'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 's_indices'}
def _generate_a_indptr(num_states, s_indices, out): idx = 0 out[0] = 0 for s in range(num_states-1): while(s_indices[idx] == s): idx += 1 out[s+1] = idx out[num_states] = len(s_indices)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_topologically'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dag'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '19', '29', '86', '106']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dag'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dag'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted_nodes'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'independent_nodes'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'deque'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_independent_nodes'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dag'}, {'id': '29', 'type': 'while_statement', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'independent_nodes'}, {'id': '31', 'type': 'block', 'children': ['32', '40', '47', '53']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'independent_nodes'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'popleft'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted_nodes'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'downstream_nodes'}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dag'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '53', 'type': 'while_statement', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'downstream_nodes'}, {'id': '55', 'type': 'block', 'children': ['56', '65', '71']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'downstream_node'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'downstream_nodes'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'not'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'downstream_node'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'dag'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'continue_statement', 'children': []}, {'id': '71', 'type': 'if_statement', 'children': ['72', '78']}; {'id': '72', 'type': 'not_operator', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'has_dependencies'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'downstream_node'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dag'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'independent_nodes'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'downstream_node'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '100']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '!='}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted_nodes'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dag'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'raise_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'graph is not acyclic'"}; {'id': '106', 'type': 'return_statement', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sorted_nodes'}
def sort_topologically(dag): dag = copy.deepcopy(dag) sorted_nodes = [] independent_nodes = deque(get_independent_nodes(dag)) while independent_nodes: node = independent_nodes.popleft() sorted_nodes.append(node) downstream_nodes = dag[node] while downstream_nodes: downstream_node = downstream_nodes.pop(0) if downstream_node not in dag: continue if not has_dependencies(downstream_node, dag): independent_nodes.append(downstream_node) if len(sorted_nodes) != len(dag.keys()): raise ValueError('graph is not acyclic') return sorted_nodes
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_topological_dag_upstreams'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dag'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ops'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'op_runs'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'runs_by_ops'}; {'id': '8', 'type': 'block', 'children': ['9', '20']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted_ops'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dags'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_topologically'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dag'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dag'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'op_id'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted_ops'}, {'id': '23', 'type': 'block', 'children': ['24', '30', '36']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'op_run_id'}, {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'runs_by_ops'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'op_id'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'op_run'}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'op_runs'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'op_run_id'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'set_op_upstreams'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43']}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'op_run'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'op_run'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ops'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'op_id'}
def set_topological_dag_upstreams(dag, ops, op_runs, runs_by_ops): sorted_ops = dags.sort_topologically(dag=dag) for op_id in sorted_ops: op_run_id = runs_by_ops[op_id] op_run = op_runs[op_run_id] set_op_upstreams(op_run=op_run, op=ops[op_id])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_from_text'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '23']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'process_text'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'generate_from_frequencies'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '23', 'type': 'return_statement', 'children': ['24']}
def generate_from_text(self, text): words = self.process_text(text) self.generate_from_frequencies(words) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_pods_metrics'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'pods'}, {'id': '7', 'type': 'block', 'children': ['8', '15', '101', '111']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'tags_map'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pod'}, {'id': '17', 'type': 'subscript', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pods'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'items'"}; {'id': '20', 'type': 'block', 'children': ['21', '31', '45', '56', '76', '92']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pod_meta'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pod'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'metadata'"}; {'id': '30', 'type': 'dictionary', 'children': []}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pod_tags'}; {'id': '34', 'type': 'call', 'children': ['35', '40']}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'kubeutil'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_pod_creator_tags'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'pod_meta'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'legacy_rep_controller_tag'}; {'id': '44', 'type': 'True', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'kubeutil'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'match_services_for_pod'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pod_meta'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '62']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'for_statement', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'pod_tags'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '%'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'kube_service:%s'"}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'namespace'"}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'pod_meta'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pod_tags'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '%'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'kube_namespace:%s'"}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'pod_meta'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'namespace'"}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'augmented_assignment', 'children': ['94', '100'], 'value': '+='}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'tags_map'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'pod_tags'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'commmon_tags'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}, {'id': '109', 'type': 'string', 'children': [], 'value': "'tags'"}; {'id': '110', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '111', 'type': 'for_statement', 'children': ['112', '115', '120']}; {'id': '112', 'type': 'pattern_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'pod_tags'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'pod_count'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tags_map'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'block', 'children': ['121', '128', '135']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'pod_tags'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'commmon_tags'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'publish_gauge'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142', '145', '146']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '+'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'NAMESPACE'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'.pods.running'"}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'pod_count'}
def _update_pods_metrics(self, instance, pods): tags_map = defaultdict(int) for pod in pods['items']: pod_meta = pod.get('metadata', {}) pod_tags = self.kubeutil.get_pod_creator_tags(pod_meta, legacy_rep_controller_tag=True) services = self.kubeutil.match_services_for_pod(pod_meta) if isinstance(services, list): for service in services: pod_tags.append('kube_service:%s' % service) if 'namespace' in pod_meta: pod_tags.append('kube_namespace:%s' % pod_meta['namespace']) tags_map[frozenset(pod_tags)] += 1 commmon_tags = instance.get('tags', []) for pod_tags, pod_count in tags_map.iteritems(): tags = list(pod_tags) tags.extend(commmon_tags) self.publish_gauge(self, NAMESPACE + '.pods.running', pod_count, tags)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_agent_tags'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'since'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '6', 'type': 'block', 'children': ['7', '23', '42', '49', '62']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'agent_tags'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'generator_expression', 'children': ['13', '17']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'parse_version_info'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'git_tag_list'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "r'^\\d+\\.\\d+\\.\\d+$'"}, {'id': '23', 'type': 'if_statement', 'children': ['24', '25', '33']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parse_version_info'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'agent_tags'}; {'id': '40', 'type': 'unary_operator', 'children': ['41'], 'value': '-'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'since'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'parse_version_info'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'since'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'agent_tags'}; {'id': '52', 'type': 'list_comprehension', 'children': ['53', '54', '57']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'agent_tags'}, {'id': '57', 'type': 'if_clause', 'children': ['58']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60', '61'], 'value': '<='}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'list_comprehension', 'children': ['64', '68']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'agent_tags'}
def get_agent_tags(since, to): agent_tags = sorted(parse_version_info(t) for t in git_tag_list(r'^\d+\.\d+\.\d+$')) if to: to = parse_version_info(to) else: to = agent_tags[-1] since = parse_version_info(since) agent_tags = [t for t in agent_tags if since <= t <= to] return [str(t) for t in reversed(agent_tags)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key_or_list'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '26', '37']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__check_okay_to_chain'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'helpers'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_index_list'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key_or_list'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '__ordering'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'helpers'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_index_document'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '37', 'type': 'return_statement', 'children': ['38']}
def sort(self, key_or_list, direction=None): self.__check_okay_to_chain() keys = helpers._index_list(key_or_list, direction) self.__ordering = helpers._index_document(keys) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_one_and_replace'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'replacement'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'projection'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'upsert'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'return_document'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ReturnDocument'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'BEFORE'}, {'id': '21', 'type': 'dictionary_splat_pattern', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '23', 'type': 'block', 'children': ['24', '31', '37']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'common'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'validate_ok_for_replace'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'replacement'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'update'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'replacement'}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '__find_and_modify'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45', '46', '47', '48']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'projection'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'upsert'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'return_document'}; {'id': '48', 'type': 'dictionary_splat', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def find_one_and_replace(self, filter, replacement, projection=None, sort=None, upsert=False, return_document=ReturnDocument.BEFORE, **kwargs): common.validate_ok_for_replace(replacement) kwargs['update'] = replacement return self.__find_and_modify(filter, projection, sort, upsert, return_document, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_one_and_update'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'projection'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'upsert'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'return_document'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ReturnDocument'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'BEFORE'}, {'id': '21', 'type': 'dictionary_splat_pattern', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '23', 'type': 'block', 'children': ['24', '31', '37']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'common'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'validate_ok_for_update'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'update'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '__find_and_modify'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45', '46', '47', '48']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'projection'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'upsert'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'return_document'}; {'id': '48', 'type': 'dictionary_splat', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def find_one_and_update(self, filter, update, projection=None, sort=None, upsert=False, return_document=ReturnDocument.BEFORE, **kwargs): common.validate_ok_for_update(update) kwargs['update'] = update return self.__find_and_modify(filter, projection, sort, upsert, return_document, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'feature_correlation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'pearson'"}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'feature_index'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'feature_names'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'dictionary_splat_pattern', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'block', 'children': ['27', '41', '51', '57']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'viz'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'FeatureCorrelation'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35', '36', '37', '38', '39']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'feature_index'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'feature_names'}, {'id': '39', 'type': 'dictionary_splat', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'viz'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '49', 'type': 'dictionary_splat', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'viz'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'finalize'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'viz'}
def feature_correlation(X, y, ax=None, method='pearson', labels=None, sort=False, feature_index=None, feature_names=None, **kwargs): viz = FeatureCorrelation(ax, method, labels, sort, feature_index, feature_names, **kwargs) viz.fit(X, y, **kwargs) viz.finalize() return viz.ax
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dispersion'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'corpus'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'colors'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'colormap'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'annotate_docs'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ignore_case'}; {'id': '26', 'type': 'False', 'children': []}, {'id': '27', 'type': 'dictionary_splat_pattern', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '29', 'type': 'block', 'children': ['30', '57', '67']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'visualizer'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'DispersionPlot'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37', '40', '43', '46', '49', '52', '55']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'colors'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'colors'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'colormap'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'colormap'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ignore_case'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ignore_case'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'annotate_docs'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'annotate_docs'}, {'id': '55', 'type': 'dictionary_splat', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'visualizer'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'corpus'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '65', 'type': 'dictionary_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'visualizer'}
def dispersion(words, corpus, y=None, ax=None, colors=None, colormap=None, labels=None, annotate_docs=False, ignore_case=False, **kwargs): visualizer = DispersionPlot( words, ax=ax, colors=colors, colormap=colormap, ignore_case=ignore_case, labels=labels, annotate_docs=annotate_docs, **kwargs ) visualizer.fit(corpus, y, **kwargs) return visualizer.ax
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_product_set'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'array_a'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'array_b'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'subscript', 'children': ['9', '37']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'concatenate'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '34']}, {'id': '19', 'type': 'list_comprehension', 'children': ['20', '25']}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '24'], 'value': '*'}, {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'array_a'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'array_b'}, {'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'xrange'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'array_a'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '37', 'type': 'slice', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'colon', 'children': []}, {'id': '39', 'type': 'colon', 'children': []}; {'id': '40', 'type': 'unary_operator', 'children': ['41'], 'value': '-'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}
def sorted_product_set(array_a, array_b): return np.sort( np.concatenate( [array_a[i] * array_b for i in xrange(len(array_a))], axis=0) )[::-1]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_inputs'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '5', 'type': 'block', 'children': ['6', '59', '81', '99', '103', '107', '133']}; {'id': '6', 'type': 'with_statement', 'children': ['7', '20']}, {'id': '7', 'type': 'with_clause', 'children': ['8']}; {'id': '8', 'type': 'with_item', 'children': ['9']}, {'id': '9', 'type': 'as_pattern', 'children': ['10', '18']}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'gfile'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Open'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '18', 'type': 'as_pattern_target', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '20', 'type': 'block', 'children': ['21', '34', '46']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '24', 'type': 'call', 'children': ['25', '32']}, {'id': '25', 'type': 'attribute', 'children': ['26', '31']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'inputs'}, {'id': '37', 'type': 'list_comprehension', 'children': ['38', '43']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52']}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'inputs'}; {'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'inputs'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'input_lens'}; {'id': '62', 'type': 'list_comprehension', 'children': ['63', '73']}, {'id': '63', 'type': 'tuple', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '72', 'type': 'argument_list', 'children': []}, {'id': '73', 'type': 'for_in_clause', 'children': ['74', '77']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'inputs'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sorted_input_lens'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '96']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'input_lens'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '90', 'type': 'lambda', 'children': ['91', '93']}, {'id': '91', 'type': 'lambda_parameters', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '98', 'type': 'True', 'children': []}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'}; {'id': '102', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '106', 'type': 'dictionary', 'children': []}, {'id': '107', 'type': 'for_statement', 'children': ['108', '113', '117']}; {'id': '108', 'type': 'pattern_list', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '110', 'type': 'tuple_pattern', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sorted_input_lens'}, {'id': '117', 'type': 'block', 'children': ['118', '127']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'inputs'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '133', 'type': 'return_statement', 'children': ['134']}; {'id': '134', 'type': 'expression_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'}
def _get_sorted_inputs(filename): with tf.gfile.Open(filename) as f: records = f.read().split("\n") inputs = [record.strip() for record in records] if not inputs[-1]: inputs.pop() input_lens = [(i, len(line.split())) for i, line in enumerate(inputs)] sorted_input_lens = sorted(input_lens, key=lambda x: x[1], reverse=True) sorted_inputs = [] sorted_keys = {} for i, (index, _) in enumerate(sorted_input_lens): sorted_inputs.append(inputs[index]) sorted_keys[index] = i return sorted_inputs, sorted_keys
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'games_by_time'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_game'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'end_game'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '44', '88']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'move_count'}, {'id': '11', 'type': 'string', 'children': [], 'value': "b'move_count'"}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'bt_table'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'read_rows'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '28', '34']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ROWCOUNT_PREFIX'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'start_game'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ROWCOUNT_PREFIX'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'end_game'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'filter_'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bigtable_row_filters'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ColumnRangeFilter'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'METADATA'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'move_count'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'move_count'}; {'id': '44', 'type': 'function_definition', 'children': ['45', '46', '48']}, {'id': '45', 'type': 'function_name', 'children': [], 'value': 'parse'}; {'id': '46', 'type': 'parameters', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '48', 'type': 'block', 'children': ['49', '59', '74']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'rk'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'row_key'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'game'}; {'id': '62', 'type': 'subscript', 'children': ['63', '73']}, {'id': '63', 'type': 'call', 'children': ['64', '72']}; {'id': '64', 'type': 'attribute', 'children': ['65', '71']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_game_from_counter'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'rk'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '72', 'type': 'argument_list', 'children': []}, {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'tuple', 'children': ['76', '87']}; {'id': '76', 'type': 'attribute', 'children': ['77', '86']}, {'id': '77', 'type': 'subscript', 'children': ['78', '85']}; {'id': '78', 'type': 'subscript', 'children': ['79', '84']}, {'id': '79', 'type': 'subscript', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cells'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'METADATA'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'move_count'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'game'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '100']}; {'id': '92', 'type': 'list_comprehension', 'children': ['93', '97']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}
def games_by_time(self, start_game, end_game): move_count = b'move_count' rows = self.bt_table.read_rows( ROWCOUNT_PREFIX.format(start_game), ROWCOUNT_PREFIX.format(end_game), filter_=bigtable_row_filters.ColumnRangeFilter( METADATA, move_count, move_count)) def parse(r): rk = str(r.row_key, 'utf-8') game = _game_from_counter.match(rk).groups()[0] return (r.cells[METADATA][move_count][0].timestamp, game) return sorted([parse(r) for r in rows], key=operator.itemgetter(0))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bleakest_moves'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_game'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'end_game'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '44', '98']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'bleak'}, {'id': '11', 'type': 'string', 'children': [], 'value': "b'bleakest_q'"}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'bt_table'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'read_rows'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '28', '34']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ROW_PREFIX'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'start_game'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ROW_PREFIX'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'end_game'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'filter_'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bigtable_row_filters'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ColumnRangeFilter'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'METADATA'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'bleak'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'bleak'}; {'id': '44', 'type': 'function_definition', 'children': ['45', '46', '48']}, {'id': '45', 'type': 'function_name', 'children': [], 'value': 'parse'}; {'id': '46', 'type': 'parameters', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '48', 'type': 'block', 'children': ['49', '59', '74', '84']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'rk'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'row_key'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}, {'id': '61', 'type': 'pattern_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '64', 'type': 'call', 'children': ['65', '73']}, {'id': '65', 'type': 'attribute', 'children': ['66', '72']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_game_row_key'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'rk'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cell_value'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'METADATA'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'bleak'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'expression_list', 'children': ['86', '90', '94']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '98', 'type': 'return_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '110']}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '107']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '107', 'type': 'for_in_clause', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'integer', 'children': [], 'value': '2'}
def bleakest_moves(self, start_game, end_game): bleak = b'bleakest_q' rows = self.bt_table.read_rows( ROW_PREFIX.format(start_game), ROW_PREFIX.format(end_game), filter_=bigtable_row_filters.ColumnRangeFilter( METADATA, bleak, bleak)) def parse(r): rk = str(r.row_key, 'utf-8') g, m = _game_row_key.match(rk).groups() q = r.cell_value(METADATA, bleak) return int(g), int(m), float(q) return sorted([parse(r) for r in rows], key=operator.itemgetter(2))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_generate_subtokens'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'token_counts'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'alphabet'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_count'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'num_iterations'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'reserved_tokens'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '23', '32', '36', '97']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'reserved_tokens'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'reserved_tokens'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'RESERVED_TOKENS'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'subtoken_list'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '+'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reserved_tokens'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'alphabet'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'max_subtoken_length'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '42']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'num_iterations'}; {'id': '42', 'type': 'block', 'children': ['43', '54', '61', '71', '83']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '%'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"\\tGenerating subtokens: iteration %d"'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'subtoken_dict'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_list_to_index_dict'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'subtoken_list'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'subtoken_counts'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_count_and_gen_subtokens'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69', '70']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'token_counts'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'alphabet'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'subtoken_dict'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'max_subtoken_length'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}, {'id': '73', 'type': 'pattern_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'subtoken_list'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'max_subtoken_length'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_gen_new_subtoken_list'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81', '82']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'subtoken_counts'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'min_count'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'alphabet'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'reserved_tokens'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '90']}, {'id': '85', 'type': 'attribute', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '%'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"\\tVocab size: %d"'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'subtoken_list'}, {'id': '97', 'type': 'return_statement', 'children': ['98']}
def _generate_subtokens( token_counts, alphabet, min_count, num_iterations=4, reserved_tokens=None): if reserved_tokens is None: reserved_tokens = RESERVED_TOKENS subtoken_list = reserved_tokens + list(alphabet) max_subtoken_length = 1 for i in xrange(num_iterations): tf.logging.info("\tGenerating subtokens: iteration %d" % i) subtoken_dict = _list_to_index_dict(subtoken_list) subtoken_counts = _count_and_gen_subtokens( token_counts, alphabet, subtoken_dict, max_subtoken_length) subtoken_list, max_subtoken_length = _gen_new_subtoken_list( subtoken_counts, min_count, alphabet, reserved_tokens) tf.logging.info("\tVocab size: %d" % len(subtoken_list)) return subtoken_list
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sparse_svd'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sparse_matrix'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'num_values'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_iter'}, {'id': '7', 'type': 'block', 'children': ['8', '20', '36', '55', '76']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': '<='}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'num_values'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'raise_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '%'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"num_values should be > 0 but instead is %d."'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'num_values'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '28']}, {'id': '21', 'type': 'boolean_operator', 'children': ['22', '25'], 'value': 'and'}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'max_iter'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '<'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'max_iter'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"max_iter should be >= 0 but instead is %d."'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'max_iter'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40', '47']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'max_iter'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'max_iter'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'FLAGS'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'max_iter_sparse_svd'}, {'id': '47', 'type': 'elif_clause', 'children': ['48', '50']}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'max_iter'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'max_iter'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '61']}, {'id': '57', 'type': 'pattern_list', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'svds'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '70', '73']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sparse_matrix'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'num_values'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'maxiter'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'max_iter'}, {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'return_singular_vectors'}, {'id': '75', 'type': 'True', 'children': []}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'tuple', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 's'}
def sparse_svd(sparse_matrix, num_values, max_iter): if num_values <= 0: raise ValueError("num_values should be > 0 but instead is %d." % num_values) if max_iter is not None and max_iter < 0: raise ValueError("max_iter should be >= 0 but instead is %d." % max_iter) if max_iter is None: max_iter = FLAGS.max_iter_sparse_svd elif not max_iter: max_iter = None u, s, v = linalg.svds( sparse_matrix, k=num_values, maxiter=max_iter, return_singular_vectors=True) return (u, s, v)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_collate_fn'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'batch_first'}; {'id': '6', 'type': 'False', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'parallel'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '109', '181', '241']}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']}, {'id': '15', 'type': 'function_name', 'children': [], 'value': 'collate_seq'}; {'id': '16', 'type': 'parameters', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '18', 'type': 'block', 'children': ['19', '30', '37', '46', '63', '94', '105']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'lengths'}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '27']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'batch_length'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'lengths'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '40', 'type': 'tuple', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'batch_length'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'seq_tensor'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'torch'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'full'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PAD'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'torch'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'int64'}, {'id': '63', 'type': 'for_statement', 'children': ['64', '67', '71']}; {'id': '64', 'type': 'pattern_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'seq'}, {'id': '71', 'type': 'block', 'children': ['72', '78']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'end_seq'}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'lengths'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '88']}; {'id': '80', 'type': 'attribute', 'children': ['81', '87']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83', '86']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'seq_tensor'}, {'id': '83', 'type': 'slice', 'children': ['84', '85']}; {'id': '84', 'type': 'colon', 'children': []}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'end_seq'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'copy_'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '91', 'type': 'slice', 'children': ['92', '93']}; {'id': '92', 'type': 'colon', 'children': []}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'end_seq'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'batch_first'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'seq_tensor'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'seq_tensor'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'tuple', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'seq_tensor'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'lengths'}, {'id': '109', 'type': 'function_definition', 'children': ['110', '111', '113']}; {'id': '110', 'type': 'function_name', 'children': [], 'value': 'parallel_collate'}, {'id': '111', 'type': 'parameters', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'seqs'}, {'id': '113', 'type': 'block', 'children': ['114', '124', '167']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'pattern_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'tgt_seqs'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'list_splat', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'seqs'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '126', 'type': 'block', 'children': ['127', '157']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'pattern_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'list_splat', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '143', '154']}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}, {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '145', 'type': 'lambda', 'children': ['146', '148']}; {'id': '146', 'type': 'lambda_parameters', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '156', 'type': 'True', 'children': []}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'tgt_seqs'}; {'id': '160', 'type': 'list_comprehension', 'children': ['161', '164']}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'tgt_seqs'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '164', 'type': 'for_in_clause', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '167', 'type': 'return_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'list_comprehension', 'children': ['172', '176']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'collate_seq'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '176', 'type': 'for_in_clause', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '178', 'type': 'list', 'children': ['179', '180'], 'value': '[src_seqs, tgt_seqs]'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'tgt_seqs'}, {'id': '181', 'type': 'function_definition', 'children': ['182', '183', '185']}; {'id': '182', 'type': 'function_name', 'children': [], 'value': 'single_collate'}, {'id': '183', 'type': 'parameters', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}, {'id': '185', 'type': 'block', 'children': ['186', '231']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '188', '219']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}, {'id': '191', 'type': 'pattern_list', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'list_splat', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '205', '216']}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '207', 'type': 'lambda', 'children': ['208', '210']}; {'id': '208', 'type': 'lambda_parameters', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '218', 'type': 'True', 'children': []}, {'id': '219', 'type': 'else_clause', 'children': ['220']}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}, {'id': '231', 'type': 'return_statement', 'children': ['232']}; {'id': '232', 'type': 'expression_list', 'children': ['233', '237']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'collate_seq'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'src_seqs'}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '241', 'type': 'if_statement', 'children': ['242', '243', '246']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'parallel'}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'return_statement', 'children': ['245']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'parallel_collate'}; {'id': '246', 'type': 'else_clause', 'children': ['247']}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'return_statement', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'single_collate'}
def build_collate_fn(batch_first=False, parallel=True, sort=False): def collate_seq(seq): lengths = [len(s) for s in seq] batch_length = max(lengths) shape = (batch_length, len(seq)) seq_tensor = torch.full(shape, config.PAD, dtype=torch.int64) for i, s in enumerate(seq): end_seq = lengths[i] seq_tensor[:end_seq, i].copy_(s[:end_seq]) if batch_first: seq_tensor = seq_tensor.t() return (seq_tensor, lengths) def parallel_collate(seqs): src_seqs, tgt_seqs = zip(*seqs) if sort: indices, src_seqs = zip(*sorted(enumerate(src_seqs), key=lambda item: len(item[1]), reverse=True)) tgt_seqs = [tgt_seqs[idx] for idx in indices] return tuple([collate_seq(s) for s in [src_seqs, tgt_seqs]]) def single_collate(src_seqs): if sort: indices, src_seqs = zip(*sorted(enumerate(src_seqs), key=lambda item: len(item[1]), reverse=True)) else: indices = range(len(src_seqs)) return collate_seq(src_seqs), tuple(indices) if parallel: return parallel_collate else: return single_collate
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_golden_chunk_records'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '21']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '8', 'type': 'call', 'children': ['9', '14']}, {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '20']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fsdb'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'golden_chunk_dir'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'string', 'children': [], 'value': "'*.zz'"}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'subscript', 'children': ['23', '37']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '34']}; {'id': '26', 'type': 'call', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'gfile'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Glob'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '36', 'type': 'True', 'children': []}, {'id': '37', 'type': 'slice', 'children': ['38', '39']}; {'id': '38', 'type': 'colon', 'children': []}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'FLAGS'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'window_size'}
def get_golden_chunk_records(): pattern = os.path.join(fsdb.golden_chunk_dir(), '*.zz') return sorted(tf.gfile.Glob(pattern), reverse=True)[:FLAGS.window_size]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_results'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'results_dicts'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '28', '32', '45']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'results dicts:'"}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'results_dicts'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted_dict'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'results_dicts'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'lambda', 'children': ['23', '25']}, {'id': '23', 'type': 'lambda_parameters', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'start_time'"}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorted_dict'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'dt'"}, {'id': '45', 'type': 'return_statement', 'children': ['46']}
def _sorted_results(self, results_dicts): print('results dicts:', results_dicts) sorted_dict = sorted(results_dicts, key=lambda k: k['start_time']) results = [] for entry in sorted_dict: results.append(entry['dt']) return results
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_models'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '24', '39', '62']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'all_models'}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'gfile'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Glob'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '23']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'models_dir'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'string', 'children': [], 'value': "'*.meta'"}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'model_filenames'}, {'id': '27', 'type': 'list_comprehension', 'children': ['28', '36']}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'all_models'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'model_numbers_names'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'list_comprehension', 'children': ['46', '59']}; {'id': '46', 'type': 'tuple', 'children': ['47', '53']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'shipname'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'detect_model_num'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'shipname'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'detect_model_name'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'model_filenames'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'model_numbers_names'}
def get_models(): all_models = gfile.Glob(os.path.join(models_dir(), '*.meta')) model_filenames = [os.path.basename(m) for m in all_models] model_numbers_names = sorted([ (shipname.detect_model_num(m), shipname.detect_model_name(m)) for m in model_filenames]) return model_numbers_names
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_by'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Callable'}, {'id': '9', 'type': 'type_parameter', 'children': ['10', '15']}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'list', 'children': ['12'], 'value': '[raw_types.Qid]'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'raw_types'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Qid'}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Any'}, {'id': '17', 'type': 'type', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'QubitOrder'"}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'QubitOrder'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'lambda', 'children': ['25', '27']}, {'id': '25', 'type': 'lambda_parameters', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'qubits'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}
def sorted_by(key: Callable[[raw_types.Qid], Any]) -> 'QubitOrder': return QubitOrder(lambda qubits: tuple(sorted(qubits, key=key)))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32', '36']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'diagonalize_real_symmetric_and_sorted_diagonal_matrices'}, {'id': '3', 'type': 'parameters', 'children': ['4', '10', '16', '17', '22', '27']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'symmetric_matrix'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '10', 'type': 'typed_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}; {'id': '12', 'type': 'type', 'children': ['13']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '16', 'type': 'keyword_separator', 'children': []}, {'id': '17', 'type': 'typed_default_parameter', 'children': ['18', '19', '21']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'rtol'}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '21', 'type': 'float', 'children': [], 'value': '1e-5'}; {'id': '22', 'type': 'typed_default_parameter', 'children': ['23', '24', '26']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '24', 'type': 'type', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '26', 'type': 'float', 'children': [], 'value': '1e-8'}, {'id': '27', 'type': 'typed_default_parameter', 'children': ['28', '29', '31']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'check_preconditions'}, {'id': '29', 'type': 'type', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'type', 'children': ['33']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '36', 'type': 'block', 'children': ['37', '149', '172', '184', '200', '241']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'check_preconditions'}, {'id': '39', 'type': 'block', 'children': ['40', '73', '128']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '67']}, {'id': '41', 'type': 'parenthesized_expression', 'children': ['42']}; {'id': '42', 'type': 'boolean_operator', 'children': ['43', '54'], 'value': 'or'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'imag'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'symmetric_matrix'}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'predicates'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'is_hermitian'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '64']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'symmetric_matrix'}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rtol'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'rtol'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'atol'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'raise_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'symmetric_matrix must be real symmetric.'"}, {'id': '73', 'type': 'if_statement', 'children': ['74', '122']}; {'id': '74', 'type': 'parenthesized_expression', 'children': ['75']}, {'id': '75', 'type': 'boolean_operator', 'children': ['76', '98'], 'value': 'or'}; {'id': '76', 'type': 'boolean_operator', 'children': ['77', '87'], 'value': 'or'}, {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'predicates'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'is_diagonal'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'atol'}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'imag'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '114'], 'value': '<'}; {'id': '104', 'type': 'subscript', 'children': ['105', '106', '110']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}; {'id': '106', 'type': 'slice', 'children': ['107', '108']}, {'id': '107', 'type': 'colon', 'children': []}; {'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'slice', 'children': ['111', '112']}, {'id': '111', 'type': 'colon', 'children': []}; {'id': '112', 'type': 'unary_operator', 'children': ['113'], 'value': '-'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116', '119']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}; {'id': '116', 'type': 'slice', 'children': ['117', '118']}, {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '118', 'type': 'colon', 'children': []}, {'id': '119', 'type': 'slice', 'children': ['120', '121']}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '121', 'type': 'colon', 'children': []}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'raise_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'diagonal_matrix must be real diagonal descending.'"}; {'id': '128', 'type': 'if_statement', 'children': ['129', '143']}, {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'predicates'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'commutes'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137', '140']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'symmetric_matrix'}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'rtol'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'rtol'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'atol'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'raise_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'Given matrices must commute.'"}, {'id': '149', 'type': 'function_definition', 'children': ['150', '151', '154']}; {'id': '150', 'type': 'function_name', 'children': [], 'value': 'similar_singular'}, {'id': '151', 'type': 'parameters', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'return_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'allclose'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '165', '169']}, {'id': '161', 'type': 'subscript', 'children': ['162', '163', '164']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '165', 'type': 'subscript', 'children': ['166', '167', '168']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'rtol'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'rtol'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ranges'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': '_contiguous_groups'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '183']}; {'id': '178', 'type': 'subscript', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'diagonal_matrix'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'similar_singular'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'symmetric_matrix'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'float64'}; {'id': '200', 'type': 'for_statement', 'children': ['201', '204', '205']}, {'id': '201', 'type': 'pattern_list', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ranges'}, {'id': '205', 'type': 'block', 'children': ['206', '219']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'block'}, {'id': '209', 'type': 'subscript', 'children': ['210', '211', '215']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'symmetric_matrix'}, {'id': '211', 'type': 'slice', 'children': ['212', '213', '214']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '213', 'type': 'colon', 'children': []}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '215', 'type': 'slice', 'children': ['216', '217', '218']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '217', 'type': 'colon', 'children': []}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '231']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223', '227']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '223', 'type': 'slice', 'children': ['224', '225', '226']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '225', 'type': 'colon', 'children': []}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '227', 'type': 'slice', 'children': ['228', '229', '230']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '229', 'type': 'colon', 'children': []}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'diagonalize_real_symmetric_matrix'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '235', '238']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'block'}, {'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'rtol'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'rtol'}; {'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'atol'}, {'id': '241', 'type': 'return_statement', 'children': ['242']}
def diagonalize_real_symmetric_and_sorted_diagonal_matrices( symmetric_matrix: np.ndarray, diagonal_matrix: np.ndarray, *, rtol: float = 1e-5, atol: float = 1e-8, check_preconditions: bool = True) -> np.ndarray: if check_preconditions: if (np.any(np.imag(symmetric_matrix)) or not predicates.is_hermitian(symmetric_matrix, rtol=rtol, atol=atol)): raise ValueError('symmetric_matrix must be real symmetric.') if (not predicates.is_diagonal(diagonal_matrix, atol=atol) or np.any(np.imag(diagonal_matrix)) or np.any(diagonal_matrix[:-1, :-1] < diagonal_matrix[1:, 1:])): raise ValueError( 'diagonal_matrix must be real diagonal descending.') if not predicates.commutes(diagonal_matrix, symmetric_matrix, rtol=rtol, atol=atol): raise ValueError('Given matrices must commute.') def similar_singular(i, j): return np.allclose(diagonal_matrix[i, i], diagonal_matrix[j, j], rtol=rtol) ranges = _contiguous_groups(diagonal_matrix.shape[0], similar_singular) p = np.zeros(symmetric_matrix.shape, dtype=np.float64) for start, end in ranges: block = symmetric_matrix[start:end, start:end] p[start:end, start:end] = diagonalize_real_symmetric_matrix( block, rtol=rtol, atol=atol) return p
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34', '48']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'findall_operations_between'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '17', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'start_frontier'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'generic_type', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '10', 'type': 'type_parameter', 'children': ['11', '15']}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ops'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Qid'}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '17', 'type': 'typed_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'end_frontier'}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'generic_type', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '22', 'type': 'type_parameter', 'children': ['23', '27']}, {'id': '23', 'type': 'type', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ops'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Qid'}, {'id': '27', 'type': 'type', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '29', 'type': 'typed_default_parameter', 'children': ['30', '31', '33']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'omit_crossing_operations'}, {'id': '31', 'type': 'type', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'type', 'children': ['35']}, {'id': '35', 'type': 'generic_type', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '37', 'type': 'type_parameter', 'children': ['38']}; {'id': '38', 'type': 'type', 'children': ['39']}, {'id': '39', 'type': 'generic_type', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'Tuple'}, {'id': '41', 'type': 'type_parameter', 'children': ['42', '44']}; {'id': '42', 'type': 'type', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '44', 'type': 'type', 'children': ['45']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ops'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'Operation'}; {'id': '48', 'type': 'block', 'children': ['49', '62', '82', '151']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '52', 'type': 'call', 'children': ['53', '58']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'BucketPriorityQueue'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ops'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Operation'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'drop_duplicate_entries'}, {'id': '61', 'type': 'True', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'involved_qubits'}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '74'], 'value': '|'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'start_frontier'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'end_frontier'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'for_statement', 'children': ['83', '84', '88']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'involved_qubits'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '111']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '101']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'start_frontier'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'end_frontier'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'block', 'children': ['112', '122', '128', '143']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'operation_at'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '126']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'is'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '125', 'type': 'None', 'children': []}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'continue_statement', 'children': []}; {'id': '128', 'type': 'if_statement', 'children': ['129', '141']}, {'id': '129', 'type': 'parenthesized_expression', 'children': ['130']}; {'id': '130', 'type': 'boolean_operator', 'children': ['131', '132'], 'value': 'and'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'omit_crossing_operations'}; {'id': '132', 'type': 'not_operator', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'involved_qubits'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'issuperset'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'qubits'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'continue_statement', 'children': []}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'enqueue'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'result'}
def findall_operations_between(self, start_frontier: Dict[ops.Qid, int], end_frontier: Dict[ops.Qid, int], omit_crossing_operations: bool = False ) -> List[Tuple[int, ops.Operation]]: result = BucketPriorityQueue[ops.Operation]( drop_duplicate_entries=True) involved_qubits = set(start_frontier.keys()) | set(end_frontier.keys()) for q in sorted(involved_qubits): for i in range(start_frontier.get(q, 0), end_frontier.get(q, len(self))): op = self.operation_at(q, i) if op is None: continue if (omit_crossing_operations and not involved_qubits.issuperset(op.qubits)): continue result.enqueue(i, op) return list(result)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_GetUnsortedNotifications'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'queue_shard'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'notifications_by_session_id'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '19', '33', '121']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'notifications_by_session_id'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'notifications_by_session_id'}; {'id': '18', 'type': 'dictionary', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '26'], 'value': 'or'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'frozen_timestamp'}; {'id': '26', 'type': 'call', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'rdfvalue'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'RDFDatetime'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Now'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '44']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'data_store'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'GetNotifications'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'queue_shard'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '44', 'type': 'block', 'children': ['45', '56']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'notifications_by_session_id'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '58', '111']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'if_statement', 'children': ['60', '67', '76']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': '>'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'first_queued'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'first_queued'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '75']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'notifications_by_session_id'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'session_id'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '76', 'type': 'elif_clause', 'children': ['77', '93']}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '85'], 'value': 'and'}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '=='}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'first_queued'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'first_queued'}, {'id': '85', 'type': 'parenthesized_expression', 'children': ['86']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '>'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'last_status'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'last_status'}, {'id': '93', 'type': 'block', 'children': ['94', '103']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"Notifications with equal first_queued fields detected: %s %s"'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'existing'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '110']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'notifications_by_session_id'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '120']}, {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'notifications_by_session_id'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '121', 'type': 'return_statement', 'children': ['122']}
def _GetUnsortedNotifications(self, queue_shard, notifications_by_session_id=None): if notifications_by_session_id is None: notifications_by_session_id = {} end_time = self.frozen_timestamp or rdfvalue.RDFDatetime.Now() for notification in self.data_store.GetNotifications(queue_shard, end_time): existing = notifications_by_session_id.get(notification.session_id) if existing: if notification.first_queued > existing.first_queued: notifications_by_session_id[notification.session_id] = notification elif notification.first_queued == existing.first_queued and ( notification.last_status > existing.last_status): logging.warning( "Notifications with equal first_queued fields detected: %s %s", notification, existing) notifications_by_session_id[notification.session_id] = notification else: notifications_by_session_id[notification.session_id] = notification return notifications_by_session_id
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'Dump'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'encoder'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '36', '56']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21', '24', '27', '30', '33']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ensure_ascii'}, {'id': '29', 'type': 'False', 'children': []}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'encoder'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'separators'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_SEPARATORS'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '46']}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'and'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'compatibility'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'PY2'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': '"utf-8"'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'text'}
def Dump(obj, sort_keys = False, encoder = None): text = json.dumps( obj, indent=2, sort_keys=sort_keys, ensure_ascii=False, cls=encoder, separators=_SEPARATORS) if compatibility.PY2 and isinstance(text, bytes): text = text.decode("utf-8") return text
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'NamedPlaceholders'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '5', 'type': 'block', 'children': ['6', '26']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'placeholders'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'string', 'children': [], 'value': '", "'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '13', 'type': 'generator_expression', 'children': ['14', '20']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"%({})s"'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"({})"'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}
def NamedPlaceholders(iterable): placeholders = ", ".join("%({})s".format(key) for key in sorted(iterable)) return "({})".format(placeholders)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'Columns'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"({})"'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': '", "'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '23', 'type': 'generator_expression', 'children': ['24', '30']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"`{}`"'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'col'}
def Columns(iterable): columns = sorted(iterable) return "({})".format(", ".join("`{}`".format(col) for col in columns))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetArtifactsForCollection'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'os_name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'artifact_list'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '23']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'artifact_arranger'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ArtifactArranger'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'os_name'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'artifact_list'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'artifact_names'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'artifact_arranger'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'GetArtifactsInProperOrder'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'return_statement', 'children': ['24']}
def GetArtifactsForCollection(os_name, artifact_list): artifact_arranger = ArtifactArranger(os_name, artifact_list) artifact_names = artifact_arranger.GetArtifactsInProperOrder() return artifact_names
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_FilterOutPathInfoDuplicates'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path_infos'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '39', '66', '94']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pi_dict'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'path_infos'}, {'id': '13', 'type': 'block', 'children': ['14', '26']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path_key'}, {'id': '17', 'type': 'tuple', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'path_type'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'GetPathID'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '37']}; {'id': '28', 'type': 'attribute', 'children': ['29', '36']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pi_dict'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'path_key'}, {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '39', 'type': 'function_definition', 'children': ['40', '41', '43']}; {'id': '40', 'type': 'function_name', 'children': [], 'value': '_SortKey'}, {'id': '41', 'type': 'parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'tuple', 'children': ['46', '51', '56', '61']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'stat_entry'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'st_ctime'}, {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'stat_entry'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'st_mtime'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'stat_entry'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'st_atime'}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'stat_entry'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'st_ino'}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '73']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pi_values'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'pi_dict'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '72', 'type': 'argument_list', 'children': []}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '81']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': '>'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'pi_values'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pi_values'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '91']}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_SortKey'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '93', 'type': 'True', 'children': []}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'list_comprehension', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'pi_dict'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '105', 'type': 'argument_list', 'children': []}
def _FilterOutPathInfoDuplicates(path_infos): pi_dict = {} for pi in path_infos: path_key = (pi.path_type, pi.GetPathID()) pi_dict.setdefault(path_key, []).append(pi) def _SortKey(pi): return ( pi.stat_entry.st_ctime, pi.stat_entry.st_mtime, pi.stat_entry.st_atime, pi.stat_entry.st_ino, ) for pi_values in pi_dict.values(): if len(pi_values) > 1: pi_values.sort(key=_SortKey, reverse=True) return [v[0] for v in pi_dict.values()]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'DrainTaskSchedulerQueueForClient'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '28', '37', '45', '230', '245', '267']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_count'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'max_queue_size'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '<='}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'rdf_client'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ClientURN'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'if_statement', 'children': ['46', '51', '95']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'data_store'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'RelationalDBEnabled'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'block', 'children': ['52', '82']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'action_requests'}, {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'data_store'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'REL_DB'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'LeaseClientActionRequests'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '67', '79']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'Basename'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'lease_time'}, {'id': '69', 'type': 'call', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'rdfvalue'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'Duration'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'FromSeconds'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'message_expiry_time'}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '85', 'type': 'list_comprehension', 'children': ['86', '92']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'rdf_flow_objects'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'GRRMessageFromClientActionRequest'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'action_requests'}, {'id': '95', 'type': 'else_clause', 'children': ['96']}; {'id': '96', 'type': 'block', 'children': ['97', '129', '139', '143', '147', '176']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_tasks'}; {'id': '100', 'type': 'call', 'children': ['101', '113']}, {'id': '101', 'type': 'attribute', 'children': ['102', '112']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'queue_manager'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'QueueManager'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'QueryAndOwn'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '121', '124']}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'Queue'}; {'id': '120', 'type': 'argument_list', 'children': []}, {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'lease_seconds'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'message_expiry_time'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'initial_ttl'}; {'id': '132', 'type': 'attribute', 'children': ['133', '138']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'rdf_flows'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'GrrMessage'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'task_ttl'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'check_before_sending'}; {'id': '142', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '146', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '147', 'type': 'for_statement', 'children': ['148', '149', '150']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'new_tasks'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'if_statement', 'children': ['152', '159', '167']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '156'], 'value': '<'}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'task_ttl'}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '-'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'initial_ttl'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'check_before_sending'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '167', 'type': 'else_clause', 'children': ['168']}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '176', 'type': 'if_statement', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'check_before_sending'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'with_statement', 'children': ['180', '195']}; {'id': '180', 'type': 'with_clause', 'children': ['181']}, {'id': '181', 'type': 'with_item', 'children': ['182']}; {'id': '182', 'type': 'as_pattern', 'children': ['183', '193']}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'queue_manager'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'QueueManager'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '193', 'type': 'as_pattern_target', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'manager'}, {'id': '195', 'type': 'block', 'children': ['196', '205']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'status_found'}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'MultiCheckStatus'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'check_before_sending'}, {'id': '205', 'type': 'for_statement', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'check_before_sending'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'if_statement', 'children': ['210', '213', '221']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'not'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'status_found'}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '221', 'type': 'else_clause', 'children': ['222']}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'manager'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'DeQueueClientRequest'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '239']}; {'id': '232', 'type': 'attribute', 'children': ['233', '238']}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'stats_collector_instance'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'Get'}, {'id': '237', 'type': 'argument_list', 'children': []}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'IncrementCounter'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241']}; {'id': '240', 'type': 'string', 'children': [], 'value': '"grr_messages_sent"'}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '245', 'type': 'if_statement', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '253', 'type': 'argument_list', 'children': ['254', '255', '259', '260']}; {'id': '254', 'type': 'string', 'children': [], 'value': '"Drained %d messages for %s in %s seconds."'}, {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '260', 'type': 'binary_operator', 'children': ['261', '266'], 'value': '-'}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '265', 'type': 'argument_list', 'children': []}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '267', 'type': 'return_statement', 'children': ['268']}
def DrainTaskSchedulerQueueForClient(self, client, max_count=None): if max_count is None: max_count = self.max_queue_size if max_count <= 0: return [] client = rdf_client.ClientURN(client) start_time = time.time() if data_store.RelationalDBEnabled(): action_requests = data_store.REL_DB.LeaseClientActionRequests( client.Basename(), lease_time=rdfvalue.Duration.FromSeconds(self.message_expiry_time), limit=max_count) result = [ rdf_flow_objects.GRRMessageFromClientActionRequest(r) for r in action_requests ] else: new_tasks = queue_manager.QueueManager(token=self.token).QueryAndOwn( queue=client.Queue(), limit=max_count, lease_seconds=self.message_expiry_time) initial_ttl = rdf_flows.GrrMessage().task_ttl check_before_sending = [] result = [] for task in new_tasks: if task.task_ttl < initial_ttl - 1: check_before_sending.append(task) else: result.append(task) if check_before_sending: with queue_manager.QueueManager(token=self.token) as manager: status_found = manager.MultiCheckStatus(check_before_sending) for task in check_before_sending: if task not in status_found: result.append(task) else: manager.DeQueueClientRequest(task) stats_collector_instance.Get().IncrementCounter("grr_messages_sent", len(result)) if result: logging.debug("Drained %d messages for %s in %s seconds.", len(result), client, time.time() - start_time) return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '71']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'federated_query'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42', '45', '48', '51', '54', '57', '60', '63', '66', '69']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'environment_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'natural_language_query'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'passages'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'aggregation'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'return_fields'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'highlight'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'passages_fields'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'passages_count'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'default_parameter', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'passages_characters'}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'default_parameter', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'deduplicate'}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'default_parameter', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'deduplicate_field'}; {'id': '50', 'type': 'None', 'children': []}, {'id': '51', 'type': 'default_parameter', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'collection_ids'}, {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'default_parameter', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'similar'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'default_parameter', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'similar_document_ids'}, {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'default_parameter', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'similar_fields'}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'default_parameter', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'bias'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'default_parameter', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'logging_opt_out'}; {'id': '68', 'type': 'None', 'children': []}, {'id': '69', 'type': 'dictionary_splat_pattern', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '71', 'type': 'block', 'children': ['72', '82', '89', '106', '115', '122', '131', '195', '210', '236']}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'environment_id'}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'raise_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'string', 'children': [], 'value': "'environment_id must be provided'"}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '85', 'type': 'dictionary', 'children': ['86']}; {'id': '86', 'type': 'pair', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': "'X-Watson-Logging-Opt-Out'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'logging_opt_out'}, {'id': '89', 'type': 'if_statement', 'children': ['90', '93']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'in'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'get_sdk_headers'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113', '114']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'discovery'"}, {'id': '113', 'type': 'string', 'children': [], 'value': "'V1'"}; {'id': '114', 'type': 'string', 'children': [], 'value': "'federated_query'"}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '125', 'type': 'dictionary', 'children': ['126']}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '134', 'type': 'dictionary', 'children': ['135', '138', '141', '144', '147', '150', '153', '156', '159', '162', '165', '168', '171', '174', '177', '180', '183', '186', '189', '192']}, {'id': '135', 'type': 'pair', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': "'filter'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '138', 'type': 'pair', 'children': ['139', '140']}, {'id': '139', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '141', 'type': 'pair', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'natural_language_query'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'natural_language_query'}; {'id': '144', 'type': 'pair', 'children': ['145', '146']}, {'id': '145', 'type': 'string', 'children': [], 'value': "'passages'"}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'passages'}, {'id': '147', 'type': 'pair', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'aggregation'"}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'aggregation'}; {'id': '150', 'type': 'pair', 'children': ['151', '152']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '153', 'type': 'pair', 'children': ['154', '155']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'return'"}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'return_fields'}; {'id': '156', 'type': 'pair', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '159', 'type': 'pair', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '162', 'type': 'pair', 'children': ['163', '164']}, {'id': '163', 'type': 'string', 'children': [], 'value': "'highlight'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'highlight'}, {'id': '165', 'type': 'pair', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': "'passages.fields'"}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'passages_fields'}; {'id': '168', 'type': 'pair', 'children': ['169', '170']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'passages.count'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'passages_count'}, {'id': '171', 'type': 'pair', 'children': ['172', '173']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'passages.characters'"}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'passages_characters'}; {'id': '174', 'type': 'pair', 'children': ['175', '176']}, {'id': '175', 'type': 'string', 'children': [], 'value': "'deduplicate'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'deduplicate'}, {'id': '177', 'type': 'pair', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': "'deduplicate.field'"}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'deduplicate_field'}; {'id': '180', 'type': 'pair', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': "'collection_ids'"}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'collection_ids'}, {'id': '183', 'type': 'pair', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'similar'"}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'similar'}; {'id': '186', 'type': 'pair', 'children': ['187', '188']}, {'id': '187', 'type': 'string', 'children': [], 'value': "'similar.document_ids'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'similar_document_ids'}, {'id': '189', 'type': 'pair', 'children': ['190', '191']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'similar.fields'"}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'similar_fields'}; {'id': '192', 'type': 'pair', 'children': ['193', '194']}, {'id': '193', 'type': 'string', 'children': [], 'value': "'bias'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'bias'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'/v1/environments/{0}/query'"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'list_splat', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': '_encode_path_vars'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'environment_id'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '217', 'type': 'argument_list', 'children': ['218', '221', '224', '227', '230', '233']}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'POST'"}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'accept_json'}, {'id': '235', 'type': 'True', 'children': []}; {'id': '236', 'type': 'return_statement', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'response'}
def federated_query(self, environment_id, filter=None, query=None, natural_language_query=None, passages=None, aggregation=None, count=None, return_fields=None, offset=None, sort=None, highlight=None, passages_fields=None, passages_count=None, passages_characters=None, deduplicate=None, deduplicate_field=None, collection_ids=None, similar=None, similar_document_ids=None, similar_fields=None, bias=None, logging_opt_out=None, **kwargs): if environment_id is None: raise ValueError('environment_id must be provided') headers = {'X-Watson-Logging-Opt-Out': logging_opt_out} if 'headers' in kwargs: headers.update(kwargs.get('headers')) sdk_headers = get_sdk_headers('discovery', 'V1', 'federated_query') headers.update(sdk_headers) params = {'version': self.version} data = { 'filter': filter, 'query': query, 'natural_language_query': natural_language_query, 'passages': passages, 'aggregation': aggregation, 'count': count, 'return': return_fields, 'offset': offset, 'sort': sort, 'highlight': highlight, 'passages.fields': passages_fields, 'passages.count': passages_count, 'passages.characters': passages_characters, 'deduplicate': deduplicate, 'deduplicate.field': deduplicate_field, 'collection_ids': collection_ids, 'similar': similar, 'similar.document_ids': similar_document_ids, 'similar.fields': similar_fields, 'bias': bias } url = '/v1/environments/{0}/query'.format( *self._encode_path_vars(environment_id)) response = self.request( method='POST', url=url, headers=headers, params=params, json=data, accept_json=True) return response
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query_relations'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'environment_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'collection_id'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'entities'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'evidence_count'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'dictionary_splat_pattern', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '27', 'type': 'block', 'children': ['28', '38', '48', '67', '82', '97', '101', '118', '127', '134', '143', '165', '181', '207']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'environment_id'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'raise_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'environment_id must be provided'"}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'collection_id'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'raise_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'string', 'children': [], 'value': "'collection_id must be provided'"}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'entities'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '56', 'type': 'list_comprehension', 'children': ['57', '64']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_convert_model'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'QueryRelationsEntity'}; {'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'entities'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '70', 'type': 'None', 'children': []}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_convert_model'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'QueryEntitiesContext'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '_convert_model'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'QueryRelationsFilter'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '100', 'type': 'dictionary', 'children': []}, {'id': '101', 'type': 'if_statement', 'children': ['102', '105']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'in'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'get_sdk_headers'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'discovery'"}, {'id': '125', 'type': 'string', 'children': [], 'value': "'V1'"}; {'id': '126', 'type': 'string', 'children': [], 'value': "'query_relations'"}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '137', 'type': 'dictionary', 'children': ['138']}; {'id': '138', 'type': 'pair', 'children': ['139', '140']}, {'id': '139', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '146', 'type': 'dictionary', 'children': ['147', '150', '153', '156', '159', '162']}, {'id': '147', 'type': 'pair', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'entities'"}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '150', 'type': 'pair', 'children': ['151', '152']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'context'"}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '153', 'type': 'pair', 'children': ['154', '155']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '156', 'type': 'pair', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'filter'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '159', 'type': 'pair', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "'count'"}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '162', 'type': 'pair', 'children': ['163', '164']}, {'id': '163', 'type': 'string', 'children': [], 'value': "'evidence_count'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'evidence_count'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'/v1/environments/{0}/collections/{1}/query_relations'"}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'list_splat', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': '_encode_path_vars'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'environment_id'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'collection_id'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '192', '195', '198', '201', '204']}, {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '191', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'accept_json'}; {'id': '206', 'type': 'True', 'children': []}, {'id': '207', 'type': 'return_statement', 'children': ['208']}
def query_relations(self, environment_id, collection_id, entities=None, context=None, sort=None, filter=None, count=None, evidence_count=None, **kwargs): if environment_id is None: raise ValueError('environment_id must be provided') if collection_id is None: raise ValueError('collection_id must be provided') if entities is not None: entities = [ self._convert_model(x, QueryRelationsEntity) for x in entities ] if context is not None: context = self._convert_model(context, QueryEntitiesContext) if filter is not None: filter = self._convert_model(filter, QueryRelationsFilter) headers = {} if 'headers' in kwargs: headers.update(kwargs.get('headers')) sdk_headers = get_sdk_headers('discovery', 'V1', 'query_relations') headers.update(sdk_headers) params = {'version': self.version} data = { 'entities': entities, 'context': context, 'sort': sort, 'filter': filter, 'count': count, 'evidence_count': evidence_count } url = '/v1/environments/{0}/collections/{1}/query_relations'.format( *self._encode_path_vars(environment_id, collection_id)) response = self.request( method='POST', url=url, headers=headers, params=params, json=data, accept_json=True) return response
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query_log'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23', '27', '44', '53', '60', '89', '93', '116']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '26', 'type': 'dictionary', 'children': []}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_sdk_headers'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'discovery'"}, {'id': '51', 'type': 'string', 'children': [], 'value': "'V1'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'query_log'"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '63', 'type': 'dictionary', 'children': ['64', '69', '72', '75', '78', '81']}; {'id': '64', 'type': 'pair', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'filter'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '72', 'type': 'pair', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'count'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '_convert_list'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'/v1/logs'"}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '104', '107', '110', '113']}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'GET'"}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'accept_json'}, {'id': '115', 'type': 'True', 'children': []}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'response'}
def query_log(self, filter=None, query=None, count=None, offset=None, sort=None, **kwargs): headers = {} if 'headers' in kwargs: headers.update(kwargs.get('headers')) sdk_headers = get_sdk_headers('discovery', 'V1', 'query_log') headers.update(sdk_headers) params = { 'version': self.version, 'filter': filter, 'query': query, 'count': count, 'offset': offset, 'sort': self._convert_list(sort) } url = '/v1/logs' response = self.request( method='GET', url=url, headers=headers, params=params, accept_json=True) return response
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_workspaces'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'page_limit'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'include_count'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'include_audit'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23', '27', '44', '53', '60', '84', '88', '111']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '26', 'type': 'dictionary', 'children': []}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_sdk_headers'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'conversation'"}, {'id': '51', 'type': 'string', 'children': [], 'value': "'V1'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'list_workspaces'"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '63', 'type': 'dictionary', 'children': ['64', '69', '72', '75', '78', '81']}; {'id': '64', 'type': 'pair', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'page_limit'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'page_limit'}; {'id': '72', 'type': 'pair', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'include_count'"}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'include_count'}, {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'cursor'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'include_audit'"}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'include_audit'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'/v1/workspaces'"}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '99', '102', '105', '108']}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'accept_json'}; {'id': '110', 'type': 'True', 'children': []}, {'id': '111', 'type': 'return_statement', 'children': ['112']}
def list_workspaces(self, page_limit=None, include_count=None, sort=None, cursor=None, include_audit=None, **kwargs): headers = {} if 'headers' in kwargs: headers.update(kwargs.get('headers')) sdk_headers = get_sdk_headers('conversation', 'V1', 'list_workspaces') headers.update(sdk_headers) params = { 'version': self.version, 'page_limit': page_limit, 'include_count': include_count, 'sort': sort, 'cursor': cursor, 'include_audit': include_audit } url = '/v1/workspaces' response = self.request( method='GET', url=url, headers=headers, params=params, accept_json=True) return response
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '55']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_feedback'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44', '47', '50', '53']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'feedback_type'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'after'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'document_title'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'model_id'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'model_version'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'category_removed'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'category_added'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'category_not_changed'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'type_removed'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'type_added'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'type_not_changed'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'default_parameter', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'page_limit'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'default_parameter', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'default_parameter', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'default_parameter', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'include_total'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'dictionary_splat_pattern', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '55', 'type': 'block', 'children': ['56', '60', '77', '86', '93', '150', '154', '177']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '59', 'type': 'dictionary', 'children': []}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'headers'"}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'headers'"}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_sdk_headers'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'compare-comply'"}; {'id': '84', 'type': 'string', 'children': [], 'value': "'V1'"}, {'id': '85', 'type': 'string', 'children': [], 'value': "'list_feedback'"}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sdk_headers'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '96', 'type': 'dictionary', 'children': ['97', '102', '105', '108', '111', '114', '117', '120', '123', '126', '129', '132', '135', '138', '141', '144', '147']}, {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'version'"}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '102', 'type': 'pair', 'children': ['103', '104']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'feedback_type'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'feedback_type'}, {'id': '105', 'type': 'pair', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': "'before'"}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '108', 'type': 'pair', 'children': ['109', '110']}, {'id': '109', 'type': 'string', 'children': [], 'value': "'after'"}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'after'}, {'id': '111', 'type': 'pair', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'document_title'"}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'document_title'}; {'id': '114', 'type': 'pair', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': "'model_id'"}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'model_id'}, {'id': '117', 'type': 'pair', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'model_version'"}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'model_version'}; {'id': '120', 'type': 'pair', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'category_removed'"}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'category_removed'}, {'id': '123', 'type': 'pair', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'category_added'"}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'category_added'}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'category_not_changed'"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'category_not_changed'}, {'id': '129', 'type': 'pair', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'type_removed'"}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'type_removed'}; {'id': '132', 'type': 'pair', 'children': ['133', '134']}, {'id': '133', 'type': 'string', 'children': [], 'value': "'type_added'"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'type_added'}, {'id': '135', 'type': 'pair', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': "'type_not_changed'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'type_not_changed'}; {'id': '138', 'type': 'pair', 'children': ['139', '140']}, {'id': '139', 'type': 'string', 'children': [], 'value': "'page_limit'"}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'page_limit'}, {'id': '141', 'type': 'pair', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'cursor'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '144', 'type': 'pair', 'children': ['145', '146']}, {'id': '145', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '147', 'type': 'pair', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'include_total'"}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'include_total'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'/v1/feedback'"}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '161', 'type': 'argument_list', 'children': ['162', '165', '168', '171', '174']}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'accept_json'}; {'id': '176', 'type': 'True', 'children': []}, {'id': '177', 'type': 'return_statement', 'children': ['178']}
def list_feedback(self, feedback_type=None, before=None, after=None, document_title=None, model_id=None, model_version=None, category_removed=None, category_added=None, category_not_changed=None, type_removed=None, type_added=None, type_not_changed=None, page_limit=None, cursor=None, sort=None, include_total=None, **kwargs): headers = {} if 'headers' in kwargs: headers.update(kwargs.get('headers')) sdk_headers = get_sdk_headers('compare-comply', 'V1', 'list_feedback') headers.update(sdk_headers) params = { 'version': self.version, 'feedback_type': feedback_type, 'before': before, 'after': after, 'document_title': document_title, 'model_id': model_id, 'model_version': model_version, 'category_removed': category_removed, 'category_added': category_added, 'category_not_changed': category_not_changed, 'type_removed': type_removed, 'type_added': type_added, 'type_not_changed': type_not_changed, 'page_limit': page_limit, 'cursor': cursor, 'sort': sort, 'include_total': include_total } url = '/v1/feedback' response = self.request( method='GET', url=url, headers=headers, params=params, accept_json=True) return response
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'multi_index_insert_row'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'index_row'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'values_row'}, {'id': '7', 'type': 'block', 'children': ['8', '32', '49', '60', '88']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'row_index'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '24']}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'levels'}; {'id': '18', 'type': 'list_comprehension', 'children': ['19', '21']}, {'id': '19', 'type': 'list', 'children': ['20'], 'value': '[i]'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'index_row'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '26', 'type': 'list_comprehension', 'children': ['27', '29']}, {'id': '27', 'type': 'list', 'children': ['28'], 'value': '[0]'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'index_row'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'values_row'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'row_index'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'tuple', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '85']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '72'], 'value': 'and'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '68'], 'value': '=='}, {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'lexsort_depth'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'index_row'}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '79'], 'value': '<'}, {'id': '73', 'type': 'subscript', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '77', 'type': 'unary_operator', 'children': ['78'], 'value': '-'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '79', 'type': 'subscript', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '83', 'type': 'unary_operator', 'children': ['84'], 'value': '-'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sort_index'}, {'id': '93', 'type': 'argument_list', 'children': []}
def multi_index_insert_row(df, index_row, values_row): row_index = pd.MultiIndex(levels=[[i] for i in index_row], labels=[[0] for i in index_row]) row = pd.DataFrame(values_row, index=row_index, columns=df.columns) df = pd.concat((df, row)) if df.index.lexsort_depth == len(index_row) and df.index[-2] < df.index[-1]: return df return df.sort_index()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'substring_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'list_comprehension', 'children': ['9', '10', '16']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '10', 'type': 'for_in_clause', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '16', 'type': 'if_clause', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}
def substring_search(word, collection): return [item for item in sorted(collection) if item.startswith(word)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_nodes'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'list_comprehension', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '15', 'type': 'for_in_clause', 'children': ['16', '19']}; {'id': '16', 'type': 'pattern_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'timeslice'}, {'id': '19', 'type': 'call', 'children': ['20', '27']}; {'id': '20', 'type': 'attribute', 'children': ['21', '26']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'DynamicBayesianNetwork'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '27', 'type': 'argument_list', 'children': []}
def _nodes(self): return list(set([node for node, timeslice in super(DynamicBayesianNetwork, self).nodes()]))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_edge'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '144', '211', '225']}; {'id': '10', 'type': 'try_statement', 'children': ['11', '136']}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '26', '32', '56', '81', '108', '122']}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '20'], 'value': 'or'}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': '!='}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '!='}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'Nodes must be of type (node, time_slice).'"}; {'id': '32', 'type': 'elif_clause', 'children': ['33', '50']}, {'id': '33', 'type': 'boolean_operator', 'children': ['34', '42'], 'value': 'or'}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '42', 'type': 'not_operator', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'Nodes must be of type (node, time_slice).'"}; {'id': '56', 'type': 'elif_clause', 'children': ['57', '64']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'block', 'children': ['65', '73']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '68', 'type': 'tuple', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '76', 'type': 'tuple', 'children': ['77', '80']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '81', 'type': 'elif_clause', 'children': ['82', '91']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '86'], 'value': '=='}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '90'], 'value': '-'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'block', 'children': ['92', '100']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '95', 'type': 'tuple', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '103', 'type': 'tuple', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'elif_clause', 'children': ['109', '116']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '>'}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'raise_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'Edges in backward direction are not allowed.'"}; {'id': '122', 'type': 'elif_clause', 'children': ['123', '130']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': '!='}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'raise_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'string', 'children': [], 'value': '"Edges over multiple time slices is not currently supported"'}; {'id': '136', 'type': 'except_clause', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'raise_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'string', 'children': [], 'value': "'Nodes must be of type (node, time_slice).'"}; {'id': '144', 'type': 'if_statement', 'children': ['145', '148', '154']}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '=='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'raise_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'string', 'children': [], 'value': "'Self Loops are not allowed'"}; {'id': '154', 'type': 'elif_clause', 'children': ['155', '189']}, {'id': '155', 'type': 'boolean_operator', 'children': ['156', '180', '181'], 'value': 'and'}; {'id': '156', 'type': 'boolean_operator', 'children': ['157', '168'], 'value': 'and'}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'in'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '159', 'type': 'call', 'children': ['160', '167']}; {'id': '160', 'type': 'attribute', 'children': ['161', '166']}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'DynamicBayesianNetwork'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170', '171'], 'value': 'in'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '170', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '171', 'type': 'call', 'children': ['172', '179']}; {'id': '172', 'type': 'attribute', 'children': ['173', '178']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'DynamicBayesianNetwork'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '179', 'type': 'argument_list', 'children': []}; {'id': '180', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'has_path'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187', '188']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'raise_statement', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'string', 'children': [], 'value': "'Loops are not allowed. Adding the edge from ({start} --> {end}) forms a loop.'"}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '205']}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '220']}, {'id': '213', 'type': 'attribute', 'children': ['214', '219']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'DynamicBayesianNetwork'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222', '223']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '223', 'type': 'dictionary_splat', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '233', '262']}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '230'], 'value': '=='}, {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '243']}; {'id': '236', 'type': 'attribute', 'children': ['237', '242']}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'DynamicBayesianNetwork'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'add_edge'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '253']}; {'id': '244', 'type': 'tuple', 'children': ['245', '248']}, {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '247', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '-'}, {'id': '249', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '252', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '253', 'type': 'tuple', 'children': ['254', '257']}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '256', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '257', 'type': 'binary_operator', 'children': ['258', '259'], 'value': '-'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '259', 'type': 'subscript', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '261', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '262', 'type': 'else_clause', 'children': ['263']}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '273']}; {'id': '266', 'type': 'attribute', 'children': ['267', '272']}, {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '269', 'type': 'argument_list', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'DynamicBayesianNetwork'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'add_node'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'tuple', 'children': ['275', '278']}, {'id': '275', 'type': 'subscript', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '278', 'type': 'binary_operator', 'children': ['279', '280'], 'value': '-'}, {'id': '279', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'end'}
def add_edge(self, start, end, **kwargs): try: if len(start) != 2 or len(end) != 2: raise ValueError('Nodes must be of type (node, time_slice).') elif not isinstance(start[1], int) or not isinstance(end[1], int): raise ValueError('Nodes must be of type (node, time_slice).') elif start[1] == end[1]: start = (start[0], 0) end = (end[0], 0) elif start[1] == end[1] - 1: start = (start[0], 0) end = (end[0], 1) elif start[1] > end[1]: raise NotImplementedError('Edges in backward direction are not allowed.') elif start[1] != end[1]: raise ValueError("Edges over multiple time slices is not currently supported") except TypeError: raise ValueError('Nodes must be of type (node, time_slice).') if start == end: raise ValueError('Self Loops are not allowed') elif start in super(DynamicBayesianNetwork, self).nodes() and end \ in super(DynamicBayesianNetwork, self).nodes() and \ nx.has_path(self, end, start): raise ValueError('Loops are not allowed. Adding the edge from ({start} --> {end}) forms a loop.'.format( start=str(start), end=str(end))) super(DynamicBayesianNetwork, self).add_edge(start, end, **kwargs) if start[1] == end[1]: super(DynamicBayesianNetwork, self).add_edge((start[0], 1 - start[1]), (end[0], 1 - end[1])) else: super(DynamicBayesianNetwork, self).add_node((end[0], 1 - end[1]))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'estimate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tabu_length'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_indegree'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '19', '29', '75', '79', '83', '239']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '18', 'type': 'float', 'children': [], 'value': '1e-8'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'state_names'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33', '47']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'block', 'children': ['34', '40']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'DAG'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'add_nodes_from'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '47', 'type': 'elif_clause', 'children': ['48', '69']}; {'id': '48', 'type': 'boolean_operator', 'children': ['49', '55'], 'value': 'or'}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'DAG'}, {'id': '55', 'type': 'not_operator', 'children': ['56']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '65'], 'value': '=='}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'raise_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"\'start\' should be a DAG with the same variables as the data set, or \'None\'."'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}; {'id': '78', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'current_model'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '83', 'type': 'while_statement', 'children': ['84', '85']}; {'id': '84', 'type': 'True', 'children': []}, {'id': '85', 'type': 'block', 'children': ['86', '90', '94', '120']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'best_score_delta'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'best_operation'}, {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'for_statement', 'children': ['95', '98', '106']}, {'id': '95', 'type': 'pattern_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'score_delta'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_legal_operations'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104', '105']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'current_model'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'max_indegree'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'if_statement', 'children': ['108', '111']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '>'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'score_delta'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'best_score_delta'}, {'id': '111', 'type': 'block', 'children': ['112', '116']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'best_operation'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'best_score_delta'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'score_delta'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '128', '130', '163', '196']}, {'id': '121', 'type': 'boolean_operator', 'children': ['122', '125'], 'value': 'or'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'best_operation'}; {'id': '124', 'type': 'None', 'children': []}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '<'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'best_score_delta'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'break_statement', 'children': []}; {'id': '130', 'type': 'elif_clause', 'children': ['131', '136']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'best_operation'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'+'"}; {'id': '136', 'type': 'block', 'children': ['137', '147']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'current_model'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'list_splat', 'children': ['144']}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'best_operation'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}; {'id': '150', 'type': 'subscript', 'children': ['151', '160']}, {'id': '151', 'type': 'parenthesized_expression', 'children': ['152']}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '159'], 'value': '+'}, {'id': '153', 'type': 'list', 'children': ['154'], 'value': "[('-', best_operation[1])]"}; {'id': '154', 'type': 'tuple', 'children': ['155', '156']}, {'id': '155', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'best_operation'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}; {'id': '160', 'type': 'slice', 'children': ['161', '162']}, {'id': '161', 'type': 'colon', 'children': []}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'tabu_length'}, {'id': '163', 'type': 'elif_clause', 'children': ['164', '169']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '168'], 'value': '=='}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'best_operation'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '168', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '169', 'type': 'block', 'children': ['170', '180']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'current_model'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'remove_edge'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'list_splat', 'children': ['177']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'best_operation'}, {'id': '179', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}, {'id': '183', 'type': 'subscript', 'children': ['184', '193']}; {'id': '184', 'type': 'parenthesized_expression', 'children': ['185']}, {'id': '185', 'type': 'binary_operator', 'children': ['186', '192'], 'value': '+'}; {'id': '186', 'type': 'list', 'children': ['187'], 'value': "[('+', best_operation[1])]"}, {'id': '187', 'type': 'tuple', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'+'"}, {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'best_operation'}, {'id': '191', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}, {'id': '193', 'type': 'slice', 'children': ['194', '195']}; {'id': '194', 'type': 'colon', 'children': []}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'tabu_length'}; {'id': '196', 'type': 'elif_clause', 'children': ['197', '202']}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '201'], 'value': '=='}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'best_operation'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'flip'"}; {'id': '202', 'type': 'block', 'children': ['203', '211', '219', '227']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '208']}, {'id': '205', 'type': 'pattern_list', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'Y'}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'best_operation'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'current_model'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'remove_edge'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'Y'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'current_model'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'Y'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}; {'id': '230', 'type': 'subscript', 'children': ['231', '236']}, {'id': '231', 'type': 'parenthesized_expression', 'children': ['232']}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '235'], 'value': '+'}, {'id': '233', 'type': 'list', 'children': ['234'], 'value': '[best_operation]'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'best_operation'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'tabu_list'}; {'id': '236', 'type': 'slice', 'children': ['237', '238']}, {'id': '237', 'type': 'colon', 'children': []}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'tabu_length'}, {'id': '239', 'type': 'return_statement', 'children': ['240']}
def estimate(self, start=None, tabu_length=0, max_indegree=None): epsilon = 1e-8 nodes = self.state_names.keys() if start is None: start = DAG() start.add_nodes_from(nodes) elif not isinstance(start, DAG) or not set(start.nodes()) == set(nodes): raise ValueError("'start' should be a DAG with the same variables as the data set, or 'None'.") tabu_list = [] current_model = start while True: best_score_delta = 0 best_operation = None for operation, score_delta in self._legal_operations(current_model, tabu_list, max_indegree): if score_delta > best_score_delta: best_operation = operation best_score_delta = score_delta if best_operation is None or best_score_delta < epsilon: break elif best_operation[0] == '+': current_model.add_edge(*best_operation[1]) tabu_list = ([('-', best_operation[1])] + tabu_list)[:tabu_length] elif best_operation[0] == '-': current_model.remove_edge(*best_operation[1]) tabu_list = ([('+', best_operation[1])] + tabu_list)[:tabu_length] elif best_operation[0] == 'flip': X, Y = best_operation[1] current_model.remove_edge(X, Y) current_model.add_edge(Y, X) tabu_list = ([best_operation] + tabu_list)[:tabu_length] return current_model
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_node'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'weight'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '64']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '31', '55']}, {'id': '11', 'type': 'boolean_operator', 'children': ['12', '24'], 'value': 'and'}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '18'], 'value': 'and'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '23'], 'value': '=='}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30']}, {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '31', 'type': 'block', 'children': ['32', '38']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '37']}; {'id': '34', 'type': 'pattern_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '48']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '47'], 'value': 'is'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'weight'"}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'weight'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'weight'}, {'id': '55', 'type': 'else_clause', 'children': ['56']}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '60', 'type': 'dictionary', 'children': ['61']}, {'id': '61', 'type': 'pair', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'weight'"}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'weight'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '73']}; {'id': '66', 'type': 'attribute', 'children': ['67', '72']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'DAG'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'add_node'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'weight'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'weight'}
def add_node(self, node, weight=None): if isinstance(node, tuple) and len(node) == 2 and isinstance(node[1], dict): node, attrs = node if attrs.get('weight', None) is not None: attrs['weight'] = weight else: attrs = {'weight': weight} super(DAG, self).add_node(node, weight=weight)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_nodes_from'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '17']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '19', '64']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '19', 'type': 'block', 'children': ['20', '38']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '30']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '26'], 'value': '!='}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'raise_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'concatenated_string', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"The number of elements in nodes and weights"'}, {'id': '37', 'type': 'string', 'children': [], 'value': '"should be equal."'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '47']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'add_node'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '59']}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'weight'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '69']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'add_node'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'node'}
def add_nodes_from(self, nodes, weights=None): nodes = list(nodes) if weights: if len(nodes) != len(weights): raise ValueError("The number of elements in nodes and weights" "should be equal.") for index in range(len(nodes)): self.add_node(node=nodes[index], weight=weights[index]) else: for node in nodes: self.add_node(node=node)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank_items'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'userid'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'user_items'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'selected_items'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'recalculate_user'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '36', '42', '53', '77', '91', '112']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '30']}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '24'], 'value': 'or'}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': '>='}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'selected_items'}, {'id': '19', 'type': 'subscript', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'user_items'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '29'], 'value': '<'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'selected_items'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'raise_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': '"Some of selected itemids are not in the model"'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'liked_vector'}, {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'user_items'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'userid'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'recommendations'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'liked_vector'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'similarity'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '68']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'recommendations'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'recommendations'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'lambda', 'children': ['71', '73']}, {'id': '71', 'type': 'lambda_parameters', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '73', 'type': 'unary_operator', 'children': ['74'], 'value': '-'}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '80', 'type': 'list_comprehension', 'children': ['81', '82', '85']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'best'}, {'id': '85', 'type': 'if_clause', 'children': ['86']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': 'in'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'selected_items'}, {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'itemid'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'selected_items'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'if_statement', 'children': ['96', '101']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'not'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'itemid'}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'recommendations'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'tuple', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'itemid'}; {'id': '110', 'type': 'unary_operator', 'children': ['111'], 'value': '-'}, {'id': '111', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '112', 'type': 'return_statement', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ret'}
def rank_items(self, userid, user_items, selected_items, recalculate_user=False): if max(selected_items) >= user_items.shape[1] or min(selected_items) < 0: raise IndexError("Some of selected itemids are not in the model") liked_vector = user_items[userid] recommendations = liked_vector.dot(self.similarity) best = sorted(zip(recommendations.indices, recommendations.data), key=lambda x: -x[1]) ret = [rec for rec in best if rec[0] in selected_items] for itemid in selected_items: if itemid not in recommendations.indices: ret.append((itemid, -1.0)) return ret
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_structure'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '25']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sites'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'from_sites'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sites'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'charge'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}
def get_sorted_structure(self, key=None, reverse=False): sites = sorted(self, key=key, reverse=reverse) return self.__class__.from_sites(sites, charge=self._charge)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_str'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_string'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'primitive'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'merge_tol'}, {'id': '15', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '16', 'type': 'block', 'children': ['17', '24', '31', '38', '45', '52', '60', '218', '229', '239']}, {'id': '17', 'type': 'import_from_statement', 'children': ['18', '22']}; {'id': '18', 'type': 'dotted_name', 'children': ['19', '20', '21']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pymatgen'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'io'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cif'}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'CifParser'}; {'id': '24', 'type': 'import_from_statement', 'children': ['25', '29']}, {'id': '25', 'type': 'dotted_name', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pymatgen'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'vasp'}, {'id': '29', 'type': 'dotted_name', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'Poscar'}, {'id': '31', 'type': 'import_from_statement', 'children': ['32', '36']}; {'id': '32', 'type': 'dotted_name', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pymatgen'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'io'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cssr'}; {'id': '36', 'type': 'dotted_name', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'Cssr'}; {'id': '38', 'type': 'import_from_statement', 'children': ['39', '43']}, {'id': '39', 'type': 'dotted_name', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'pymatgen'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'xcrysden'}, {'id': '43', 'type': 'dotted_name', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'XSF'}, {'id': '45', 'type': 'import_from_statement', 'children': ['46', '50']}; {'id': '46', 'type': 'dotted_name', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pymatgen'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'io'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'atat'}; {'id': '50', 'type': 'dotted_name', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'Mcsqs'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64', '87', '107', '127', '150', '179', '195', '209']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '=='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '63', 'type': 'string', 'children': [], 'value': '"cif"'}; {'id': '64', 'type': 'block', 'children': ['65', '74']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'CifParser'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'from_string'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'input_string'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '77', 'type': 'subscript', 'children': ['78', '86']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_structures'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'primitive'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'primitive'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '87', 'type': 'elif_clause', 'children': ['88', '91']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '=='}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '90', 'type': 'string', 'children': [], 'value': '"poscar"'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '95', 'type': 'attribute', 'children': ['96', '106']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'Poscar'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'from_string'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'input_string'}; {'id': '102', 'type': 'False', 'children': []}, {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'read_velocities'}, {'id': '105', 'type': 'False', 'children': []}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'structure'}, {'id': '107', 'type': 'elif_clause', 'children': ['108', '111']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '=='}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"cssr"'}, {'id': '111', 'type': 'block', 'children': ['112', '121']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'cssr'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'Cssr'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'from_string'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'input_string'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cssr'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'structure'}, {'id': '127', 'type': 'elif_clause', 'children': ['128', '131']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '130', 'type': 'string', 'children': [], 'value': '"json"'}, {'id': '131', 'type': 'block', 'children': ['132', '141']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'loads'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'input_string'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'Structure'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'from_dict'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '150', 'type': 'elif_clause', 'children': ['151', '154']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '=='}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '153', 'type': 'string', 'children': [], 'value': '"yaml"'}; {'id': '154', 'type': 'block', 'children': ['155', '161', '170']}, {'id': '155', 'type': 'import_statement', 'children': ['156']}; {'id': '156', 'type': 'aliased_import', 'children': ['157', '160']}, {'id': '157', 'type': 'dotted_name', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ruamel'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'yaml'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'yaml'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'safe_load'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'input_string'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'Structure'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'from_dict'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '179', 'type': 'elif_clause', 'children': ['180', '183']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '=='}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '182', 'type': 'string', 'children': [], 'value': '"xsf"'}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '187', 'type': 'attribute', 'children': ['188', '194']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'XSF'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'from_string'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'input_string'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'structure'}, {'id': '195', 'type': 'elif_clause', 'children': ['196', '199']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '=='}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"mcsqs"'}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'Mcsqs'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'structure_from_string'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'input_string'}, {'id': '209', 'type': 'else_clause', 'children': ['210']}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'raise_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '%'}; {'id': '216', 'type': 'string', 'children': [], 'value': '"Unrecognized format `%s`!"'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'get_sorted_structure'}; {'id': '228', 'type': 'argument_list', 'children': []}, {'id': '229', 'type': 'if_statement', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'merge_tol'}, {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'merge_sites'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'merge_tol'}, {'id': '239', 'type': 'return_statement', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'from_sites'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 's'}
def from_str(cls, input_string, fmt, primitive=False, sort=False, merge_tol=0.0): from pymatgen.io.cif import CifParser from pymatgen.io.vasp import Poscar from pymatgen.io.cssr import Cssr from pymatgen.io.xcrysden import XSF from pymatgen.io.atat import Mcsqs fmt = fmt.lower() if fmt == "cif": parser = CifParser.from_string(input_string) s = parser.get_structures(primitive=primitive)[0] elif fmt == "poscar": s = Poscar.from_string(input_string, False, read_velocities=False).structure elif fmt == "cssr": cssr = Cssr.from_string(input_string) s = cssr.structure elif fmt == "json": d = json.loads(input_string) s = Structure.from_dict(d) elif fmt == "yaml": import ruamel.yaml as yaml d = yaml.safe_load(input_string) s = Structure.from_dict(d) elif fmt == "xsf": s = XSF.from_string(input_string).structure elif fmt == "mcsqs": s = Mcsqs.structure_from_string(input_string) else: raise ValueError("Unrecognized format `%s`!" % fmt) if sort: s = s.get_sorted_structure() if merge_tol: s.merge_sites(merge_tol) return cls.from_sites(s)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_transition_chempots'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '25', '49', '53', '99', '105']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'not'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'elements'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'concatenated_string', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': '"get_transition_chempots can only be called with "'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"elements in the phase diagram."'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'critical_chempots'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '30']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'facet'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'facets'}; {'id': '30', 'type': 'block', 'children': ['31', '40']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'chempots'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_get_facet_chempots'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'facet'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'critical_chempots'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'chempots'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'clean_pots'}; {'id': '52', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '59']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'critical_chempots'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '67', '75']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '66'], 'value': '=='}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'clean_pots'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'clean_pots'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'if_statement', 'children': ['78', '91']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '88'], 'value': '>'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '-'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'clean_pots'}; {'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '-'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'PhaseDiagram'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'numerical_tol'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'clean_pots'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'clean_pots'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'clean_pots'}
def get_transition_chempots(self, element): if element not in self.elements: raise ValueError("get_transition_chempots can only be called with " "elements in the phase diagram.") critical_chempots = [] for facet in self.facets: chempots = self._get_facet_chempots(facet) critical_chempots.append(chempots[element]) clean_pots = [] for c in sorted(critical_chempots): if len(clean_pots) == 0: clean_pots.append(c) else: if abs(c - clean_pots[-1]) > PhaseDiagram.numerical_tol: clean_pots.append(c) clean_pots.reverse() return tuple(clean_pots)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_dir'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'exts'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"_*"'}; {'id': '12', 'type': 'block', 'children': ['13', '17', '177']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pseudos'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21', '123']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'exts'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"all_files"'}, {'id': '21', 'type': 'block', 'children': ['22', '96', '111']}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '42']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '24', 'type': 'list_comprehension', 'children': ['25', '34']}, {'id': '25', 'type': 'call', 'children': ['26', '31']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'if_statement', 'children': ['44', '52']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'try_statement', 'children': ['54', '85']}; {'id': '54', 'type': 'block', 'children': ['55', '64']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'Pseudo'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'from_file'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66', '74']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'pseudos'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '74', 'type': 'else_clause', 'children': ['75']}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '%'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'Skipping file %s'"}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '85', 'type': 'except_clause', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '%'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'Skipping file %s'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '99']}, {'id': '97', 'type': 'not_operator', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'pseudos'}, {'id': '99', 'type': 'block', 'children': ['100', '109']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '%'}, {'id': '107', 'type': 'string', 'children': [], 'value': "'No pseudopotentials parsed from folder %s'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '109', 'type': 'return_statement', 'children': ['110']}; {'id': '110', 'type': 'None', 'children': []}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '%'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'Creating PseudoTable with %i pseudopotentials'"}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'pseudos'}, {'id': '123', 'type': 'else_clause', 'children': ['124']}; {'id': '124', 'type': 'block', 'children': ['125', '135']}, {'id': '125', 'type': 'if_statement', 'children': ['126', '129']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'exts'}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'exts'}, {'id': '133', 'type': 'tuple', 'children': ['134']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"psp8"'}, {'id': '135', 'type': 'for_statement', 'children': ['136', '137', '145']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'find_exts'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141', '142']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'exts'}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'try_statement', 'children': ['147', '160']}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'pseudos'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'Pseudo'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'from_file'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '160', 'type': 'except_clause', 'children': ['161', '165']}, {'id': '161', 'type': 'as_pattern', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '163', 'type': 'as_pattern_target', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'critical'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'}, {'id': '173', 'type': 'string', 'children': [], 'value': '"Error in %s:\\n%s"'}; {'id': '174', 'type': 'tuple', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '177', 'type': 'return_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '185']}, {'id': '179', 'type': 'attribute', 'children': ['180', '184']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'pseudos'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'sort_by_z'}, {'id': '185', 'type': 'argument_list', 'children': []}
def from_dir(cls, top, exts=None, exclude_dirs="_*"): pseudos = [] if exts == "all_files": for f in [os.path.join(top, fn) for fn in os.listdir(top)]: if os.path.isfile(f): try: p = Pseudo.from_file(f) if p: pseudos.append(p) else: logger.info('Skipping file %s' % f) except: logger.info('Skipping file %s' % f) if not pseudos: logger.warning('No pseudopotentials parsed from folder %s' % top) return None logger.info('Creating PseudoTable with %i pseudopotentials' % len(pseudos)) else: if exts is None: exts=("psp8",) for p in find_exts(top, exts, exclude_dirs=exclude_dirs): try: pseudos.append(Pseudo.from_file(p)) except Exception as exc: logger.critical("Error in %s:\n%s" % (p, exc)) return cls(pseudos).sort_by_z()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '14', '48']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '18', '19']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pseudo'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'block', 'children': ['20', '39']}; {'id': '20', 'type': 'try_statement', 'children': ['21', '30']}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pseudo'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '30', 'type': 'except_clause', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'tuple', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '60']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '74']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '68', 'type': 'lambda', 'children': ['69', '71']}, {'id': '69', 'type': 'lambda_parameters', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sorted(self, attrname, reverse=False): attrs = [] for i, pseudo in self: try: a = getattr(pseudo, attrname) except AttributeError: a = np.inf attrs.append((i, a)) return self.__class__([self[a[0]] for a in sorted(attrs, key=lambda t: t[1], reverse=reverse)])