sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'slice_locs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'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': 'end'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'slice_locs'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28', '29']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'kind'}
def slice_locs(self, start=None, end=None, step=None, kind=None): return super().slice_locs(start, end, step, kind=kind)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_loc'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '22', '97', '122', '129', '151', '171', '177', '193', '214', '224', '234', '245', '258', '318']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'raise_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'concatenated_string', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'only the default get_loc method is '"},{'id': '21', 'type': 'string', 'children': [], 'value': "'currently supported for MultiIndex'"},{'id': '22', 'type': 'function_definition', 'children': ['23', '24', '26']},{'id': '23', 'type': 'function_name', 'children': [], 'value': '_maybe_to_slice'},{'id': '24', 'type': 'parameters', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '26', 'type': 'block', 'children': ['27', '45', '58', '67', '82', '89', '95']},{'id': '27', 'type': 'if_statement', 'children': ['28', '42']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '37'], 'value': 'or'},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '!='},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '41', 'type': 'string', 'children': [], 'value': "'int64'"},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'maybe_indices_to_slice'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'if_statement', 'children': ['59', '64']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '74', 'type': 'argument_list', 'children': ['75', '79']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '81', 'type': 'string', 'children': [], 'value': "'bool'"},{'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': 'mask'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'fill'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'False', 'children': []},{'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': 'mask'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '94', 'type': 'True', 'children': []},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '97', 'type': 'if_statement', 'children': ['98', '104']},{'id': '98', 'type': 'not_operator', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '104', 'type': 'block', 'children': ['105', '117']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_get_level_indexer'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '116', 'type': 'integer', 'children': [], 'value': '0'},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_maybe_to_slice'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'keylen'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '129', 'type': 'if_statement', 'children': ['130', '135']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': '<'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'nlevels'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'keylen'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'raise_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'concatenated_string', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'Key length ({0}) exceeds index depth ({1})'"},{'id': '144', 'type': 'string', 'children': [], 'value': "''"},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'keylen'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'nlevels'},{'id': '151', 'type': 'if_statement', 'children': ['152', '161']},{'id': '152', 'type': 'boolean_operator', 'children': ['153', '158'], 'value': 'and'},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '=='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'keylen'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'nlevels'},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'is_unique'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'return_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_engine'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'get_loc'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'lexsort_depth'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'pattern_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'lead_key'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'follow_key'},{'id': '182', 'type': 'expression_list', 'children': ['183', '188']},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '185', 'type': 'slice', 'children': ['186', '187']},{'id': '186', 'type': 'colon', 'children': []},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '190', 'type': 'slice', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '192', 'type': 'colon', 'children': []},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '198']},{'id': '195', 'type': 'pattern_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '198', 'type': '()', 'children': ['199']},{'id': '199', 'type': 'conditional_expression', 'children': ['200', '207', '208'], 'value': 'if'},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'slice_locs'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'lead_key'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'lead_key'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'lead_key'},{'id': '208', 'type': 'tuple', 'children': ['209', '210']},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'if_statement', 'children': ['215', '218']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': '=='},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'raise_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '224', 'type': 'if_statement', 'children': ['225', '227']},{'id': '225', 'type': 'not_operator', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'follow_key'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241', '242']},{'id': '240', 'type': 'string', 'children': [], 'value': "'indexing past lexsort depth may impact performance.'"},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'PerformanceWarning'},{'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'stacklevel'},{'id': '244', 'type': 'integer', 'children': [], 'value': '10'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '252', 'type': 'argument_list', 'children': ['253', '254', '255']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '257', 'type': 'string', 'children': [], 'value': "'int64'"},{'id': '258', 'type': 'for_statement', 'children': ['259', '262', '270']},{'id': '259', 'type': 'pattern_list', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'follow_key'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'lead_key'},{'id': '270', 'type': 'block', 'children': ['271', '292', '306']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '274', 'type': 'comparison_operator', 'children': ['275', '282'], 'value': '=='},{'id': '275', 'type': 'subscript', 'children': ['276', '281']},{'id': '276', 'type': 'subscript', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '282', 'type': 'call', 'children': ['283', '290']},{'id': '283', 'type': 'attribute', 'children': ['284', '289']},{'id': '284', 'type': 'subscript', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'get_loc'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '292', 'type': 'if_statement', 'children': ['293', '299']},{'id': '293', 'type': 'not_operator', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '298', 'type': 'argument_list', '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': 'loc'},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '306', 'type': 'if_statement', 'children': ['307', '312']},{'id': '307', 'type': 'not_operator', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'raise_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '318', 'type': 'return_statement', 'children': ['319']},{'id': '319', 'type': '()', 'children': ['320']},{'id': '320', 'type': 'conditional_expression', 'children': ['321', '325', '333'], 'value': 'if'},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': '_maybe_to_slice'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '325', 'type': 'comparison_operator', 'children': ['326', '330'], 'value': '!='},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '330', 'type': 'binary_operator', 'children': ['331', '332'], 'value': '-'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '333', 'type': 'call', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '335', 'type': 'argument_list', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'stop'}
def get_loc(self, key, method=None): if method is not None: raise NotImplementedError('only the default get_loc method is ' 'currently supported for MultiIndex') def _maybe_to_slice(loc): if not isinstance(loc, np.ndarray) or loc.dtype != 'int64': return loc loc = lib.maybe_indices_to_slice(loc, len(self)) if isinstance(loc, slice): return loc mask = np.empty(len(self), dtype='bool') mask.fill(False) mask[loc] = True return mask if not isinstance(key, tuple): loc = self._get_level_indexer(key, level=0) return _maybe_to_slice(loc) keylen = len(key) if self.nlevels < keylen: raise KeyError('Key length ({0}) exceeds index depth ({1})' ''.format(keylen, self.nlevels)) if keylen == self.nlevels and self.is_unique: return self._engine.get_loc(key) i = self.lexsort_depth lead_key, follow_key = key[:i], key[i:] start, stop = (self.slice_locs(lead_key, lead_key) if lead_key else (0, len(self))) if start == stop: raise KeyError(key) if not follow_key: return slice(start, stop) warnings.warn('indexing past lexsort depth may impact performance.', PerformanceWarning, stacklevel=10) loc = np.arange(start, stop, dtype='int64') for i, k in enumerate(follow_key, len(lead_key)): mask = self.codes[i][loc] == self.levels[i].get_loc(k) if not mask.all(): loc = loc[mask] if not len(loc): raise KeyError(key) return (_maybe_to_slice(loc) if len(loc) != stop - start else slice(start, stop))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'union'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'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': 'sort'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '24', '35', '52', '70']},{'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': '_validate_sort_keyword'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '17', 'type': 'expression_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': '_assert_can_do_setop'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'result_names'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_convert_can_do_setop'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '35', 'type': 'if_statement', 'children': ['36', '49']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '43'], 'value': 'or'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '42'], 'value': '=='},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'equals'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'uniq_tuples'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'fast_unique_multiple'},{'id': '59', 'type': 'argument_list', 'children': ['60', '67']},{'id': '60', 'type': 'list', 'children': ['61', '64'], 'value': '[self._ndarray_values,\n other._ndarray_values]'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_ndarray_values'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_ndarray_values'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'from_arrays'},{'id': '75', 'type': 'argument_list', 'children': ['76', '81', '84']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'lzip'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'list_splat', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'uniq_tuples'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'result_names'}
def union(self, other, sort=None): self._validate_sort_keyword(sort) self._assert_can_do_setop(other) other, result_names = self._convert_can_do_setop(other) if len(other) == 0 or self.equals(other): return self uniq_tuples = lib.fast_unique_multiple([self._ndarray_values, other._ndarray_values], sort=sort) return MultiIndex.from_arrays(lzip(*uniq_tuples), sortorder=0, names=result_names)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersection'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'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': 'sort'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '24', '35', '45', '51', '57', '69', '81']},{'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': '_validate_sort_keyword'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '17', 'type': 'expression_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': '_assert_can_do_setop'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'result_names'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_convert_can_do_setop'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '35', 'type': 'if_statement', 'children': ['36', '42']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self_tuples'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_ndarray_values'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'other_tuples'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_ndarray_values'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'uniq_tuples'},{'id': '60', 'type': 'binary_operator', 'children': ['61', '65'], 'value': '&'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self_tuples'},{'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': 'other_tuples'},{'id': '69', 'type': 'if_statement', 'children': ['70', '73']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '72', 'type': 'None', 'children': []},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'uniq_tuples'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'uniq_tuples'},{'id': '81', 'type': 'if_statement', 'children': ['82', '88', '112']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '87'], 'value': '=='},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'uniq_tuples'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '92', 'type': 'argument_list', 'children': ['93', '98', '106', '109']},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '100', 'type': 'binary_operator', 'children': ['101', '103'], 'value': '*'},{'id': '101', 'type': 'list', 'children': ['102'], 'value': '[[]]'},{'id': '102', 'type': 'list', 'children': [], 'value': '[]'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'nlevels'},{'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'result_names'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '111', 'type': 'False', 'children': []},{'id': '112', 'type': 'else_clause', 'children': ['113']},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'from_arrays'},{'id': '119', 'type': 'argument_list', 'children': ['120', '125', '128']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'lzip'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'list_splat', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'uniq_tuples'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'result_names'}
def intersection(self, other, sort=False): self._validate_sort_keyword(sort) self._assert_can_do_setop(other) other, result_names = self._convert_can_do_setop(other) if self.equals(other): return self self_tuples = self._ndarray_values other_tuples = other._ndarray_values uniq_tuples = set(self_tuples) & set(other_tuples) if sort is None: uniq_tuples = sorted(uniq_tuples) if len(uniq_tuples) == 0: return MultiIndex(levels=self.levels, codes=[[]] * self.nlevels, names=result_names, verify_integrity=False) else: return MultiIndex.from_arrays(lzip(*uniq_tuples), sortorder=0, names=result_names)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'difference'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'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': 'sort'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '24', '35', '45', '76', '84', '93', '112', '132', '143', '155']},{'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': '_validate_sort_keyword'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '17', 'type': 'expression_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': '_assert_can_do_setop'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'result_names'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_convert_can_do_setop'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '35', 'type': 'if_statement', 'children': ['36', '42']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '41'], 'value': '=='},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'if_statement', 'children': ['46', '52']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '56', 'type': 'argument_list', 'children': ['57', '62', '70', '73']},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '64', 'type': 'binary_operator', 'children': ['65', '67'], 'value': '*'},{'id': '65', 'type': 'list', 'children': ['66'], 'value': '[[]]'},{'id': '66', 'type': 'list', 'children': [], 'value': '[]'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'nlevels'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'result_names'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '75', 'type': 'False', 'children': []},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_get_unique_index'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_indexer'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '111']},{'id': '102', 'type': 'call', 'children': ['103', '110']},{'id': '103', 'type': 'attribute', 'children': ['104', '109']},{'id': '104', 'type': '()', 'children': ['105']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '!='},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '107', 'type': 'unary_operator', 'children': ['108'], 'value': '-'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'nonzero'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'label_diff'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'setdiff1d'},{'id': '119', 'type': 'argument_list', 'children': ['120', '128', '129']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'assume_unique'},{'id': '131', 'type': 'True', 'children': []},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '135', 'type': 'call', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'label_diff'},{'id': '143', 'type': 'if_statement', 'children': ['144', '147']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '146', 'type': 'None', 'children': []},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '155', 'type': 'if_statement', 'children': ['156', '162', '189']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '161'], 'value': '=='},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'return_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '166', 'type': 'argument_list', 'children': ['167', '175', '183', '186']},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '169', 'type': 'binary_operator', 'children': ['170', '172'], 'value': '*'},{'id': '170', 'type': 'list', 'children': ['171'], 'value': '[[]]'},{'id': '171', 'type': 'list', 'children': [], 'value': '[]'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'nlevels'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '180'], 'value': '*'},{'id': '178', 'type': 'list', 'children': ['179'], 'value': '[[]]'},{'id': '179', 'type': 'list', 'children': [], 'value': '[]'},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'nlevels'},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'result_names'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '188', 'type': 'False', 'children': []},{'id': '189', 'type': 'else_clause', 'children': ['190']},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'return_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'from_tuples'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198', '201']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '200', 'type': 'integer', 'children': [], 'value': '0'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'result_names'}
def difference(self, other, sort=None): self._validate_sort_keyword(sort) self._assert_can_do_setop(other) other, result_names = self._convert_can_do_setop(other) if len(other) == 0: return self if self.equals(other): return MultiIndex(levels=self.levels, codes=[[]] * self.nlevels, names=result_names, verify_integrity=False) this = self._get_unique_index() indexer = this.get_indexer(other) indexer = indexer.take((indexer != -1).nonzero()[0]) label_diff = np.setdiff1d(np.arange(this.size), indexer, assume_unique=True) difference = this.values.take(label_diff) if sort is None: difference = sorted(difference) if len(difference) == 0: return MultiIndex(levels=[[]] * self.nlevels, codes=[[]] * self.nlevels, names=result_names, verify_integrity=False) else: return MultiIndex.from_tuples(difference, sortorder=0, names=result_names)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '5', 'type': 'block', 'children': ['6', '13', '25', '29', '41', '51', '60', '69']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_ensure_arraylike'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '13', 'type': 'if_statement', 'children': ['14', '18']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'is_extension_array_dtype'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'original'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '37']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33', '34', '35', '36']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'htable'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ndtype'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_get_hashtable_algo'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'htable'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'uniques'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'uniques'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_reconstruct_data'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'uniques'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'original'},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'uniques'}
def unique(values): values = _ensure_arraylike(values) if is_extension_array_dtype(values): return values.unique() original = values htable, _, values, dtype, ndtype = _get_hashtable_algo(values) table = htable(len(values)) uniques = table.unique(values) uniques = _reconstruct_data(uniques, dtype, original) return uniques
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'value_counts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dropna'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '30', '39', '243', '257', '273']},{'id': '21', 'type': 'import_from_statement', 'children': ['22', '26', '28']},{'id': '22', 'type': 'dotted_name', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '26', 'type': 'dotted_name', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '28', 'type': 'dotted_name', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '37', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'if_statement', 'children': ['40', '43', '162']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'block', 'children': ['44', '80', '91', '103', '116', '124', '149']},{'id': '44', 'type': 'try_statement', 'children': ['45', '72']},{'id': '45', 'type': 'block', 'children': ['46', '54', '61']},{'id': '46', 'type': 'import_from_statement', 'children': ['47', '52']},{'id': '47', 'type': 'dotted_name', 'children': ['48', '49', '50', '51']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '52', 'type': 'dotted_name', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cut'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cut'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'include_lowest'},{'id': '71', 'type': 'True', 'children': []},{'id': '72', 'type': 'except_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'raise_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': '"bins argument only works with numeric data."'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'value_counts'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'dropna'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dropna'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '96', 'type': 'call', 'children': ['97', '102']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'notna'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'index'},{'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': 'result'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'string', 'children': [], 'value': "'interval'"},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'if_statement', 'children': ['125', '137']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '127'], 'value': 'and'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'dropna'},{'id': '127', 'type': 'call', 'children': ['128', '136']},{'id': '128', 'type': 'attribute', 'children': ['129', '135']},{'id': '129', 'type': '()', 'children': ['130']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': '=='},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '141', 'type': 'subscript', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '145', 'type': 'slice', 'children': ['146', '147', '148']},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'colon', 'children': []},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'list', 'children': ['158'], 'value': '[len(ii)]'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '162', 'type': 'else_clause', 'children': ['163']},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'if_statement', 'children': ['165', '174', '203']},{'id': '165', 'type': 'boolean_operator', 'children': ['166', '170'], 'value': 'or'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'is_extension_array_dtype'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'is_sparse'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '174', 'type': 'block', 'children': ['175', '191', '197']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '178', 'type': 'call', 'children': ['179', '187']},{'id': '179', 'type': 'attribute', 'children': ['180', '186']},{'id': '180', 'type': 'attribute', 'children': ['181', '185']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_values'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'value_counts'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'dropna'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'dropna'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '203', 'type': 'else_clause', 'children': ['204']},{'id': '204', 'type': 'block', 'children': ['205', '215', '230']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'pattern_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_value_counts_arraylike'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'dropna'},{'id': '215', 'type': 'if_statement', 'children': ['216', '222']},{'id': '216', 'type': 'not_operator', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '240']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '243', 'type': 'if_statement', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '257', 'type': 'if_statement', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '/'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '272', 'type': 'argument_list', 'children': []},{'id': '273', 'type': 'return_statement', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'result'}
def value_counts(values, sort=True, ascending=False, normalize=False, bins=None, dropna=True): from pandas.core.series import Series, Index name = getattr(values, 'name', None) if bins is not None: try: from pandas.core.reshape.tile import cut values = Series(values) ii = cut(values, bins, include_lowest=True) except TypeError: raise TypeError("bins argument only works with numeric data.") result = ii.value_counts(dropna=dropna) result = result[result.index.notna()] result.index = result.index.astype('interval') result = result.sort_index() if dropna and (result.values == 0).all(): result = result.iloc[0:0] counts = np.array([len(ii)]) else: if is_extension_array_dtype(values) or is_sparse(values): result = Series(values)._values.value_counts(dropna=dropna) result.name = name counts = result.values else: keys, counts = _value_counts_arraylike(values, dropna) if not isinstance(keys, Index): keys = Index(keys) result = Series(counts, index=keys, name=name) if sort: result = result.sort_values(ascending=ascending) if normalize: result = result / float(counts.sum()) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_argsort_with_ascending'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '29', '38']},{'id': '8', 'type': 'if_statement', 'children': ['9', '17']},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '14'], 'value': 'or'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'is_integer'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '25']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '21', 'type': 'binary_operator', 'children': ['22', '24'], 'value': '+'},{'id': '22', 'type': 'tuple', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '28', 'type': 'True', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'validate_argsort_kind'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'max_fname_arg_count'},{'id': '37', 'type': 'integer', 'children': [], 'value': '3'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def validate_argsort_with_ascending(ascending, args, kwargs): if is_integer(ascending) or ascending is None: args = (ascending,) + args ascending = True validate_argsort_kind(args, kwargs, max_fname_arg_count=3) return ascending
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '44']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_asof'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '35', '38', '41']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'left_on'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'right_on'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'left_index'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'right_index'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'left_by'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'right_by'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'_x'"},{'id': '34', 'type': 'string', 'children': [], 'value': "'_y'"},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'allow_exact_matches'},{'id': '40', 'type': 'True', 'children': []},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '43', 'type': 'string', 'children': [], 'value': "'backward'"},{'id': '44', 'type': 'block', 'children': ['45', '92']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_AsOfMerge'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53', '56', '59', '62', '65', '68', '71', '74', '77', '80', '83', '86', '89']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'left_on'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'left_on'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'right_on'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'right_on'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'left_index'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'left_index'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'right_index'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'right_index'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'left_by'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'left_by'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'right_by'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'right_by'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '82', 'type': 'string', 'children': [], 'value': "'asof'"},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'allow_exact_matches'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'allow_exact_matches'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'get_result'},{'id': '97', 'type': 'argument_list', 'children': []}
def merge_asof(left, right, on=None, left_on=None, right_on=None, left_index=False, right_index=False, by=None, left_by=None, right_by=None, suffixes=('_x', '_y'), tolerance=None, allow_exact_matches=True, direction='backward'): op = _AsOfMerge(left, right, on=on, left_on=left_on, right_on=right_on, left_index=left_index, right_index=right_index, by=by, left_by=left_by, right_by=right_by, suffixes=suffixes, how='asof', tolerance=tolerance, allow_exact_matches=allow_exact_matches, direction=direction) return op.get_result()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_classes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '6', 'type': 'block', 'children': ['7', '9', '15', '31', '38', '44']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': '"Generate classes from `items` by taking the sorted unique values."'},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'classes'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'classes'}
def generate_classes(self, items): "Generate classes from `items` by taking the sorted unique values." classes = set() for c in items: classes = classes.union(set(c)) classes = list(classes) classes.sort() return classes
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'most_confused'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '9']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_val'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '9', 'type': 'integer', 'children': [], 'value': '1'},{'id': '10', 'type': 'typed_default_parameter', 'children': ['11', '12', '14']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'generic_type', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Collection'},{'id': '18', 'type': 'type_parameter', 'children': ['19']},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'generic_type', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '22', 'type': 'type_parameter', 'children': ['23', '25', '27']},{'id': '23', 'type': 'type', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '25', 'type': 'type', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '27', 'type': 'type', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '29', 'type': 'block', 'children': ['30', '32', '43', '51', '90']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"Sorted descending list of largest non-diagonal entries of confusion matrix, presented as actual, predicted, number of occurrences."'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cm'},{'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': 'confusion_matrix'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fill_diagonal'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '74']},{'id': '55', 'type': 'tuple', 'children': ['56', '63', '70']},{'id': '56', 'type': 'subscript', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'subscript', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '70', 'type': 'subscript', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '74', 'type': 'for_in_clause', 'children': ['75', '78']},{'id': '75', 'type': 'pattern_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'list_splat', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '>='},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'min_val'},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95', '101']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'integer', 'children': [], 'value': '2'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '103', 'type': 'True', 'children': []}
def most_confused(self, min_val:int=1, slice_size:int=1)->Collection[Tuple[str,str,int]]: "Sorted descending list of largest non-diagonal entries of confusion matrix, presented as actual, predicted, number of occurrences." cm = self.confusion_matrix(slice_size=slice_size) np.fill_diagonal(cm, 0) res = [(self.data.classes[i],self.data.classes[j],cm[i,j]) for i,j in zip(*np.where(cm>=min_val))] return sorted(res, key=itemgetter(2), reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_toplosses_idxs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'learn'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n_imgs'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '12', '20', '33', '52', '64']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': '"Sorts `ds_type` dataset by top losses and returns dataset and sorted indices."'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dl'},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'learn'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'fix_dl'},{'id': '20', 'type': 'if_statement', 'children': ['21', '23']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'n_imgs'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'n_imgs'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dl'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '39']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'top_losses'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'learn'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'get_preds'},{'id': '43', 'type': 'argument_list', 'children': ['44', '49']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ds_type'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'DatasetType'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'Fix'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'with_loss'},{'id': '51', 'type': 'True', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '55', 'type': 'subscript', 'children': ['56', '63']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'topk'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'top_losses'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'n_imgs'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'expression_list', 'children': ['66', '76']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'padded_ds'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dl'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '74', 'type': 'dictionary_splat', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'idxs'}
def get_toplosses_idxs(cls, learn, n_imgs, **kwargs): "Sorts `ds_type` dataset by top losses and returns dataset and sorted indices." dl = learn.data.fix_dl if not n_imgs: n_imgs = len(dl.dataset) _,_,top_losses = learn.get_preds(ds_type=DatasetType.Fix, with_loss=True) idxs = torch.topk(top_losses, n_imgs)[1] return cls.padded_ds(dl.dataset, **kwargs), idxs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_idxs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'similarities'},{'id': '6', 'type': 'block', 'children': ['7', '9', '22', '48']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': '"Sorts `similarities` and return the indexes in pairs ordered by highest similarity."'},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'largest_indices'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'similarities'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'similarities'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '25', 'type': 'list_comprehension', 'children': ['26', '37']},{'id': '26', 'type': 'tuple', 'children': ['27', '32']},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'subscript', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '41', 'type': 'argument_list', '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': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '51', '54']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'l'}
def sort_idxs(cls, similarities): "Sorts `similarities` and return the indexes in pairs ordered by highest similarity." idxs = cls.largest_indices(similarities, len(similarities)) idxs = [(idxs[0][i], idxs[1][i]) for i in range(len(idxs[0]))] return [e for l in idxs for e in l]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'uniqueify'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '15', 'type': 'block', 'children': ['16', '18', '34', '43']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Return sorted unique values of `x`."'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '33']},{'id': '25', 'type': 'attribute', 'children': ['26', '32']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'fromkeys'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'res'}
def uniqueify(x:Series, sort:bool=False)->List: "Return sorted unique values of `x`." res = list(OrderedDict.fromkeys(x).keys()) if sort: res.sort() return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_imported_modules'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cells'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'nb_module_name'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'block', 'children': ['9', '11', '17', '46', '55', '78', '86', '100']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '"Finds all submodules of notebook - sorted by submodules > top level modules > manual imports. This gives notebook imports priority"'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'module_names'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_top_level_modules'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'nb_imports'},{'id': '20', 'type': 'list_comprehension', 'children': ['21', '27', '30', '40']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cell'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cells'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'IMPORT_RE'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cell'},{'id': '39', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '40', 'type': 'if_clause', 'children': ['41']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': '=='},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'cell'},{'id': '44', 'type': 'string', 'children': [], 'value': "'cell_type'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'nb_module_name'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'parent_modules'},{'id': '58', 'type': 'list_comprehension', 'children': ['59', '72']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '66', 'type': 'slice', 'children': ['67', '68']},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': '()', 'children': ['69']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'range_of'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'all_modules'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '85'], 'value': '+'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '+'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'module_names'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'nb_imports'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'parent_modules'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '89', 'type': 'list_comprehension', 'children': ['90', '97']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'import_mod'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'},{'id': '96', 'type': 'True', 'children': []},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'all_modules'},{'id': '100', 'type': 'return_statement', 'children': ['101']},{'id': '101', 'type': 'list_comprehension', 'children': ['102', '103', '106']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '106', 'type': 'if_clause', 'children': ['107']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '109', 'type': 'None', 'children': []}
def get_imported_modules(cells, nb_module_name=''): "Finds all submodules of notebook - sorted by submodules > top level modules > manual imports. This gives notebook imports priority" module_names = get_top_level_modules() nb_imports = [match.group(1) for cell in cells for match in IMPORT_RE.finditer(cell['source']) if cell['cell_type'] == 'code'] parts = nb_module_name.split('.') parent_modules = ['.'.join(parts[:(x+1)]) for x in range_of(parts)] all_modules = module_names + nb_imports + parent_modules mods = [import_mod(m, ignore_errors=True) for m in all_modules] return [m for m in mods if m is not None]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'numericalize_tok'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_vocab'},{'id': '7', 'type': 'integer', 'children': [], 'value': '50000'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'min_freq'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'unk_tok'},{'id': '13', 'type': 'string', 'children': [], 'value': '"_unk_"'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'pad_tok'},{'id': '16', 'type': 'string', 'children': [], 'value': '"_pad_"'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'bos_tok'},{'id': '19', 'type': 'string', 'children': [], 'value': '"_bos_"'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'eos_tok'},{'id': '22', 'type': 'string', 'children': [], 'value': '"_eos_"'},{'id': '23', 'type': 'block', 'children': ['24', '36', '56', '63', '82', '86', '94', '102', '110', '118', '140']},{'id': '24', 'type': 'if_statement', 'children': ['25', '30']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 'string', 'children': [], 'value': '"Expected to receive a list of tokens. Received a string instead"'},{'id': '36', 'type': 'if_statement', 'children': ['37', '44']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '48', 'type': 'list_comprehension', 'children': ['49', '50', '53']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'int2tok'},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '68', '78']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '72']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'max_vocab'},{'id': '78', 'type': 'if_clause', 'children': ['79']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '>'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'min_freq'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'unk_id'},{'id': '85', 'type': 'integer', 'children': [], 'value': '3'},{'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': 'int2tok'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'bos_tok'},{'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': 'int2tok'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pad_tok'},{'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': 'int2tok'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'integer', 'children': [], 'value': '2'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'eos_tok'},{'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': 'int2tok'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'unk_id'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'unk_tok'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'tok2int'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '125', 'type': 'argument_list', 'children': ['126', '128']},{'id': '126', 'type': 'lambda', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'unk_id'},{'id': '128', 'type': 'dictionary_comprehension', 'children': ['129', '132']},{'id': '129', 'type': 'pair', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '132', 'type': 'for_in_clause', 'children': ['133', '136']},{'id': '133', 'type': 'pattern_list', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'int2tok'},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'expression_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'int2tok'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'tok2int'}
def numericalize_tok(tokens, max_vocab=50000, min_freq=0, unk_tok="_unk_", pad_tok="_pad_", bos_tok="_bos_", eos_tok="_eos_"): if isinstance(tokens, str): raise ValueError("Expected to receive a list of tokens. Received a string instead") if isinstance(tokens[0], list): tokens = [p for o in tokens for p in o] freq = Counter(tokens) int2tok = [o for o,c in freq.most_common(max_vocab) if c>min_freq] unk_id = 3 int2tok.insert(0, bos_tok) int2tok.insert(1, pad_tok) int2tok.insert(2, eos_tok) int2tok.insert(unk_id, unk_tok) tok2int = collections.defaultdict(lambda:unk_id, {v:k for k,v in enumerate(int2tok)}) return int2tok, tok2int
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_freq_tuples'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'my_list'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'print_total_threshold'},{'id': '6', 'type': 'block', 'children': ['7', '11', '29']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'my_list'},{'id': '14', 'type': 'block', 'children': ['15', '23']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'augmented_assignment', 'children': ['25', '28'], 'value': '+='},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'subscript', 'children': ['31', '50']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '33', 'type': 'argument_list', 'children': ['34', '39', '47']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '49', 'type': 'True', 'children': []},{'id': '50', 'type': 'slice', 'children': ['51', '52']},{'id': '51', 'type': 'colon', 'children': []},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'print_total_threshold'}
def get_freq_tuples(my_list, print_total_threshold): d = {} for token in my_list: d.setdefault(token, 0) d[token] += 1 return sorted(d.items(), key=operator.itemgetter(1), reverse=True)[:print_total_threshold]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_levels'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'arcs'},{'id': '6', 'type': 'block', 'children': ['7', '27']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '15', 'type': 'argument_list', 'children': ['16', '26']},{'id': '16', 'type': 'lambda', 'children': ['17', '19']},{'id': '17', 'type': 'lambda_parameters', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'arc'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '23'], 'value': '-'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'arc'},{'id': '22', 'type': 'string', 'children': [], 'value': '"end"'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'arc'},{'id': '25', 'type': 'string', 'children': [], 'value': '"start"'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'arcs'},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'levels'}
def get_levels(self, arcs): levels = set(map(lambda arc: arc["end"] - arc["start"], arcs)) return sorted(list(levels))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'organize_commands'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'corrected_commands'},{'id': '5', 'type': 'block', 'children': ['6', '22', '45', '60', '88']},{'id': '6', 'type': 'try_statement', 'children': ['7', '18']},{'id': '7', 'type': 'block', 'children': ['8', '15']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'first_command'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'corrected_commands'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'yield', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'first_command'},{'id': '18', 'type': 'except_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'without_duplicates'},{'id': '25', 'type': 'set_comprehension', 'children': ['26', '27', '41']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'corrected_commands'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'lambda', 'children': ['36', '38']},{'id': '36', 'type': 'lambda_parameters', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '41', 'type': 'if_clause', 'children': ['42']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '!='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'first_command'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted_commands'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'without_duplicates'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'lambda', 'children': ['55', '57']},{'id': '55', 'type': 'lambda_parameters', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'corrected_command'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'corrected_command'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'logs'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'Corrected commands: '"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "', '"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '75', 'type': 'generator_expression', 'children': ['76', '82']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "u'{}'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '87'], 'value': '+'},{'id': '85', 'type': 'list', 'children': ['86'], 'value': '[first_command]'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'first_command'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sorted_commands'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted_commands'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'yield', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'command'}
def organize_commands(corrected_commands): try: first_command = next(corrected_commands) yield first_command except StopIteration: return without_duplicates = { command for command in sorted( corrected_commands, key=lambda command: command.priority) if command != first_command} sorted_commands = sorted( without_duplicates, key=lambda corrected_command: corrected_command.priority) logs.debug('Corrected commands: '.format( ', '.join(u'{}'.format(cmd) for cmd in [first_command] + sorted_commands))) for command in sorted_commands: yield command
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_corrected_commands'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '5', 'type': 'block', 'children': ['6', '31']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'corrected_commands'},{'id': '9', 'type': 'generator_expression', 'children': ['10', '11', '16', '23']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'corrected'},{'id': '11', 'type': 'for_in_clause', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_rules'},{'id': '15', 'type': 'argument_list', 'children': []},{'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': 'rule'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'is_match'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'corrected'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_corrected_commands'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'organize_commands'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'corrected_commands'}
def get_corrected_commands(command): corrected_commands = ( corrected for rule in get_rules() if rule.is_match(command) for corrected in rule.get_corrected_commands(command)) return organize_commands(corrected_commands)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_partition_query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '28', '32', '68', '72', '107', '116']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'limit_clause'},{'id': '19', 'type': 'conditional_expression', 'children': ['20', '26', '27'], 'value': 'if'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'LIMIT {}'"},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '27', 'type': 'string', 'children': [], 'value': "''"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'order_by_clause'},{'id': '31', 'type': 'string', 'children': [], 'value': "''"},{'id': '32', 'type': 'if_statement', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '34', 'type': 'block', 'children': ['35', '39', '57']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '38', 'type': 'list', 'children': [], 'value': '[]'},{'id': '39', 'type': 'for_statement', 'children': ['40', '43', '44']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'conditional_expression', 'children': ['52', '55', '56'], 'value': 'if'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '+'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '54', 'type': 'string', 'children': [], 'value': "' DESC'"},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '56', 'type': 'string', 'children': [], 'value': "''"},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'order_by_clause'},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'},{'id': '61', 'type': 'string', 'children': [], 'value': "'ORDER BY '"},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "', '"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'where_clause'},{'id': '71', 'type': 'string', 'children': [], 'value': "''"},{'id': '72', 'type': 'if_statement', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '74', 'type': 'block', 'children': ['75', '79', '96']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '78', 'type': 'list', 'children': [], 'value': '[]'},{'id': '79', 'type': 'for_statement', 'children': ['80', '83', '88']},{'id': '80', 'type': 'pattern_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': 'f"{field} = \'{value}\'"'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'where_clause'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'},{'id': '100', 'type': 'string', 'children': [], 'value': "'WHERE '"},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "' AND '"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'textwrap'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dedent'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sql'}
def _partition_query( cls, table_name, limit=0, order_by=None, filters=None): limit_clause = 'LIMIT {}'.format(limit) if limit else '' order_by_clause = '' if order_by: l = [] for field, desc in order_by: l.append(field + ' DESC' if desc else '') order_by_clause = 'ORDER BY ' + ', '.join(l) where_clause = '' if filters: l = [] for field, value in filters.items(): l.append(f"{field} = '{value}'") where_clause = 'WHERE ' + ' AND '.join(l) sql = textwrap.dedent(f ) return sql
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cocktail_shaker_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '5', 'type': 'block', 'children': ['6', '28', '35', '39', '123']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'swap'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '21']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '18']},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '21', 'type': 'expression_list', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'n'},{'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': 'arr'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'swapped'},{'id': '38', 'type': 'True', 'children': []},{'id': '39', 'type': 'while_statement', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'swapped'},{'id': '41', 'type': 'block', 'children': ['42', '46', '77', '84', '88']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'swapped'},{'id': '45', 'type': 'False', 'children': []},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '53']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'if_statement', 'children': ['55', '64']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '61'], 'value': '>'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '-'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'block', 'children': ['65', '73']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'swap'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '-'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'swapped'},{'id': '76', 'type': 'True', 'children': []},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '=='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'swapped'},{'id': '80', 'type': 'False', 'children': []},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'swapped'},{'id': '87', 'type': 'False', 'children': []},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '99']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '92', 'type': 'argument_list', 'children': ['93', '96', '97']},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '-'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'unary_operator', 'children': ['98'], 'value': '-'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '110']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '107'], 'value': '>'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '-'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '110', 'type': 'block', 'children': ['111', '119']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'swap'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118']},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '-'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'swapped'},{'id': '122', 'type': 'True', 'children': []},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'arr'}
def cocktail_shaker_sort(arr): def swap(i, j): arr[i], arr[j] = arr[j], arr[i] n = len(arr) swapped = True while swapped: swapped = False for i in range(1, n): if arr[i - 1] > arr[i]: swap(i - 1, i) swapped = True if swapped == False: return arr swapped = False for i in range(n-1,0,-1): if arr[i - 1] > arr[i]: swap(i - 1, i) swapped = True return arr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'max_heapify'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'simulation'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '8', 'type': 'block', 'children': ['9', '18', '119', '135']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'last_parent'},{'id': '12', 'type': 'binary_operator', 'children': ['13', '17'], 'value': '//'},{'id': '13', 'type': '()', 'children': ['14']},{'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '-'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '16', 'type': 'integer', 'children': [], 'value': '1'},{'id': '17', 'type': 'integer', 'children': [], 'value': '2'},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '28']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24', '26']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'last_parent'},{'id': '24', 'type': 'unary_operator', 'children': ['25'], 'value': '-'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'unary_operator', 'children': ['27'], 'value': '-'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'block', 'children': ['29', '33']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '33', 'type': 'while_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'last_parent'},{'id': '37', 'type': 'block', 'children': ['38', '46', '69']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '45'], 'value': '+'},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '*'},{'id': '43', 'type': 'integer', 'children': [], 'value': '2'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'if_statement', 'children': ['47', '62']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '53'], 'value': 'and'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '52'], 'value': '<='},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': '<'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'if_statement', 'children': ['70', '77', '116']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': '>'},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '77', 'type': 'block', 'children': ['78', '94', '98']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '87']},{'id': '80', 'type': 'pattern_list', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '87', 'type': 'expression_list', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '98', 'type': 'if_statement', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'simulation'},{'id': '100', 'type': 'block', 'children': ['101', '107']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '+'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112', '113', '114']},{'id': '111', 'type': 'string', 'children': [], 'value': '"iteration"'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '113', 'type': 'string', 'children': [], 'value': '":"'},{'id': '114', 'type': 'list_splat', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '116', 'type': 'else_clause', 'children': ['117']},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'break_statement', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '128']},{'id': '121', 'type': 'pattern_list', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '128', 'type': 'expression_list', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'iteration'}
def max_heapify(arr, end, simulation, iteration): last_parent = (end - 1) // 2 for parent in range(last_parent, -1, -1): current_parent = parent while current_parent <= last_parent: child = 2 * current_parent + 1 if child + 1 <= end and arr[child] < arr[child + 1]: child = child + 1 if arr[child] > arr[current_parent]: arr[current_parent], arr[child] = arr[child], arr[current_parent] current_parent = child if simulation: iteration = iteration + 1 print("iteration",iteration,":",*arr) else: break arr[0], arr[end] = arr[end], arr[0] return iteration
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'min_heapify'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'simulation'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '8', 'type': 'block', 'children': ['9', '18', '29', '149']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '12', 'type': 'binary_operator', 'children': ['13', '17'], 'value': '-'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'last_parent'},{'id': '21', 'type': 'binary_operator', 'children': ['22', '28'], 'value': '//'},{'id': '22', 'type': '()', 'children': ['23']},{'id': '23', 'type': 'binary_operator', 'children': ['24', '27'], 'value': '-'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '-'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'integer', 'children': [], 'value': '2'},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '39']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35', '37']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'last_parent'},{'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'block', 'children': ['40', '44']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '44', 'type': 'while_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<='},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'last_parent'},{'id': '48', 'type': 'block', 'children': ['49', '57', '86']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '56'], 'value': '+'},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '*'},{'id': '54', 'type': 'integer', 'children': [], 'value': '2'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'if_statement', 'children': ['58', '79']},{'id': '58', 'type': 'boolean_operator', 'children': ['59', '66'], 'value': 'and'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '<='},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '-'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '72'], 'value': '>'},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '78'], 'value': '+'},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'if_statement', 'children': ['87', '98', '146']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '93'], 'value': '<'},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '+'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '98', 'type': 'block', 'children': ['99', '124', '128']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '112', '113']},{'id': '101', 'type': 'pattern_list', 'children': ['102', '107']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '+'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '+'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '112', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '113', 'type': 'expression_list', 'children': ['114', '119']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '+'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '+'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'current_parent'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '128', 'type': 'if_statement', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'simulation'},{'id': '130', 'type': 'block', 'children': ['131', '137']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '+'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143', '144']},{'id': '141', 'type': 'string', 'children': [], 'value': '"iteration"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '143', 'type': 'string', 'children': [], 'value': '":"'},{'id': '144', 'type': 'list_splat', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'break_statement', 'children': []},{'id': '149', 'type': 'return_statement', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'iteration'}
def min_heapify(arr, start, simulation, iteration): end = len(arr) - 1 last_parent = (end - start - 1) // 2 for parent in range(last_parent, -1, -1): current_parent = parent while current_parent <= last_parent: child = 2 * current_parent + 1 if child + 1 <= end - start and arr[child + start] > arr[ child + 1 + start]: child = child + 1 if arr[child + start] < arr[current_parent + start]: arr[current_parent + start], arr[child + start] = \ arr[child + start], arr[current_parent + start] current_parent = child if simulation: iteration = iteration + 1 print("iteration",iteration,":",*arr) else: break return iteration
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pancake_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '96']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'len_arr'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '<='},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'len_arr'},{'id': '16', 'type': 'integer', 'children': [], 'value': '1'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '32']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '24', 'type': 'argument_list', 'children': ['25', '29', '30']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'unary_operator', 'children': ['31'], 'value': '-'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'block', 'children': ['33', '50']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'index_max'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '46', 'type': 'slice', 'children': ['47', '48', '49']},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'colon', 'children': []},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '50', 'type': 'if_statement', 'children': ['51', '56']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '!='},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '+'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'index_max'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '56', 'type': 'block', 'children': ['57', '81']},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '!='},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'index_max'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '71']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '66', 'type': 'slice', 'children': ['67', '68']},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '+'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'index_max'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '76', 'type': 'slice', 'children': ['77', '78']},{'id': '77', 'type': 'colon', 'children': []},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '+'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'index_max'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '88']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '85', 'type': 'slice', 'children': ['86', '87']},{'id': '86', 'type': 'colon', 'children': []},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '93', 'type': 'slice', 'children': ['94', '95']},{'id': '94', 'type': 'colon', 'children': []},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'arr'}
def pancake_sort(arr): len_arr = len(arr) if len_arr <= 1: return arr for cur in range(len(arr), 1, -1): index_max = arr.index(max(arr[0:cur])) if index_max+1 != cur: if index_max != 0: arr[:index_max+1] = reversed(arr[:index_max+1]) arr[:cur] = reversed(arr[:cur]) return arr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'natural_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'lambda', 'children': ['8', '10']},{'id': '8', 'type': 'lambda_parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '11', 'type': 'block', 'children': ['12', '55', '62']},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']},{'id': '13', 'type': 'function_name', 'children': [], 'value': 'get_alphanum_key_func'},{'id': '14', 'type': 'parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '16', 'type': 'block', 'children': ['17', '34']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '20', 'type': 'lambda', 'children': ['21', '23']},{'id': '21', 'type': 'lambda_parameters', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '23', 'type': 'conditional_expression', 'children': ['24', '28', '33'], 'value': 'if'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'lambda', 'children': ['36', '38']},{'id': '36', 'type': 'lambda_parameters', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '38', 'type': 'list_comprehension', 'children': ['39', '43']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'([0-9]+)'"},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_alphanum_key_func'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort_key'}
def natural_sort(list, key=lambda s:s): def get_alphanum_key_func(key): convert = lambda text: int(text) if text.isdigit() else text return lambda s: [convert(c) for c in re.split('([0-9]+)', key(s))] sort_key = get_alphanum_key_func(key) list.sort(key=sort_key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_vocab'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'vocab_path'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'vocab_size'},{'id': '7', 'type': 'block', 'children': ['8', '15', '24', '48', '61', '69']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_read_words'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'count_pairs'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '29', 'type': 'argument_list', 'children': ['30', '35']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'lambda', 'children': ['38', '40']},{'id': '38', 'type': 'lambda_parameters', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'tuple', 'children': ['41', '45']},{'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'list_splat', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'count_pairs'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '66', 'type': 'slice', 'children': ['67', '68']},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'vocab_size'},{'id': '69', 'type': 'with_statement', 'children': ['70', '80']},{'id': '70', 'type': 'with_clause', 'children': ['71']},{'id': '71', 'type': 'with_item', 'children': ['72']},{'id': '72', 'type': 'as_pattern', 'children': ['73', '78']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'vocab_path'},{'id': '77', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '78', 'type': 'as_pattern_target', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'f'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'words'}
def _build_vocab(filename, vocab_path, vocab_size): data = _read_words(filename) counter = collections.Counter(data) count_pairs = sorted(counter.items(), key=lambda x: (-x[1], x[0])) words, _ = list(zip(*count_pairs)) words = words[:vocab_size] with open(vocab_path, "w") as f: f.write("\n".join(words))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_read_stepfiles_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path_prefix'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'path_suffix'},{'id': '7', 'type': 'string', 'children': [], 'value': '".index"'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'min_steps'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'block', 'children': ['12', '16', '119']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'stepfiles'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '26']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_try_twice_tf_glob'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '25'], 'value': '+'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '+'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path_prefix'},{'id': '24', 'type': 'string', 'children': [], 'value': '"*-[0-9]*"'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'path_suffix'},{'id': '26', 'type': 'block', 'children': ['27', '42', '63', '69', '92']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '30', 'type': 'conditional_expression', 'children': ['31', '40', '41'], 'value': 'if'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '33', 'type': 'slice', 'children': ['34', '35']},{'id': '34', 'type': 'colon', 'children': []},{'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'path_suffix'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'path_suffix'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '42', 'type': 'try_statement', 'children': ['43', '59']},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '57']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '57', 'type': 'unary_operator', 'children': ['58'], 'value': '-'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'except_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'continue_statement', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '<'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'min_steps'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'continue_statement', 'children': []},{'id': '69', 'type': 'if_statement', 'children': ['70', '79']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '79', 'type': 'block', 'children': ['80', '91']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '90', 'type': 'string', 'children': [], 'value': '" was deleted, so skipping it"'},{'id': '91', 'type': 'continue_statement', 'children': []},{'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': 'stepfiles'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'StepFile'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102', '110', '118']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'getmtime'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'getctime'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'stepfiles'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '126', 'type': 'lambda', 'children': ['127', '129']},{'id': '127', 'type': 'lambda_parameters', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'unary_operator', 'children': ['130'], 'value': '-'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'steps'}
def _read_stepfiles_list(path_prefix, path_suffix=".index", min_steps=0): stepfiles = [] for filename in _try_twice_tf_glob(path_prefix + "*-[0-9]*" + path_suffix): basename = filename[:-len(path_suffix)] if path_suffix else filename try: steps = int(basename.rsplit("-")[-1]) except ValueError: continue if steps < min_steps: continue if not os.path.exists(filename): tf.logging.info(filename + " was deleted, so skipping it") continue stepfiles.append(StepFile(basename, os.path.getmtime(filename), os.path.getctime(filename), steps)) return sorted(stepfiles, key=lambda x: -x.steps)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'},{'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': 'indent'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '75']},{'id': '15', 'type': 'function_definition', 'children': ['16', '17', '19']},{'id': '16', 'type': 'function_name', 'children': [], 'value': 'remove_callables'},{'id': '17', 'type': 'parameters', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '19', 'type': 'block', 'children': ['20', '73']},{'id': '20', 'type': 'if_statement', 'children': ['21', '26', '51']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'dictionary_comprehension', 'children': ['29', '35', '45']},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'remove_callables'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'if_clause', 'children': ['46']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'elif_clause', 'children': ['52', '57']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '64', '67']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'remove_callables'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'if_clause', 'children': ['68']},{'id': '68', 'type': 'not_operator', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '80', 'type': 'argument_list', 'children': ['81', '89', '92', '95']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'remove_callables'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}
def to_json(self, indent=None, separators=None, sort_keys=False): def remove_callables(x): if isinstance(x, dict): return {k: remove_callables(v) for k, v in six.iteritems(x) if not callable(v)} elif isinstance(x, list): return [remove_callables(i) for i in x if not callable(i)] return x return json.dumps( remove_callables(self.values()), indent=indent, separators=separators, sort_keys=sort_keys)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_topk_unique'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '6', 'type': 'block', 'children': ['7', '15', '23', '40', '56', '62', '78', '82', '98', '204', '228', '234', '240', '249', '261', '273', '285']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'neg_inf_r0'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'constant'},{'id': '30', 'type': 'argument_list', 'children': ['31', '35']},{'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '-'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ones'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ones'},{'id': '47', 'type': 'argument_list', 'children': ['48', '51']},{'id': '48', 'type': 'list', 'children': ['49', '50'], 'value': '[height, width]'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'neg_inf_r2'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '*'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ones'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'neg_inf_r0'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '69', 'type': 'argument_list', 'children': ['70', '76', '77']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'is_nan'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'neg_inf_r2'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'topk_r2'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '89', 'type': 'argument_list', 'children': ['90', '93']},{'id': '90', 'type': 'list', 'children': ['91', '92'], 'value': '[height, k]'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '104']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '104', 'type': 'block', 'children': ['105', '120', '156', '175', '193']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'kth_order_statistic'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'reduce_max'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114', '117']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'keepdims'},{'id': '119', 'type': 'True', 'children': []},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'k_mask'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '127', 'type': 'argument_list', 'children': ['128', '153']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'expand_dims'},{'id': '132', 'type': 'argument_list', 'children': ['133', '152']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'equal'},{'id': '137', 'type': 'argument_list', 'children': ['138', '144']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'fill'},{'id': '148', 'type': 'argument_list', 'children': ['149', '151']},{'id': '149', 'type': 'list', 'children': ['150'], 'value': '[k]'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'list', 'children': ['154', '155'], 'value': '[height, 1]'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '155', 'type': 'integer', 'children': [], 'value': '1'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'topk_r2'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165', '174']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'k_mask'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'kth_order_statistic'},{'id': '171', 'type': 'list', 'children': ['172', '173'], 'value': '[1, k]'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'topk_r2'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ge_r2'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'greater_equal'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'kth_order_statistic'},{'id': '190', 'type': 'list', 'children': ['191', '192'], 'value': '[1, width]'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202', '203']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ge_r2'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'neg_inf_r2'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'log2_ceiling'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '219', 'type': 'argument_list', 'children': ['220', '227']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '227', 'type': 'integer', 'children': [], 'value': '2'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'next_power_of_two'},{'id': '231', 'type': 'binary_operator', 'children': ['232', '233'], 'value': '<<'},{'id': '232', 'type': 'integer', 'children': [], 'value': '1'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'log2_ceiling'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'count_mask'},{'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '-'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'next_power_of_two'},{'id': '239', 'type': 'integer', 'children': [], 'value': '1'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'mask_r0'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'constant'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'count_mask'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'mask_r2'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'fill'},{'id': '256', 'type': 'argument_list', 'children': ['257', '260']},{'id': '257', 'type': 'list', 'children': ['258', '259'], 'value': '[height, k]'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'mask_r0'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'topk_r2_s32'},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'bitcast'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'topk_r2'},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'topk_indices_r2'},{'id': '276', 'type': 'call', 'children': ['277', '282']},{'id': '277', 'type': 'attribute', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'bitwise'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'bitwise_and'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'topk_r2_s32'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'mask_r2'},{'id': '285', 'type': 'return_statement', 'children': ['286']},{'id': '286', 'type': 'expression_list', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'topk_r2'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'topk_indices_r2'}
def _create_topk_unique(inputs, k): height = inputs.shape[0] width = inputs.shape[1] neg_inf_r0 = tf.constant(-np.inf, dtype=tf.float32) ones = tf.ones([height, width], dtype=tf.float32) neg_inf_r2 = ones * neg_inf_r0 inputs = tf.where(tf.is_nan(inputs), neg_inf_r2, inputs) tmp = inputs topk_r2 = tf.zeros([height, k], dtype=tf.float32) for i in range(k): kth_order_statistic = tf.reduce_max(tmp, axis=1, keepdims=True) k_mask = tf.tile(tf.expand_dims(tf.equal(tf.range(k), tf.fill([k], i)), 0), [height, 1]) topk_r2 = tf.where(k_mask, tf.tile(kth_order_statistic, [1, k]), topk_r2) ge_r2 = tf.greater_equal(inputs, tf.tile(kth_order_statistic, [1, width])) tmp = tf.where(ge_r2, neg_inf_r2, inputs) log2_ceiling = int(math.ceil(math.log(float(int(width)), 2))) next_power_of_two = 1 << log2_ceiling count_mask = next_power_of_two - 1 mask_r0 = tf.constant(count_mask) mask_r2 = tf.fill([height, k], mask_r0) topk_r2_s32 = tf.bitcast(topk_r2, tf.int32) topk_indices_r2 = tf.bitwise.bitwise_and(topk_r2_s32, mask_r2) return topk_r2, topk_indices_r2
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'top_k_with_unique'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '6', 'type': 'block', 'children': ['7', '22', '32', '44']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'unique_inputs'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_create_make_unique'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'cast'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'top_values'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_create_topk_unique'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'unique_inputs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'top_values'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cast'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'top_values'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'expression_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'top_values'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'indices'}
def top_k_with_unique(inputs, k): unique_inputs = _create_make_unique(tf.cast(inputs, tf.float32)) top_values, indices = _create_topk_unique(unique_inputs, k) top_values = tf.cast(top_values, inputs.dtype) return top_values, indices
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_rowwise_unsorted_segment_sum'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '7', 'type': 'block', 'children': ['8', '27', '56', '77']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '13']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'unstack'},{'id': '17', 'type': 'argument_list', 'children': ['18', '24']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '26', 'type': 'integer', 'children': [], 'value': '2'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'indices_flat'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '40'], 'value': '+'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '37', 'type': 'list', 'children': ['38'], 'value': '[-1]'},{'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '55'], 'value': '*'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'div'},{'id': '45', 'type': 'argument_list', 'children': ['46', '54']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '*'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ret_flat'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'unsorted_segment_sum'},{'id': '63', 'type': 'argument_list', 'children': ['64', '73', '74']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '70', 'type': 'list', 'children': ['71'], 'value': '[-1]'},{'id': '71', 'type': 'unary_operator', 'children': ['72'], 'value': '-'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'indices_flat'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '*'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ret_flat'},{'id': '84', 'type': 'list', 'children': ['85', '86'], 'value': '[batch, n]'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'n'}
def _rowwise_unsorted_segment_sum(values, indices, n): batch, k = tf.unstack(tf.shape(indices), num=2) indices_flat = tf.reshape(indices, [-1]) + tf.div(tf.range(batch * k), k) * n ret_flat = tf.unsorted_segment_sum( tf.reshape(values, [-1]), indices_flat, batch * n) return tf.reshape(ret_flat, [batch, n])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_inputs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'delimiter'},{'id': '7', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '8', 'type': 'block', 'children': ['9', '18', '75', '98', '113', '117', '121', '147']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'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': 'logging'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Getting sorted inputs"'},{'id': '18', 'type': 'with_statement', 'children': ['19', '32']},{'id': '19', 'type': 'with_clause', 'children': ['20']},{'id': '20', 'type': 'with_item', 'children': ['21']},{'id': '21', 'type': 'as_pattern', 'children': ['22', '30']},{'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': 'tf'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'gfile'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Open'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '30', 'type': 'as_pattern_target', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '32', 'type': 'block', 'children': ['33', '41', '50', '62']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'delimiter'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '53', 'type': 'list_comprehension', 'children': ['54', '59']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '62', 'type': 'if_statement', 'children': ['63', '68']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '66', 'type': 'unary_operator', 'children': ['67'], 'value': '-'},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'input_lens'},{'id': '78', 'type': 'list_comprehension', 'children': ['79', '90']},{'id': '79', 'type': 'tuple', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '81', 'type': 'unary_operator', 'children': ['82'], 'value': '-'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '94']},{'id': '91', 'type': 'pattern_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted_input_lens'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'input_lens'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'},{'id': '116', 'type': 'dictionary', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'},{'id': '120', 'type': 'list', 'children': [], 'value': '[]'},{'id': '121', 'type': 'for_statement', 'children': ['122', '127', '131']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '124', 'type': 'tuple_pattern', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sorted_input_lens'},{'id': '131', 'type': 'block', 'children': ['132', '141']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'expression_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}
def _get_sorted_inputs(filename, delimiter="\n"): tf.logging.info("Getting sorted inputs") with tf.gfile.Open(filename) as f: text = f.read() records = text.split(delimiter) 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=operator.itemgetter(1)) sorted_keys = {} sorted_inputs = [] 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', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_batch_by_length'},{'id': '3', 'type': 'parameters', 'children': ['4', '10']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tensor'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Tensor'},{'id': '10', 'type': 'typed_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sequence_lengths'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Tensor'},{'id': '16', 'type': 'block', 'children': ['17', '41', '55', '65', '83', '97', '107']},{'id': '17', 'type': 'if_statement', 'children': ['18', '35']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '27'], 'value': 'or'},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tensor'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Tensor'},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sequence_lengths'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'Tensor'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'raise_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': '"Both the tensor and sequence lengths must be torch.Tensors."'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '46']},{'id': '43', 'type': 'pattern_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sorted_sequence_lengths'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'permutation_index'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sequence_lengths'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '54', 'type': 'True', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted_tensor'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'tensor'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'index_select'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'permutation_index'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'index_range'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74', '78']},{'id': '73', 'type': 'integer', 'children': [], 'value': '0'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sequence_lengths'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sequence_lengths'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '88']},{'id': '85', 'type': 'pattern_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'reverse_mapping'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'permutation_index'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'integer', 'children': [], 'value': '0'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '96', 'type': 'False', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'restoration_indices'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'index_range'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'index_select'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'reverse_mapping'},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'expression_list', 'children': ['109', '110', '111', '112']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sorted_tensor'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sorted_sequence_lengths'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'restoration_indices'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'permutation_index'}
def sort_batch_by_length(tensor: torch.Tensor, sequence_lengths: torch.Tensor): if not isinstance(tensor, torch.Tensor) or not isinstance(sequence_lengths, torch.Tensor): raise ConfigurationError("Both the tensor and sequence lengths must be torch.Tensors.") sorted_sequence_lengths, permutation_index = sequence_lengths.sort(0, descending=True) sorted_tensor = tensor.index_select(0, permutation_index) index_range = torch.arange(0, len(sequence_lengths), device=sequence_lengths.device) _, reverse_mapping = permutation_index.sort(0, descending=False) restoration_indices = index_range.index_select(0, reverse_mapping) return sorted_tensor, sorted_sequence_lengths, restoration_indices, permutation_index
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_config'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Config'},{'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'string', 'children': [], 'value': '""'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '15', 'type': 'block', 'children': ['16', '22']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'new_indent'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '+'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '21', 'type': 'string', 'children': [], 'value': '" "'},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': '""'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'list', 'children': ['29', '30', '36', '51', '52'], 'value': '[\n "{\\n",\n f\'{new_indent}"type": "{config.typ3}",\\n\' if config.typ3 else \'\',\n "".join(_render(item, new_indent) for item in config.items),\n indent,\n "}\\n"\n ]'},{'id': '29', 'type': 'string', 'children': [], 'value': '"{\\n"'},{'id': '30', 'type': 'conditional_expression', 'children': ['31', '32', '35'], 'value': 'if'},{'id': '31', 'type': 'string', 'children': [], 'value': 'f\'{new_indent}"type": "{config.typ3}",\\n\''},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'typ3'},{'id': '35', 'type': 'string', 'children': [], 'value': "''"},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '""'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '40', 'type': 'generator_expression', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_render'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'new_indent'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '52', 'type': 'string', 'children': [], 'value': '"}\\n"'}
def render_config(config: Config, indent: str = "") -> str: new_indent = indent + " " return "".join([ "{\n", f'{new_indent}"type": "{config.typ3}",\n' if config.typ3 else '', "".join(_render(item, new_indent) for item in config.items), indent, "}\n" ])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '54']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_and_run_forward'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '33', '39', '45']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'generic_type', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Callable'},{'id': '10', 'type': 'type_parameter', 'children': ['11', '17']},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'list', 'children': ['13', '14'], 'value': '[PackedSequence, Optional[RnnState]]'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'PackedSequence'},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'RnnState'},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'generic_type', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '20', 'type': 'type_parameter', 'children': ['21', '31']},{'id': '21', 'type': 'type', 'children': ['22']},{'id': '22', 'type': 'generic_type', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Union'},{'id': '24', 'type': 'type_parameter', 'children': ['25', '27']},{'id': '25', 'type': 'type', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'PackedSequence'},{'id': '27', 'type': 'type', 'children': ['28']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Tensor'},{'id': '31', 'type': 'type', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'RnnState'},{'id': '33', 'type': 'typed_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '35', 'type': 'type', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'Tensor'},{'id': '39', 'type': 'typed_parameter', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '41', 'type': 'type', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'Tensor'},{'id': '45', 'type': 'typed_default_parameter', 'children': ['46', '47', '53']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'hidden_state'},{'id': '47', 'type': 'type', 'children': ['48']},{'id': '48', 'type': 'generic_type', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '50', 'type': 'type_parameter', 'children': ['51']},{'id': '51', 'type': 'type', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'RnnState'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'block', 'children': ['55', '64', '85', '92', '105', '134', '219', '229']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '67', 'type': 'call', 'children': ['68', '84']},{'id': '68', 'type': 'attribute', 'children': ['69', '83']},{'id': '69', 'type': 'call', 'children': ['70', '82']},{'id': '70', 'type': 'attribute', 'children': ['71', '81']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'subscript', 'children': ['77', '78', '80']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '78', 'type': 'slice', 'children': ['79']},{'id': '79', 'type': 'colon', 'children': []},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sequence_lengths'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'get_lengths_from_binary_sequence_mask'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '99', '100']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96', '97', '98']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sorted_sequence_lengths'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'restoration_indices'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sorting_indices'},{'id': '99', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort_batch_by_length'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sequence_lengths'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'packed_sequence_input'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'pack_padded_sequence'},{'id': '110', 'type': 'argument_list', 'children': ['111', '120', '131']},{'id': '111', 'type': 'subscript', 'children': ['112', '113', '116', '118']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sorted_inputs'},{'id': '113', 'type': 'slice', 'children': ['114', '115']},{'id': '114', 'type': 'colon', 'children': []},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '116', 'type': 'slice', 'children': ['117']},{'id': '117', 'type': 'colon', 'children': []},{'id': '118', 'type': 'slice', 'children': ['119']},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'call', 'children': ['121', '130']},{'id': '121', 'type': 'attribute', 'children': ['122', '129']},{'id': '122', 'type': 'attribute', 'children': ['123', '128']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'sorted_sequence_lengths'},{'id': '125', 'type': 'slice', 'children': ['126', '127']},{'id': '126', 'type': 'colon', 'children': []},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'batch_first'},{'id': '133', 'type': 'True', 'children': []},{'id': '134', 'type': 'if_statement', 'children': ['135', '139', '206']},{'id': '135', 'type': 'not_operator', 'children': ['136']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'stateful'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '144', '149', '182']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'is'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'hidden_state'},{'id': '143', 'type': 'None', 'children': []},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'initial_states'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'hidden_state'},{'id': '149', 'type': 'elif_clause', 'children': ['150', '155']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'hidden_state'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'initial_states'},{'id': '159', 'type': 'list_comprehension', 'children': ['160', '179']},{'id': '160', 'type': 'call', 'children': ['161', '178']},{'id': '161', 'type': 'attribute', 'children': ['162', '177']},{'id': '162', 'type': 'subscript', 'children': ['163', '170', '172', '175']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'index_select'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sorting_indices'},{'id': '170', 'type': 'slice', 'children': ['171']},{'id': '171', 'type': 'colon', 'children': []},{'id': '172', 'type': 'slice', 'children': ['173', '174']},{'id': '173', 'type': 'colon', 'children': []},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '175', 'type': 'slice', 'children': ['176']},{'id': '176', 'type': 'colon', 'children': []},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'contiguous'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'hidden_state'},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'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': 'initial_states'},{'id': '187', 'type': 'call', 'children': ['188', '205']},{'id': '188', 'type': 'attribute', 'children': ['189', '204']},{'id': '189', 'type': 'subscript', 'children': ['190', '197', '199', '202']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'hidden_state'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'index_select'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'sorting_indices'},{'id': '197', 'type': 'slice', 'children': ['198']},{'id': '198', 'type': 'colon', 'children': []},{'id': '199', 'type': 'slice', 'children': ['200', '201']},{'id': '200', 'type': 'colon', 'children': []},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '202', 'type': 'slice', 'children': ['203']},{'id': '203', 'type': 'colon', 'children': []},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'contiguous'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'else_clause', 'children': ['207']},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'initial_states'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': '_get_initial_states'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217', '218']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'sorting_indices'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '224']},{'id': '221', 'type': 'pattern_list', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'module_output'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'final_states'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'packed_sequence_input'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'initial_states'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'expression_list', 'children': ['231', '232', '233']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'module_output'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'final_states'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'restoration_indices'}
def sort_and_run_forward(self, module: Callable[[PackedSequence, Optional[RnnState]], Tuple[Union[PackedSequence, torch.Tensor], RnnState]], inputs: torch.Tensor, mask: torch.Tensor, hidden_state: Optional[RnnState] = None): batch_size = mask.size(0) num_valid = torch.sum(mask[:, 0]).int().item() sequence_lengths = get_lengths_from_binary_sequence_mask(mask) sorted_inputs, sorted_sequence_lengths, restoration_indices, sorting_indices =\ sort_batch_by_length(inputs, sequence_lengths) packed_sequence_input = pack_padded_sequence(sorted_inputs[:num_valid, :, :], sorted_sequence_lengths[:num_valid].data.tolist(), batch_first=True) if not self.stateful: if hidden_state is None: initial_states = hidden_state elif isinstance(hidden_state, tuple): initial_states = [state.index_select(1, sorting_indices)[:, :num_valid, :].contiguous() for state in hidden_state] else: initial_states = hidden_state.index_select(1, sorting_indices)[:, :num_valid, :].contiguous() else: initial_states = self._get_initial_states(batch_size, num_valid, sorting_indices) module_output, final_states = module(packed_sequence_input, initial_states) return module_output, final_states, restoration_indices
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_initial_states'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '13', 'type': 'typed_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorting_indices'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'LongTensor'},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'generic_type', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '22', 'type': 'type_parameter', 'children': ['23']},{'id': '23', 'type': 'type', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'RnnState'},{'id': '25', 'type': 'block', 'children': ['26', '35', '167']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': 'is'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'if_statement', 'children': ['36', '48', '125', '159']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '>'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '38', 'type': 'call', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'subscript', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'block', 'children': ['49', '64', '68', '110', '119']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'num_states_to_concat'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '-'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '54', 'type': 'call', 'children': ['55', '62']},{'id': '55', 'type': 'attribute', 'children': ['56', '61']},{'id': '56', 'type': 'subscript', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'resized_states'},{'id': '67', 'type': 'list', 'children': [], 'value': '[]'},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '73']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '73', 'type': 'block', 'children': ['74', '95']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_zeros'},{'id': '81', 'type': 'argument_list', 'children': ['82', '88', '89']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'num_states_to_concat'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'resized_states'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '105', 'type': 'argument_list', 'children': ['106', '109']},{'id': '106', 'type': 'list', 'children': ['107', '108'], 'value': '[state, zeros]'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'resized_states'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'correctly_shaped_states'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '125', 'type': 'elif_clause', 'children': ['126', '138']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '<'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '128', 'type': 'call', 'children': ['129', '136']},{'id': '129', 'type': 'attribute', 'children': ['130', '135']},{'id': '130', 'type': 'subscript', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'correctly_shaped_states'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '144', 'type': 'generator_expression', 'children': ['145', '154']},{'id': '145', 'type': 'subscript', 'children': ['146', '147', '149', '152']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '147', 'type': 'slice', 'children': ['148']},{'id': '148', 'type': 'colon', 'children': []},{'id': '149', 'type': 'slice', 'children': ['150', '151']},{'id': '150', 'type': 'colon', 'children': []},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '152', 'type': 'slice', 'children': ['153']},{'id': '153', 'type': 'colon', 'children': []},{'id': '154', 'type': 'for_in_clause', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '159', 'type': 'else_clause', 'children': ['160']},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'correctly_shaped_states'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '167', 'type': 'if_statement', 'children': ['168', '176', '207']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '175'], 'value': '=='},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'block', 'children': ['177', '183', '193']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'correctly_shaped_state'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'correctly_shaped_states'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'sorted_state'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'correctly_shaped_state'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'index_select'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192']},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'sorting_indices'},{'id': '193', 'type': 'return_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '206']},{'id': '195', 'type': 'attribute', 'children': ['196', '205']},{'id': '196', 'type': 'subscript', 'children': ['197', '198', '200', '203']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'sorted_state'},{'id': '198', 'type': 'slice', 'children': ['199']},{'id': '199', 'type': 'colon', 'children': []},{'id': '200', 'type': 'slice', 'children': ['201', '202']},{'id': '201', 'type': 'colon', 'children': []},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '203', 'type': 'slice', 'children': ['204']},{'id': '204', 'type': 'colon', 'children': []},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'contiguous'},{'id': '206', 'type': 'argument_list', 'children': []},{'id': '207', 'type': 'else_clause', 'children': ['208']},{'id': '208', 'type': 'block', 'children': ['209', '223']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'sorted_states'},{'id': '212', 'type': 'list_comprehension', 'children': ['213', '220']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'index_select'},{'id': '217', 'type': 'argument_list', 'children': ['218', '219']},{'id': '218', 'type': 'integer', 'children': [], 'value': '1'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'sorting_indices'},{'id': '220', 'type': 'for_in_clause', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'correctly_shaped_states'},{'id': '223', 'type': 'return_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '226', 'type': 'generator_expression', 'children': ['227', '240']},{'id': '227', 'type': 'call', 'children': ['228', '239']},{'id': '228', 'type': 'attribute', 'children': ['229', '238']},{'id': '229', 'type': 'subscript', 'children': ['230', '231', '233', '236']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '231', 'type': 'slice', 'children': ['232']},{'id': '232', 'type': 'colon', 'children': []},{'id': '233', 'type': 'slice', 'children': ['234', '235']},{'id': '234', 'type': 'colon', 'children': []},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'num_valid'},{'id': '236', 'type': 'slice', 'children': ['237']},{'id': '237', 'type': 'colon', 'children': []},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'contiguous'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'for_in_clause', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sorted_states'}
def _get_initial_states(self, batch_size: int, num_valid: int, sorting_indices: torch.LongTensor) -> Optional[RnnState]: if self._states is None: return None if batch_size > self._states[0].size(1): num_states_to_concat = batch_size - self._states[0].size(1) resized_states = [] for state in self._states: zeros = state.new_zeros(state.size(0), num_states_to_concat, state.size(2)) resized_states.append(torch.cat([state, zeros], 1)) self._states = tuple(resized_states) correctly_shaped_states = self._states elif batch_size < self._states[0].size(1): correctly_shaped_states = tuple(state[:, :batch_size, :] for state in self._states) else: correctly_shaped_states = self._states if len(self._states) == 1: correctly_shaped_state = correctly_shaped_states[0] sorted_state = correctly_shaped_state.index_select(1, sorting_indices) return sorted_state[:, :num_valid, :].contiguous() else: sorted_states = [state.index_select(1, sorting_indices) for state in correctly_shaped_states] return tuple(state[:, :num_valid, :].contiguous() for state in sorted_states)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_states'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'final_states'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'RnnStateStorage'},{'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'restoration_indices'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'LongTensor'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '32']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'new_unsorted_states'},{'id': '21', 'type': 'list_comprehension', 'children': ['22', '29']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'index_select'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'restoration_indices'},{'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'final_states'},{'id': '32', 'type': 'if_statement', 'children': ['33', '38', '53']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': 'is'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '46', 'type': 'generator_expression', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'new_unsorted_states'},{'id': '53', 'type': 'else_clause', 'children': ['54']},{'id': '54', 'type': 'block', 'children': ['55', '68', '79', '113', '117', '222']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'current_state_batch_size'},{'id': '58', 'type': 'call', 'children': ['59', '66']},{'id': '59', 'type': 'attribute', 'children': ['60', '65']},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'new_state_batch_size'},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'final_states'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'used_new_rows_mask'},{'id': '82', 'type': 'list_comprehension', 'children': ['83', '110']},{'id': '83', 'type': 'call', 'children': ['84', '106']},{'id': '84', 'type': 'attribute', 'children': ['85', '105']},{'id': '85', 'type': 'call', 'children': ['86', '104']},{'id': '86', 'type': 'attribute', 'children': ['87', '103']},{'id': '87', 'type': '()', 'children': ['88']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '102'], 'value': '!='},{'id': '89', 'type': 'call', 'children': ['90', '99']},{'id': '90', 'type': 'attribute', 'children': ['91', '98']},{'id': '91', 'type': 'subscript', 'children': ['92', '93', '94', '96']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '93', 'type': 'integer', 'children': [], 'value': '0'},{'id': '94', 'type': 'slice', 'children': ['95']},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'slice', 'children': ['97']},{'id': '97', 'type': 'colon', 'children': []},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'unary_operator', 'children': ['101'], 'value': '-'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109']},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'new_state_batch_size'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'new_unsorted_states'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'new_states'},{'id': '116', 'type': 'list', 'children': [], 'value': '[]'},{'id': '117', 'type': 'if_statement', 'children': ['118', '121', '178']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '>'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'current_state_batch_size'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'new_state_batch_size'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'for_statement', 'children': ['123', '127', '135']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'old_state'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'new_state'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'used_mask'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '129', 'type': 'argument_list', 'children': ['130', '133', '134']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'new_unsorted_states'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'used_new_rows_mask'},{'id': '135', 'type': 'block', 'children': ['136', '153', '167']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'masked_old_state'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '149'], 'value': '*'},{'id': '140', 'type': 'subscript', 'children': ['141', '142', '144', '147']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'old_state'},{'id': '142', 'type': 'slice', 'children': ['143']},{'id': '143', 'type': 'colon', 'children': []},{'id': '144', 'type': 'slice', 'children': ['145', '146']},{'id': '145', 'type': 'colon', 'children': []},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'new_state_batch_size'},{'id': '147', 'type': 'slice', 'children': ['148']},{'id': '148', 'type': 'colon', 'children': []},{'id': '149', 'type': '()', 'children': ['150']},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '-'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'used_mask'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '164']},{'id': '155', 'type': 'subscript', 'children': ['156', '157', '159', '162']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'old_state'},{'id': '157', 'type': 'slice', 'children': ['158']},{'id': '158', 'type': 'colon', 'children': []},{'id': '159', 'type': 'slice', 'children': ['160', '161']},{'id': '160', 'type': 'colon', 'children': []},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'new_state_batch_size'},{'id': '162', 'type': 'slice', 'children': ['163']},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '+'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'new_state'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'masked_old_state'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'new_states'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'old_state'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'detach'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'else_clause', 'children': ['179']},{'id': '179', 'type': 'block', 'children': ['180', '184']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'new_states'},{'id': '183', 'type': 'list', 'children': [], 'value': '[]'},{'id': '184', 'type': 'for_statement', 'children': ['185', '189', '197']},{'id': '185', 'type': 'pattern_list', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'old_state'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'new_state'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'used_mask'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '191', 'type': 'argument_list', 'children': ['192', '195', '196']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'new_unsorted_states'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'used_new_rows_mask'},{'id': '197', 'type': 'block', 'children': ['198', '207', '211']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'masked_old_state'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '*'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'old_state'},{'id': '203', 'type': '()', 'children': ['204']},{'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '-'},{'id': '205', 'type': 'integer', 'children': [], 'value': '1'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'used_mask'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'augmented_assignment', 'children': ['209', '210'], 'value': '+='},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'new_state'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'masked_old_state'},{'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': 'new_states'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'new_state'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'detach'},{'id': '221', 'type': 'argument_list', 'children': []},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': '_states'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'new_states'}
def _update_states(self, final_states: RnnStateStorage, restoration_indices: torch.LongTensor) -> None: new_unsorted_states = [state.index_select(1, restoration_indices) for state in final_states] if self._states is None: self._states = tuple(state.data for state in new_unsorted_states) else: current_state_batch_size = self._states[0].size(1) new_state_batch_size = final_states[0].size(1) used_new_rows_mask = [(state[0, :, :].sum(-1) != 0.0).float().view(1, new_state_batch_size, 1) for state in new_unsorted_states] new_states = [] if current_state_batch_size > new_state_batch_size: for old_state, new_state, used_mask in zip(self._states, new_unsorted_states, used_new_rows_mask): masked_old_state = old_state[:, :new_state_batch_size, :] * (1 - used_mask) old_state[:, :new_state_batch_size, :] = new_state + masked_old_state new_states.append(old_state.detach()) else: new_states = [] for old_state, new_state, used_mask in zip(self._states, new_unsorted_states, used_new_rows_mask): masked_old_state = old_state * (1 - used_mask) new_state += masked_old_state new_states.append(new_state.detach()) self._states = tuple(new_states)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_prune_beam'},{'id': '3', 'type': 'parameters', 'children': ['4', '12', '16']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'State'},{'id': '12', 'type': 'typed_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'beam_size'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'typed_default_parameter', 'children': ['17', '18', '20']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort_states'},{'id': '18', 'type': 'type', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'type', 'children': ['22']},{'id': '22', 'type': 'generic_type', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '24', 'type': 'type_parameter', 'children': ['25']},{'id': '25', 'type': 'type', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'State'},{'id': '27', 'type': 'block', 'children': ['28', '47', '77', '81', '173']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31', '43']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'states_by_batch_index'},{'id': '31', 'type': 'type', 'children': ['32']},{'id': '32', 'type': 'generic_type', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '34', 'type': 'type_parameter', 'children': ['35', '37']},{'id': '35', 'type': 'type', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '37', 'type': 'type', 'children': ['38']},{'id': '38', 'type': 'generic_type', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '40', 'type': 'type_parameter', 'children': ['41']},{'id': '41', 'type': 'type', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'State'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '50', 'type': 'block', 'children': ['51', '60', '68']},{'id': '51', 'type': 'assert_statement', 'children': ['52']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '59'], 'value': '=='},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'batch_indices'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'batch_index'},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'batch_indices'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'states_by_batch_index'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'batch_index'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pruned_states'},{'id': '80', 'type': 'list', 'children': [], 'value': '[]'},{'id': '81', 'type': 'for_statement', 'children': ['82', '85', '90']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'instance_states'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'states_by_batch_index'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'block', 'children': ['91', '158']},{'id': '91', 'type': 'if_statement', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sort_states'},{'id': '93', 'type': 'block', 'children': ['94', '117', '132', '154']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'torch'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'list_comprehension', 'children': ['103', '114']},{'id': '103', 'type': 'call', 'children': ['104', '111']},{'id': '104', 'type': 'attribute', 'children': ['105', '110']},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'unary_operator', 'children': ['113'], 'value': '-'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'instance_states'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '126', 'type': 'argument_list', 'children': ['127', '129']},{'id': '127', 'type': 'unary_operator', 'children': ['128'], 'value': '-'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '131', 'type': 'True', 'children': []},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sorted_states'},{'id': '135', 'type': 'list_comprehension', 'children': ['136', '139']},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'instance_states'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '141', 'type': 'call', 'children': ['142', '153']},{'id': '142', 'type': 'attribute', 'children': ['143', '152']},{'id': '143', 'type': 'call', 'children': ['144', '151']},{'id': '144', 'type': 'attribute', 'children': ['145', '150']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'detach'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'instance_states'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'sorted_states'},{'id': '158', 'type': 'for_statement', 'children': ['159', '160', '165']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'instance_states'},{'id': '162', 'type': 'slice', 'children': ['163', '164']},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'beam_size'},{'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': 'pruned_states'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'pruned_states'}
def _prune_beam(states: List[State], beam_size: int, sort_states: bool = False) -> List[State]: states_by_batch_index: Dict[int, List[State]] = defaultdict(list) for state in states: assert len(state.batch_indices) == 1 batch_index = state.batch_indices[0] states_by_batch_index[batch_index].append(state) pruned_states = [] for _, instance_states in states_by_batch_index.items(): if sort_states: scores = torch.cat([state.score[0].view(-1) for state in instance_states]) _, sorted_indices = scores.sort(-1, descending=True) sorted_states = [instance_states[i] for i in sorted_indices.detach().cpu().numpy()] instance_states = sorted_states for state in instance_states[:beam_size]: pruned_states.append(state) return pruned_states
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'take_step'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'StateType'},{'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'max_actions'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'typed_default_parameter', 'children': ['15', '16', '22']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'allowed_actions'},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'generic_type', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '19', 'type': 'type_parameter', 'children': ['20']},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Set'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'type', 'children': ['24']},{'id': '24', 'type': 'generic_type', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '26', 'type': 'type_parameter', 'children': ['27']},{'id': '27', 'type': 'type', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'StateType'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}
def take_step(self, state: StateType, max_actions: int = None, allowed_actions: List[Set] = None) -> List[StateType]: raise NotImplementedError
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'row_sparse_pull'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'row_ids'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '21', '26', '38', '46', '50', '54', '79', '90', '101', '113', '174']},{'id': '16', 'type': 'assert_statement', 'children': ['17']},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'assert_statement', 'children': ['22']},{'id': '22', 'type': '()', 'children': ['23']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'row_ids'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'row_ids'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'NDArray'},{'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': 'row_ids'},{'id': '36', 'type': 'list', 'children': ['37'], 'value': '[row_ids]'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'row_ids'},{'id': '38', 'type': 'assert_statement', 'children': ['39', '45']},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'row_ids'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '45', 'type': 'string', 'children': [], 'value': '"row_ids should be NDArray or list of NDArray"'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'first_out'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'single_rowid'},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'if_statement', 'children': ['55', '67']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '62'], 'value': 'and'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '=='},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'row_ids'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '67', 'type': 'block', 'children': ['68', '72']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'single_rowid'},{'id': '71', 'type': 'True', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'first_out'},{'id': '75', 'type': 'list', 'children': ['76'], 'value': '[out[0]]'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '85']},{'id': '81', 'type': 'pattern_list', 'children': ['82', '83', '84']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ckeys'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cvals'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'use_str_keys'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_ctype_key_value'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'first_out'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '96']},{'id': '92', 'type': 'pattern_list', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'crow_ids'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_ctype_key_value'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'row_ids'},{'id': '101', 'type': 'assert_statement', 'children': ['102', '112']},{'id': '102', 'type': '()', 'children': ['103']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '108'], 'value': '=='},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'crow_ids'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'cvals'},{'id': '112', 'type': 'string', 'children': [], 'value': '"the number of row_ids doesn\'t match the number of values"'},{'id': '113', 'type': 'if_statement', 'children': ['114', '115', '144']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'use_str_keys'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'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': '_LIB'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'MXKVStorePullRowSparseEx'},{'id': '124', 'type': 'argument_list', 'children': ['125', '128', '135', '136', '137', '138']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'mx_uint'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ckeys'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ckeys'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'cvals'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'crow_ids'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ctypes'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_LIB'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'MXKVStorePullRowSparse'},{'id': '154', 'type': 'argument_list', 'children': ['155', '158', '165', '166', '167', '168']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mx_uint'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ckeys'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ckeys'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'cvals'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'crow_ids'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ctypes'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '174', 'type': 'if_statement', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'single_rowid'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'for_statement', 'children': ['178', '179', '184']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'out_i'},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '181', 'type': 'slice', 'children': ['182', '183']},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'colon', 'children': []},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'copyto'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'out_i'}
def row_sparse_pull(self, key, out=None, priority=0, row_ids=None): assert(out is not None) assert(row_ids is not None) if isinstance(row_ids, NDArray): row_ids = [row_ids] assert(isinstance(row_ids, list)), \ "row_ids should be NDArray or list of NDArray" first_out = out single_rowid = False if len(row_ids) == 1 and isinstance(out, list): single_rowid = True first_out = [out[0]] ckeys, cvals, use_str_keys = _ctype_key_value(key, first_out) _, crow_ids, _ = _ctype_key_value(key, row_ids) assert(len(crow_ids) == len(cvals)), \ "the number of row_ids doesn't match the number of values" if use_str_keys: check_call(_LIB.MXKVStorePullRowSparseEx( self.handle, mx_uint(len(ckeys)), ckeys, cvals, crow_ids, ctypes.c_int(priority))) else: check_call(_LIB.MXKVStorePullRowSparse( self.handle, mx_uint(len(ckeys)), ckeys, cvals, crow_ids, ctypes.c_int(priority))) if single_rowid: for out_i in out[1:]: out[0].copyto(out_i)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'row_sparse_array'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '21', '125']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '21', 'type': 'block', 'children': ['22', '29']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'arg_len'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '29', 'type': 'if_statement', 'children': ['30', '33', '44', '67']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '<'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'arg_len'},{'id': '32', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'ValueError'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '+'},{'id': '39', 'type': 'string', 'children': [], 'value': '"Unexpected length of input tuple: "'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'arg_len'},{'id': '44', 'type': 'elif_clause', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '>'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'arg_len'},{'id': '47', 'type': 'integer', 'children': [], 'value': '2'},{'id': '48', 'type': 'block', 'children': ['49', '55']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_check_shape'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61', '64']},{'id': '59', 'type': 'string', 'children': [], 'value': "'row_sparse'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '85', '104']},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '78'], 'value': 'and'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'integer_types'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '80', 'type': 'argument_list', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'integer_types'},{'id': '85', 'type': 'block', 'children': ['86', '92']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_check_shape'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98', '101']},{'id': '96', 'type': 'string', 'children': [], 'value': "'row_sparse'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '104', 'type': 'else_clause', 'children': ['105']},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_row_sparse_ndarray_from_definition'},{'id': '109', 'type': 'argument_list', 'children': ['110', '113', '116', '119', '122']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'if_statement', 'children': ['128', '133', '153', '165']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'RowSparseNDArray'},{'id': '133', 'type': 'block', 'children': ['134', '142']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_check_shape'},{'id': '137', 'type': 'argument_list', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147', '150']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '153', 'type': 'elif_clause', 'children': ['154', '159']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'CSRNDArray'},{'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': 'ValueError'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': '"Unexpected input type: CSRNDArray"'},{'id': '165', 'type': 'else_clause', 'children': ['166']},{'id': '166', 'type': 'block', 'children': ['167', '175', '185', '205', '213']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': '_prepare_default_dtype'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'dns'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_array'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '185', 'type': 'if_statement', 'children': ['186', '195']},{'id': '186', 'type': 'boolean_operator', 'children': ['187', '190'], 'value': 'and'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '194'], 'value': '!='},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'dns'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'dns'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'dns'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'as_in_context'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_check_shape'},{'id': '208', 'type': 'argument_list', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'dns'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '213', 'type': 'return_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'dns'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'tostype'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': "'row_sparse'"}
def row_sparse_array(arg1, shape=None, ctx=None, dtype=None): if isinstance(arg1, tuple): arg_len = len(arg1) if arg_len < 2: raise ValueError("Unexpected length of input tuple: " + str(arg_len)) elif arg_len > 2: _check_shape(arg1, shape) return empty('row_sparse', arg1, ctx=ctx, dtype=dtype) else: if isinstance(arg1[0], integer_types) and isinstance(arg1[1], integer_types): _check_shape(arg1, shape) return empty('row_sparse', arg1, ctx=ctx, dtype=dtype) else: return _row_sparse_ndarray_from_definition(arg1[0], arg1[1], shape=shape, ctx=ctx, dtype=dtype) else: if isinstance(arg1, RowSparseNDArray): _check_shape(arg1.shape, shape) return array(arg1, ctx=ctx, dtype=dtype) elif isinstance(arg1, CSRNDArray): raise ValueError("Unexpected input type: CSRNDArray") else: dtype = _prepare_default_dtype(arg1, dtype) dns = _array(arg1, dtype=dtype) if ctx is not None and dns.context != ctx: dns = dns.as_in_context(ctx) _check_shape(dns.shape, shape) return dns.tostype('row_sparse')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '22', '44']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'beams'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '11', 'type': 'for_in_clause', 'children': ['12', '15']},{'id': '12', 'type': 'tuple_pattern', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'entries'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortedBeams'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '32']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'beams'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'lambda', 'children': ['35', '37']},{'id': '35', 'type': 'lambda_parameters', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '41'], 'value': '*'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'prTotal'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'prText'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'list_comprehension', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'labeling'},{'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sortedBeams'}
def sort(self): beams = [v for (_, v) in self.entries.items()] sortedBeams = sorted(beams, reverse=True, key=lambda x: x.prTotal*x.prText) return [x.labeling for x in sortedBeams]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'runtime'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'model_generator'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '8', 'type': 'block', 'children': ['9', '19', '28', '32', '144', '153']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'old_seed'},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'integer', 'children': [], 'value': '3293'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'method_reps'},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '38']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'block', 'children': ['39', '60', '66', '74', '82', '94', '104', '112', '117', '127']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '46']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43', '44', '45']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'X_train'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'y_train'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'train_test_split'},{'id': '48', 'type': 'argument_list', 'children': ['49', '53', '54', '57']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': '__toarray'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'test_size'},{'id': '56', 'type': 'integer', 'children': [], 'value': '100'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'model_generator'},{'id': '65', 'type': 'argument_list', 'children': []},{'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': 'model'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'X_train'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'y_train'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'explainer'},{'id': '85', 'type': 'call', 'children': ['86', '91']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'X_train'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'build_time'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '103'], 'value': '-'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'explainer'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'explain_time'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '126'], 'value': '-'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'start'},{'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': 'method_reps'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'build_time'},{'id': '135', 'type': 'binary_operator', 'children': ['136', '139'], 'value': '/'},{'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '*'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'explain_time'},{'id': '138', 'type': 'float', 'children': [], 'value': '1000.0'},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'old_seed'},{'id': '153', 'type': 'return_statement', 'children': ['154']},{'id': '154', 'type': 'expression_list', 'children': ['155', '156']},{'id': '155', 'type': 'None', 'children': []},{'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': 'mean'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'method_reps'}
def runtime(X, y, model_generator, method_name): old_seed = np.random.seed() np.random.seed(3293) method_reps = [] for i in range(1): X_train, X_test, y_train, _ = train_test_split(__toarray(X), y, test_size=100, random_state=i) model = model_generator() model.fit(X_train, y_train) start = time.time() explainer = getattr(methods, method_name)(model, X_train) build_time = time.time() - start start = time.time() explainer(X_test) explain_time = time.time() - start method_reps.append(build_time + explain_time * 1000.0 / X_test.shape[0]) np.random.seed(old_seed) return None, np.mean(method_reps)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'local_accuracy'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'model_generator'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '8', 'type': 'block', 'children': ['9', '100', '128']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '14']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'score_map'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'true'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '14', 'type': 'block', 'children': ['15', '40']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '31'], 'value': '/'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'std'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '-'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'true'},{'id': '31', 'type': '()', 'children': ['32']},{'id': '32', 'type': 'binary_operator', 'children': ['33', '39'], 'value': '+'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'std'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'true'},{'id': '39', 'type': 'float', 'children': [], 'value': '1e-8'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44', '47', '54', '61', '68', '75', '82', '89', '96']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '<'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '43', 'type': 'float', 'children': [], 'value': '1e-6'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '47', 'type': 'elif_clause', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '<'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '50', 'type': 'float', 'children': [], 'value': '0.01'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'float', 'children': [], 'value': '0.9'},{'id': '54', 'type': 'elif_clause', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '<'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '57', 'type': 'float', 'children': [], 'value': '0.05'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'float', 'children': [], 'value': '0.75'},{'id': '61', 'type': 'elif_clause', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '<'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '64', 'type': 'float', 'children': [], 'value': '0.1'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'float', 'children': [], 'value': '0.6'},{'id': '68', 'type': 'elif_clause', 'children': ['69', '72']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '<'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '71', 'type': 'float', 'children': [], 'value': '0.2'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'float', 'children': [], 'value': '0.4'},{'id': '75', 'type': 'elif_clause', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '<'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '78', 'type': 'float', 'children': [], 'value': '0.3'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'float', 'children': [], 'value': '0.3'},{'id': '82', 'type': 'elif_clause', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '<'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '85', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'float', 'children': [], 'value': '0.2'},{'id': '89', 'type': 'elif_clause', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '<'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '92', 'type': 'float', 'children': [], 'value': '0.7'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'float', 'children': [], 'value': '0.1'},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '100', 'type': 'function_definition', 'children': ['101', '102', '110']},{'id': '101', 'type': 'function_name', 'children': [], 'value': 'score_function'},{'id': '102', 'type': 'parameters', 'children': ['103', '104', '105', '106', '107', '108', '109']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'X_train'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'y_train'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'y_test'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'attr_function'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'trained_model'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'local_accuracy'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119', '120', '121', '125', '126', '127']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'X_train'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'y_train'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'y_test'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'attr_function'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'model_generator'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'score_map'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'trained_model'},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'expression_list', 'children': ['130', '131']},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': '__score_method'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135', '136', '137', '138', '139']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '136', 'type': 'None', 'children': []},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'model_generator'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'score_function'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'method_name'}
def local_accuracy(X, y, model_generator, method_name): def score_map(true, pred): v = min(1.0, np.std(pred - true) / (np.std(true) + 1e-8)) if v < 1e-6: return 1.0 elif v < 0.01: return 0.9 elif v < 0.05: return 0.75 elif v < 0.1: return 0.6 elif v < 0.2: return 0.4 elif v < 0.3: return 0.3 elif v < 0.5: return 0.2 elif v < 0.7: return 0.1 else: return 0.0 def score_function(X_train, X_test, y_train, y_test, attr_function, trained_model, random_state): return measures.local_accuracy( X_train, y_train, X_test, y_test, attr_function(X_test), model_generator, score_map, trained_model ) return None, __score_method(X, y, None, model_generator, score_function, method_name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_checkpoints_for_actor'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'actor_id'},{'id': '5', 'type': 'block', 'children': ['6', '19', '26', '48']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'checkpoint_info'},{'id': '9', 'type': 'call', 'children': ['10', '17']},{'id': '10', 'type': 'attribute', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ray'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'global_state'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'actor_checkpoint_info'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'actor_id'},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'checkpoint_info'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'checkpoints'},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '35']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Checkpoint'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'checkpoint_id'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'checkpoint_id'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '41', 'type': 'argument_list', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'checkpoint_info'},{'id': '44', 'type': 'string', 'children': [], 'value': '"CheckpointIds"'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'checkpoint_info'},{'id': '47', 'type': 'string', 'children': [], 'value': '"Timestamps"'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53', '61']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'checkpoints'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '55', 'type': 'lambda', 'children': ['56', '58']},{'id': '56', 'type': 'lambda_parameters', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'checkpoint'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'checkpoint'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '63', 'type': 'True', 'children': []}
def get_checkpoints_for_actor(actor_id): checkpoint_info = ray.worker.global_state.actor_checkpoint_info(actor_id) if checkpoint_info is None: return [] checkpoints = [ Checkpoint(checkpoint_id, timestamp) for checkpoint_id, timestamp in zip(checkpoint_info["CheckpointIds"], checkpoint_info["Timestamps"]) ] return sorted( checkpoints, key=lambda checkpoint: checkpoint.timestamp, reverse=True, )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_naturalize'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '5', 'type': 'block', 'children': ['6', '16']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'string', 'children': [], 'value': '"([0-9]+)"'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'list_comprehension', 'children': ['18', '33']},{'id': '18', 'type': 'conditional_expression', 'children': ['19', '23', '28'], 'value': 'if'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'splits'}
def _naturalize(string): splits = re.split("([0-9]+)", string) return [int(text) if text.isdigit() else text.lower() for text in splits]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mount'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'adapter'},{'id': '7', 'type': 'block', 'children': ['8', '16', '36']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '15']},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'adapters'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'adapter'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'keys_to_move'},{'id': '19', 'type': 'list_comprehension', 'children': ['20', '21', '26']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'adapters'},{'id': '26', 'type': 'if_clause', 'children': ['27']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '<'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'keys_to_move'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '47']},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'adapters'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'adapters'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'}
def mount(self, prefix, adapter): self.adapters[prefix] = adapter keys_to_move = [k for k in self.adapters if len(k) < len(prefix)] for key in keys_to_move: self.adapters[key] = self.adapters.pop(key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_outrows'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'outrows'},{'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': 'sorted'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'outrows'},{'id': '11', 'type': 'keyword_argument', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '13', 'type': 'lambda', 'children': ['14', '16']},{'id': '14', 'type': 'lambda_parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '18', 'type': 'generator_expression', 'children': ['19', '23']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'row'}
def sorted_outrows(outrows): return sorted(outrows, key=lambda row: tuple(str(x) for x in row))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'traceParseAction'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '5', 'type': 'block', 'children': ['6', '13', '123', '137']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_trim_arity'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '13', 'type': 'function_definition', 'children': ['14', '15', '18']},{'id': '14', 'type': 'function_name', 'children': [], 'value': 'z'},{'id': '15', 'type': 'parameters', 'children': ['16']},{'id': '16', 'type': 'list_splat_pattern', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'paArgs'},{'id': '18', 'type': 'block', 'children': ['19', '25', '37', '59', '78', '108', '121']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'thisFunc'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '31']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'paArgs'},{'id': '33', 'type': 'slice', 'children': ['34', '36']},{'id': '34', 'type': 'unary_operator', 'children': ['35'], 'value': '-'},{'id': '35', 'type': 'integer', 'children': [], 'value': '3'},{'id': '36', 'type': 'colon', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '44']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '43'], 'value': '>'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'paArgs'},{'id': '43', 'type': 'integer', 'children': [], 'value': '3'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'thisFunc'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '58'], 'value': '+'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '57'], 'value': '+'},{'id': '50', 'type': 'attribute', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'paArgs'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '57', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'thisFunc'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '66']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '%'},{'id': '68', 'type': 'string', 'children': [], 'value': '">>entering %s(line: \'%s\', %d, %r)\\n"'},{'id': '69', 'type': 'tuple', 'children': ['70', '71', '76', '77']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'thisFunc'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '78', 'type': 'try_statement', 'children': ['79', '88']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'list_splat', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'paArgs'},{'id': '88', 'type': 'except_clause', 'children': ['89', '93']},{'id': '89', 'type': 'as_pattern', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '91', 'type': 'as_pattern_target', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '93', 'type': 'block', 'children': ['94', '107']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'},{'id': '103', 'type': 'string', 'children': [], 'value': '"<<leaving %s (exception: %s)\\n"'},{'id': '104', 'type': 'tuple', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'thisFunc'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '107', 'type': 'raise_statement', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'},{'id': '117', 'type': 'string', 'children': [], 'value': '"<<leaving %s (ret: %r)\\n"'},{'id': '118', 'type': 'tuple', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'thisFunc'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '123', 'type': 'try_statement', 'children': ['124', '133']},{'id': '124', 'type': 'block', 'children': ['125']},{'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': 'z'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '133', 'type': 'except_clause', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'pass_statement', 'children': []},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'z'}
def traceParseAction(f): f = _trim_arity(f) def z(*paArgs): thisFunc = f.__name__ s,l,t = paArgs[-3:] if len(paArgs)>3: thisFunc = paArgs[0].__class__.__name__ + '.' + thisFunc sys.stderr.write( ">>entering %s(line: '%s', %d, %r)\n" % (thisFunc,line(l,s),l,t) ) try: ret = f(*paArgs) except Exception as exc: sys.stderr.write( "<<leaving %s (exception: %s)\n" % (thisFunc,exc) ) raise sys.stderr.write( "<<leaving %s (ret: %r)\n" % (thisFunc,ret) ) return ret try: z.__name__ = f.__name__ except AttributeError: pass return z
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_tree'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'},{'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': 'OrderedDict'},{'id': '9', 'type': 'argument_list', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '12', 'type': 'argument_list', 'children': ['13', '35']},{'id': '13', 'type': 'list_comprehension', 'children': ['14', '26']},{'id': '14', 'type': 'tuple', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'v'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '30']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'lambda', 'children': ['38', '40']},{'id': '38', 'type': 'lambda_parameters', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'}
def sorted_tree(tree): return OrderedDict(sorted([(k, sorted(v, key=attrgetter('key'))) for k, v in tree.items()], key=lambda kv: kv[0].key))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '31']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'make_attrgetter'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'postprocess'},{'id': '26', 'type': 'conditional_expression', 'children': ['27', '28', '30'], 'value': 'if'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ignore_case'},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '39']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def do_sort( environment, value, reverse=False, case_sensitive=False, attribute=None ): key_func = make_attrgetter( environment, attribute, postprocess=ignore_case if not case_sensitive else None ) return sorted(value, key=key_func, reverse=reverse)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'wantdirs'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '62', '71', '101']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '14']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'add_dir'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '14', 'type': 'block', 'children': ['15', '22', '30']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': "'add_dir added %s'"},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '30', 'type': 'if_statement', 'children': ['31', '36']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '!='},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '36', 'type': 'block', 'children': ['37', '50', '56']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '42']},{'id': '39', 'type': 'pattern_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '50', 'type': 'assert_statement', 'children': ['51']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'not'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '53', 'type': 'tuple', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "''"},{'id': '55', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_dir'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '71', 'type': 'if_statement', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'wantdirs'},{'id': '73', 'type': 'block', 'children': ['74', '80', '97']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'add_dir'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'augmented_assignment', 'children': ['99', '100'], 'value': '|='},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'list_comprehension', 'children': ['103', '112']},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'list_splat', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'path_tuple'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'path_tuple'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '116', 'type': 'generator_expression', 'children': ['117', '125']},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'result'}
def sorted(self, wantdirs=False): def add_dir(dirs, d): dirs.add(d) logger.debug('add_dir added %s', d) if d != self.base: parent, _ = os.path.split(d) assert parent not in ('', '/') add_dir(dirs, parent) result = set(self.files) if wantdirs: dirs = set() for f in result: add_dir(dirs, os.path.dirname(f)) result |= dirs return [os.path.join(*path_tuple) for path_tuple in sorted(os.path.split(path) for path in result)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'next_event_indexer'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'all_dates'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'all_sids'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'event_dates'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'event_timestamps'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'event_sids'},{'id': '10', 'type': 'block', 'children': ['11', '18', '42', '51', '63', '75', '115']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'validate_event_metadata'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'event_dates'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'event_timestamps'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'event_sids'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '25', 'type': 'argument_list', 'children': ['26', '35', '37']},{'id': '26', 'type': 'tuple', 'children': ['27', '31']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'all_dates'},{'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': 'all_sids'},{'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sid_ixs'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'all_sids'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'event_sids'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'dt_ixs'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'all_dates'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'event_dates'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '62', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ts_ixs'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'event_timestamps'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '74', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '90']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '79', 'type': 'argument_list', 'children': ['80', '86', '88']},{'id': '80', 'type': 'binary_operator', 'children': ['81', '85'], 'value': '-'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'event_sids'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '-'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'unary_operator', 'children': ['89'], 'value': '-'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'block', 'children': ['91', '97', '103']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'start_ix'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ts_ixs'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'end_ix'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dt_ixs'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '114']},{'id': '105', 'type': 'subscript', 'children': ['106', '107', '111']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '107', 'type': 'slice', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'start_ix'},{'id': '109', 'type': 'colon', 'children': []},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'end_ix'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sid_ixs'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '115', 'type': 'return_statement', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'out'}
def next_event_indexer(all_dates, data_query_cutoff, all_sids, event_dates, event_timestamps, event_sids): validate_event_metadata(event_dates, event_timestamps, event_sids) out = np.full((len(all_dates), len(all_sids)), -1, dtype=np.int64) sid_ixs = all_sids.searchsorted(event_sids) dt_ixs = all_dates.searchsorted(event_dates, side='right') ts_ixs = data_query_cutoff.searchsorted(event_timestamps, side='right') for i in range(len(event_sids) - 1, -1, -1): start_ix = ts_ixs[i] end_ix = dt_ixs[i] out[start_ix:end_ix, sid_ixs[i]] = i return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'previous_event_indexer'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'all_sids'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'event_dates'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'event_timestamps'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'event_sids'},{'id': '9', 'type': 'block', 'children': ['10', '17', '41', '51', '60', '72', '76', '126']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'validate_event_metadata'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'event_dates'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'event_timestamps'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'event_sids'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'out'},{'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': 'full'},{'id': '24', 'type': 'argument_list', 'children': ['25', '34', '36']},{'id': '25', 'type': 'tuple', 'children': ['26', '30']},{'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': 'data_query_cutoff_times'},{'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': 'all_sids'},{'id': '34', 'type': 'unary_operator', 'children': ['35'], 'value': '-'},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'eff_dts'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'maximum'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'event_dates'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'event_timestamps'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sid_ixs'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'all_sids'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'event_sids'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'dt_ixs'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'eff_dts'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '71', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'last_written'},{'id': '75', 'type': 'dictionary', 'children': []},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '91']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '80', 'type': 'argument_list', 'children': ['81', '87', '89']},{'id': '81', 'type': 'binary_operator', 'children': ['82', '86'], 'value': '-'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'event_dates'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'unary_operator', 'children': ['90'], 'value': '-'},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'block', 'children': ['92', '98', '104', '120']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sid_ix'},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sid_ixs'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'dt_ix'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'dt_ixs'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '119']},{'id': '106', 'type': 'subscript', 'children': ['107', '108', '118']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '108', 'type': 'slice', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'dt_ix'},{'id': '110', 'type': 'colon', 'children': []},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'last_written'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sid_ix'},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'sid_ix'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'last_written'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'sid_ix'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dt_ix'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'out'}
def previous_event_indexer(data_query_cutoff_times, all_sids, event_dates, event_timestamps, event_sids): validate_event_metadata(event_dates, event_timestamps, event_sids) out = np.full( (len(data_query_cutoff_times), len(all_sids)), -1, dtype=np.int64, ) eff_dts = np.maximum(event_dates, event_timestamps) sid_ixs = all_sids.searchsorted(event_sids) dt_ixs = data_query_cutoff_times.searchsorted(eff_dts, side='right') last_written = {} for i in range(len(event_dates) - 1, -1, -1): sid_ix = sid_ixs[i] dt_ix = dt_ixs[i] out[dt_ix:last_written.get(sid_ix, None), sid_ix] = i last_written[sid_ix] = dt_ix return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'last_in_date_group'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'assets'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'have_sids'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'extra_groupers'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '33', '41', '50', '54', '78', '100', '167']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '20', 'type': 'list', 'children': ['21'], 'value': '[data_query_cutoff_times[data_query_cutoff_times.searchsorted(\n df[TS_FIELD_NAME].values,\n )]]'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'TS_FIELD_NAME'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '33', 'type': 'if_statement', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'have_sids'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'augmented_assignment', 'children': ['38', '39'], 'value': '+='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '39', 'type': 'list', 'children': ['40'], 'value': '[SID_FIELD_NAME]'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'SID_FIELD_NAME'},{'id': '41', 'type': 'if_statement', 'children': ['42', '45']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'extra_groupers'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'extra_groupers'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'augmented_assignment', 'children': ['52', '53'], 'value': '+='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'extra_groupers'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '57', 'type': 'call', 'children': ['58', '77']},{'id': '58', 'type': 'attribute', 'children': ['59', '76']},{'id': '59', 'type': 'call', 'children': ['60', '71']},{'id': '60', 'type': 'attribute', 'children': ['61', '70']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'TS_FIELD_NAME'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '75', 'type': 'False', 'children': []},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '89']},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '88'], 'value': '-'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'unstack'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'unary_operator', 'children': ['99'], 'value': '-'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'if_statement', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'if_statement', 'children': ['104', '105', '156']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'have_sids'},{'id': '105', 'type': 'block', 'children': ['106', '112']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '119', 'type': 'argument_list', 'children': ['120', '123']},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'from_product'},{'id': '131', 'type': 'argument_list', 'children': ['132', '151']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '149'], 'value': '+'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'subscript', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '140', 'type': 'slice', 'children': ['141', '142', '143']},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'colon', 'children': []},{'id': '143', 'type': 'binary_operator', 'children': ['144', '148'], 'value': '+'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'extra_groupers'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'tuple', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'assets'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'last_in_group'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'last_in_group'}
def last_in_date_group(df, data_query_cutoff_times, assets, reindex=True, have_sids=True, extra_groupers=None): idx = [data_query_cutoff_times[data_query_cutoff_times.searchsorted( df[TS_FIELD_NAME].values, )]] if have_sids: idx += [SID_FIELD_NAME] if extra_groupers is None: extra_groupers = [] idx += extra_groupers last_in_group = df.drop(TS_FIELD_NAME, axis=1).groupby( idx, sort=False, ).last() for _ in range(len(idx) - 1): last_in_group = last_in_group.unstack(-1) if reindex: if have_sids: cols = last_in_group.columns last_in_group = last_in_group.reindex( index=data_query_cutoff_times, columns=pd.MultiIndex.from_product( tuple(cols.levels[0:len(extra_groupers) + 1]) + (assets,), names=cols.names, ), ) else: last_in_group = last_in_group.reindex(data_query_cutoff_times) return last_in_group
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'risk_metric_period'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_session'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'end_session'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'algorithm_leverages'},{'id': '10', 'type': 'block', 'children': ['11', '29', '52', '66', '80', '96', '105', '117', '138', '213']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '23'], 'value': '&'},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '>='},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'start_session'},{'id': '23', 'type': '()', 'children': ['24']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '<='},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'end_session'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '41'], 'value': '&'},{'id': '35', 'type': '()', 'children': ['36']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '>='},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'start_session'},{'id': '41', 'type': '()', 'children': ['42']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': '<='},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '46', 'type': 'subscript', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'benchmark_period_returns'},{'id': '55', 'type': 'subscript', 'children': ['56', '64']},{'id': '56', 'type': 'attribute', 'children': ['57', '63']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'cum_returns'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '64', 'type': 'unary_operator', 'children': ['65'], 'value': '-'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'algorithm_period_returns'},{'id': '69', 'type': 'subscript', 'children': ['70', '78']},{'id': '70', 'type': 'attribute', 'children': ['71', '77']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cum_returns'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '78', 'type': 'unary_operator', 'children': ['79'], 'value': '-'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'alpha_beta_aligned'},{'id': '89', 'type': 'argument_list', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sharpe'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sharpe_ratio'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '105', 'type': 'if_statement', 'children': ['106', '112']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sharpe'},{'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': 'sharpe'},{'id': '116', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'sortino'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sortino_ratio'},{'id': '124', 'type': 'argument_list', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_downside_risk'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'downside_risk'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'rval'},{'id': '141', 'type': 'dictionary', 'children': ['142', '145', '148', '151', '154', '157', '160', '163', '166', '174', '180', '188', '196', '206']},{'id': '142', 'type': 'pair', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'algorithm_period_return'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'algorithm_period_returns'},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'benchmark_period_return'"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'benchmark_period_returns'},{'id': '148', 'type': 'pair', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': "'treasury_period_return'"},{'id': '150', 'type': 'integer', 'children': [], 'value': '0'},{'id': '151', 'type': 'pair', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': "'excess_return'"},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'algorithm_period_returns'},{'id': '154', 'type': 'pair', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': "'alpha'"},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '157', 'type': 'pair', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'beta'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '160', 'type': 'pair', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "'sharpe'"},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sharpe'},{'id': '163', 'type': 'pair', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': "'sortino'"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sortino'},{'id': '166', 'type': 'pair', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "'period_label'"},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'end_session'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'string', 'children': [], 'value': '"%Y-%m"'},{'id': '174', 'type': 'pair', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': "'trading_days'"},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '180', 'type': 'pair', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "'algo_volatility'"},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'annual_volatility'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '188', 'type': 'pair', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "'benchmark_volatility'"},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'annual_volatility'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'benchmark_returns'},{'id': '196', 'type': 'pair', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': "'max_drawdown'"},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'max_drawdown'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'algorithm_returns'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '206', 'type': 'pair', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': "'max_leverage'"},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'algorithm_leverages'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'return_statement', 'children': ['214']},{'id': '214', 'type': 'dictionary_comprehension', 'children': ['215', '232']},{'id': '215', 'type': 'pair', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '217', 'type': '()', 'children': ['218']},{'id': '218', 'type': 'conditional_expression', 'children': ['219', '220', '231'], 'value': 'if'},{'id': '219', 'type': 'None', 'children': []},{'id': '220', 'type': 'boolean_operator', 'children': ['221', '224'], 'value': 'and'},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': '!='},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '223', 'type': 'string', 'children': [], 'value': "'period_label'"},{'id': '224', 'type': 'not_operator', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'isfinite'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '232', 'type': 'for_in_clause', 'children': ['233', '236']},{'id': '233', 'type': 'pattern_list', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'rval'}
def risk_metric_period(cls, start_session, end_session, algorithm_returns, benchmark_returns, algorithm_leverages): algorithm_returns = algorithm_returns[ (algorithm_returns.index >= start_session) & (algorithm_returns.index <= end_session) ] benchmark_returns = benchmark_returns[ (benchmark_returns.index >= start_session) & (benchmark_returns.index <= algorithm_returns.index[-1]) ] benchmark_period_returns = ep.cum_returns(benchmark_returns).iloc[-1] algorithm_period_returns = ep.cum_returns(algorithm_returns).iloc[-1] alpha, beta = ep.alpha_beta_aligned( algorithm_returns.values, benchmark_returns.values, ) sharpe = ep.sharpe_ratio(algorithm_returns) if pd.isnull(sharpe): sharpe = 0.0 sortino = ep.sortino_ratio( algorithm_returns.values, _downside_risk=ep.downside_risk(algorithm_returns.values), ) rval = { 'algorithm_period_return': algorithm_period_returns, 'benchmark_period_return': benchmark_period_returns, 'treasury_period_return': 0, 'excess_return': algorithm_period_returns, 'alpha': alpha, 'beta': beta, 'sharpe': sharpe, 'sortino': sortino, 'period_label': end_session.strftime("%Y-%m"), 'trading_days': len(benchmark_returns), 'algo_volatility': ep.annual_volatility(algorithm_returns), 'benchmark_volatility': ep.annual_volatility(benchmark_returns), 'max_drawdown': ep.max_drawdown(algorithm_returns.values), 'max_leverage': algorithm_leverages.max(), } return { k: ( None if k != 'period_label' and not np.isfinite(v) else v ) for k, v in iteritems(rval) }
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_last_data_per_qtr'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'assets_with_data'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '9', 'type': 'block', 'children': ['10', '28', '34', '43', '54', '69', '78', '91']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'last_per_qtr'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'last_in_date_group'},{'id': '15', 'type': 'argument_list', 'children': ['16', '19', '20', '21', '24']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'estimates'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'data_query_cutoff_times'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'assets_with_data'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'extra_groupers'},{'id': '26', 'type': 'list', 'children': ['27'], 'value': '[NORMALIZED_QUARTERS]'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'NORMALIZED_QUARTERS'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'last_per_qtr'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ffill_across_cols'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'last_per_qtr'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name_map'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'last_per_qtr'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'list', 'children': ['52', '53'], 'value': '[SID_FIELD_NAME, NORMALIZED_QUARTERS]'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'SID_FIELD_NAME'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'NORMALIZED_QUARTERS'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'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': 'stacked_last_per_qtr'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'set_names'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63', '66']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'SIMULATION_DATES'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '68', 'type': 'True', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'EVENT_DATE_FIELD_NAME'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'EVENT_DATE_FIELD_NAME'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'to_datetime'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'EVENT_DATE_FIELD_NAME'},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'expression_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'last_per_qtr'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'}
def get_last_data_per_qtr(self, assets_with_data, columns, dates, data_query_cutoff_times): last_per_qtr = last_in_date_group( self.estimates, data_query_cutoff_times, assets_with_data, reindex=True, extra_groupers=[NORMALIZED_QUARTERS], ) last_per_qtr.index = dates ffill_across_cols(last_per_qtr, columns, self.name_map) stacked_last_per_qtr = last_per_qtr.stack( [SID_FIELD_NAME, NORMALIZED_QUARTERS], ) stacked_last_per_qtr.index.set_names( SIMULATION_DATES, level=0, inplace=True, ) stacked_last_per_qtr = stacked_last_per_qtr.sort_values( EVENT_DATE_FIELD_NAME, ) stacked_last_per_qtr[EVENT_DATE_FIELD_NAME] = pd.to_datetime( stacked_last_per_qtr[EVENT_DATE_FIELD_NAME] ) return last_per_qtr, stacked_last_per_qtr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_zeroth_quarter_idx'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '6', 'type': 'block', 'children': ['7', '44']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'previous_releases_per_date'},{'id': '10', 'type': 'call', 'children': ['11', '41']},{'id': '11', 'type': 'attribute', 'children': ['12', '40']},{'id': '12', 'type': 'call', 'children': ['13', '31']},{'id': '13', 'type': 'attribute', 'children': ['14', '30']},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '<='},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'stacked_last_per_qtr'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'EVENT_DATE_FIELD_NAME'},{'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': 'stacked_last_per_qtr'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_level_values'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'SIMULATION_DATES'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '31', 'type': 'argument_list', 'children': ['32', '37']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '34', 'type': 'list', 'children': ['35', '36'], 'value': '[SIMULATION_DATES, SID_FIELD_NAME]'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'SIMULATION_DATES'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'SID_FIELD_NAME'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'as_index'},{'id': '39', 'type': 'False', 'children': []},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nth'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'previous_releases_per_date'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'index'}
def get_zeroth_quarter_idx(self, stacked_last_per_qtr): previous_releases_per_date = stacked_last_per_qtr.loc[ stacked_last_per_qtr[EVENT_DATE_FIELD_NAME] <= stacked_last_per_qtr.index.get_level_values(SIMULATION_DATES) ].groupby( level=[SIMULATION_DATES, SID_FIELD_NAME], as_index=False, ).nth(-1) return previous_releases_per_date.index
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '7', 'type': 'string', 'children': [], 'value': "'ordinal'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'NotSpecified'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'NotSpecified'},{'id': '17', 'type': 'block', 'children': ['18', '37']},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'NotSpecified'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Rank'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '31', '34']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'GroupedRowTransform'},{'id': '40', 'type': 'argument_list', 'children': ['41', '47', '51', '54', '57', '60', '63', '66']},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'transform'},{'id': '43', 'type': 'conditional_expression', 'children': ['44', '45', '46'], 'value': 'if'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'rankdata'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'rankdata_1d_descending'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'transform_args'},{'id': '49', 'type': 'tuple', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'float64_dtype'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'missing_value'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'window_safe'},{'id': '68', 'type': 'True', 'children': []}
def rank(self, method='ordinal', ascending=True, mask=NotSpecified, groupby=NotSpecified): if groupby is NotSpecified: return Rank(self, method=method, ascending=ascending, mask=mask) return GroupedRowTransform( transform=rankdata if ascending else rankdata_1d_descending, transform_args=(method,), factor=self, groupby=groupby, dtype=float64_dtype, missing_value=nan, mask=mask, window_safe=True, )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_in_sorted_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '6', 'type': 'block', 'children': ['7', '16', '45']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '16', 'type': 'if_statement', 'children': ['17', '29']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '24'], 'value': 'or'},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '!='},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'LookupError'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': '"{dt} is not in {dts}"'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '38', 'type': 'argument_list', 'children': ['39', '42']},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ix'}
def find_in_sorted_index(dts, dt): ix = dts.searchsorted(dt) if ix == len(dts) or dts[ix] != dt: raise LookupError("{dt} is not in {dts}".format(dt=dt, dts=dts)) return ix
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nearest_unequal_elements'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '6', 'type': 'block', 'children': ['7', '18', '29', '40', '52', '70', '114', '125', '139']},{'id': '7', 'type': 'if_statement', 'children': ['8', '12']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'is_unique'},{'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': 'string', 'children': [], 'value': '"dts must be unique"'},{'id': '18', 'type': 'if_statement', 'children': ['19', '23']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'is_monotonic_increasing'},{'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': 'string', 'children': [], 'value': '"dts must be sorted in increasing order"'},{'id': '29', 'type': 'if_statement', 'children': ['30', '35']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'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': 'dts'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'expression_list', 'children': ['38', '39']},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '51', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '52', 'type': 'try_statement', 'children': ['53', '60']},{'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': 'sortval'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '60', 'type': 'except_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'expression_list', 'children': ['65', '69']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '67', 'type': 'unary_operator', 'children': ['68'], 'value': '-'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'if_statement', 'children': ['71', '74', '85', '102']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '<'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sortval'},{'id': '74', 'type': 'block', 'children': ['75', '81']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'lower_ix'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '-'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'upper_ix'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '85', 'type': 'elif_clause', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '=='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sortval'},{'id': '89', 'type': 'block', 'children': ['90', '96']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'lower_ix'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '-'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'upper_ix'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'else_clause', 'children': ['103']},{'id': '103', 'type': 'block', 'children': ['104', '108']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'lower_ix'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'upper_ix'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '+'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sortpos'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'lower_value'},{'id': '117', 'type': 'conditional_expression', 'children': ['118', '121', '124'], 'value': 'if'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lower_ix'},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': '>='},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'lower_ix'},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'None', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'upper_value'},{'id': '128', 'type': 'conditional_expression', 'children': ['129', '132', '138'], 'value': 'if'},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'upper_ix'},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '<'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'upper_ix'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'dts'},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'expression_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'lower_value'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'upper_value'}
def nearest_unequal_elements(dts, dt): if not dts.is_unique: raise ValueError("dts must be unique") if not dts.is_monotonic_increasing: raise ValueError("dts must be sorted in increasing order") if not len(dts): return None, None sortpos = dts.searchsorted(dt, side='left') try: sortval = dts[sortpos] except IndexError: return dts[-1], None if dt < sortval: lower_ix = sortpos - 1 upper_ix = sortpos elif dt == sortval: lower_ix = sortpos - 1 upper_ix = sortpos + 1 else: lower_ix = sortpos upper_ix = sortpos + 1 lower_value = dts[lower_ix] if lower_ix >= 0 else None upper_value = dts[upper_ix] if upper_ix < len(dts) else None return lower_value, upper_value
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'date_sorted_sources'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '6', 'type': 'block', 'children': ['7', '24']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_stream'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'list_splat', 'children': ['16']},{'id': '16', 'type': 'generator_expression', 'children': ['17', '21']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_decorate_source'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '24', 'type': 'for_statement', 'children': ['25', '28', '29']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted_stream'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'yield', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'message'}
def date_sorted_sources(*sources): sorted_stream = heapq.merge(*(_decorate_source(s) for s in sources)) for _, message in sorted_stream: yield message
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execution_order'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'refcounts'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'topological_sort'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'subgraph'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'set_comprehension', 'children': ['24', '25', '34']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '25', 'type': 'for_in_clause', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'refcount'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'refcounts'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'if_clause', 'children': ['35']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '>'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'refcount'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'}
def execution_order(self, refcounts): return iter(nx.topological_sort( self.graph.subgraph( {term for term, refcount in refcounts.items() if refcount > 0}, ), ))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '"HTTPHeaders"'},{'id': '11', 'type': 'block', 'children': ['12', '18', '37']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '26']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_CRLF_RE'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'if_statement', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parse_line'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'h'}
def parse(cls, headers: str) -> "HTTPHeaders": h = cls() for line in _CRLF_RE.split(headers): if line: h.parse_line(line) return h
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lovasz_grad'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'gt_sorted'},{'id': '5', 'type': 'block', 'children': ['6', '13', '21', '36', '54', '62', '89']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'gt_sorted'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'gts'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'gt_sorted'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '-'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'gts'},{'id': '26', 'type': 'call', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'gt_sorted'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cumsum'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '+'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'gts'},{'id': '41', 'type': 'call', 'children': ['42', '52']},{'id': '42', 'type': 'attribute', 'children': ['43', '51']},{'id': '43', 'type': 'call', 'children': ['44', '50']},{'id': '44', 'type': 'attribute', 'children': ['45', '49']},{'id': '45', 'type': '()', 'children': ['46']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '-'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'gt_sorted'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cumsum'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'jaccard'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'},{'id': '58', 'type': 'float', 'children': [], 'value': '1.'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '/'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '62', 'type': 'if_statement', 'children': ['63', '66']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '75']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'jaccard'},{'id': '71', 'type': 'slice', 'children': ['72', '73', '74']},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'colon', 'children': []},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '75', 'type': 'binary_operator', 'children': ['76', '82'], 'value': '-'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'jaccard'},{'id': '78', 'type': 'slice', 'children': ['79', '80', '81']},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'colon', 'children': []},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'jaccard'},{'id': '84', 'type': 'slice', 'children': ['85', '86', '87']},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'colon', 'children': []},{'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'jaccard'}
def lovasz_grad(gt_sorted): p = len(gt_sorted) gts = gt_sorted.sum() intersection = gts - gt_sorted.float().cumsum(0) union = gts + (1 - gt_sorted).float().cumsum(0) jaccard = 1. - intersection / union if p > 1: jaccard[1:p] = jaccard[1:p] - jaccard[0:-1] return jaccard
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '41']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '32', '35', '38']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '8', 'type': 'string', 'children': [], 'value': '"inner"'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'left_on'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'right_on'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'left_index'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'right_index'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '26', 'type': 'False', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '29', 'type': 'tuple', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': '"_x"'},{'id': '31', 'type': 'string', 'children': [], 'value': '"_y"'},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '63']},{'id': '42', 'type': 'if_statement', 'children': ['43', '49']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'raise_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': '"can not merge DataFrame with instance of type {}"'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70', '73', '76', '79', '82', '85', '88', '91', '94', '97', '100']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'left_on'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'left_on'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'right_on'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'right_on'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'left_index'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'left_index'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'right_index'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'right_index'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'validate'}
def merge( left, right, how="inner", on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=("_x", "_y"), copy=True, indicator=False, validate=None, ): if not isinstance(left, DataFrame): raise ValueError( "can not merge DataFrame with instance of type {}".format(type(right)) ) return left.merge( right, how=how, on=on, left_on=left_on, right_on=right_on, left_index=left_index, right_index=right_index, sort=sort, suffixes=suffixes, copy=copy, indicator=indicator, validate=validate, )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'copartition'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'how_to_join'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'force_repartition'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '28', '50', '66', '79', '83', '89', '93', '180', '284']},{'id': '13', 'type': 'if_statement', 'children': ['14', '22']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'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': 'other'},{'id': '26', 'type': 'list', 'children': ['27'], 'value': '[other]'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'index_obj'},{'id': '31', 'type': '()', 'children': ['32']},{'id': '32', 'type': 'conditional_expression', 'children': ['33', '40', '43'], 'value': 'if'},{'id': '33', 'type': 'list_comprehension', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'list_comprehension', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'joined_index'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_join_index_objects'},{'id': '57', 'type': 'argument_list', 'children': ['58', '61', '62', '63']},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '^'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'index_obj'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'how_to_join'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'left_old_idx'},{'id': '69', 'type': 'conditional_expression', 'children': ['70', '73', '76'], 'value': 'if'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '=='},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'right_old_idxes'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'index_obj'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'reindexed_self'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'reindexed_other_list'},{'id': '92', 'type': 'list', 'children': [], 'value': '[]'},{'id': '93', 'type': 'function_definition', 'children': ['94', '95', '97']},{'id': '94', 'type': 'function_name', 'children': [], 'value': 'compute_reindex'},{'id': '95', 'type': 'parameters', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'old_idx'},{'id': '97', 'type': 'block', 'children': ['98', '178']},{'id': '98', 'type': 'function_definition', 'children': ['99', '100', '102']},{'id': '99', 'type': 'function_name', 'children': [], 'value': 'reindex_partition'},{'id': '100', 'type': 'parameters', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '102', 'type': 'block', 'children': ['103', '176']},{'id': '103', 'type': 'if_statement', 'children': ['104', '107', '141']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '106', 'type': 'integer', 'children': [], 'value': '0'},{'id': '107', 'type': 'block', 'children': ['108', '114', '125']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'old_idx'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'new_df'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'joined_index'},{'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': 'new_df'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'RangeIndex'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'new_df'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '141', 'type': 'else_clause', 'children': ['142']},{'id': '142', 'type': 'block', 'children': ['143', '149', '160']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'old_idx'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'new_df'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'joined_index'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'new_df'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'RangeIndex'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'new_df'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'new_df'},{'id': '178', 'type': 'return_statement', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'reindex_partition'},{'id': '180', 'type': 'for_statement', 'children': ['181', '182', '189']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '189', 'type': 'block', 'children': ['190', '224', '259', '277']},{'id': '190', 'type': 'if_statement', 'children': ['191', '205', '210']},{'id': '191', 'type': 'boolean_operator', 'children': ['192', '195'], 'value': 'or'},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '!='},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '194', 'type': 'integer', 'children': [], 'value': '0'},{'id': '195', 'type': '()', 'children': ['196']},{'id': '196', 'type': 'boolean_operator', 'children': ['197', '203'], 'value': 'and'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'left_old_idx'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'joined_index'},{'id': '203', 'type': 'not_operator', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'force_repartition'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'reindex_left'},{'id': '209', 'type': 'None', 'children': []},{'id': '210', 'type': 'else_clause', 'children': ['211']},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'reindex_left'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '218', 'type': 'identifier', 'children': [], 'value': '_prepare_method'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'compute_reindex'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'left_old_idx'},{'id': '224', 'type': 'if_statement', 'children': ['225', '236', '241']},{'id': '225', 'type': 'boolean_operator', 'children': ['226', '234'], 'value': 'and'},{'id': '226', 'type': 'call', 'children': ['227', '232']},{'id': '227', 'type': 'attribute', 'children': ['228', '231']},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'right_old_idxes'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'joined_index'},{'id': '234', 'type': 'not_operator', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'force_repartition'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'reindex_right'},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'else_clause', 'children': ['242']},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'reindex_right'},{'id': '246', 'type': 'call', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '251', 'type': 'identifier', 'children': [], 'value': '_prepare_method'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'compute_reindex'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'right_old_idxes'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '264']},{'id': '261', 'type': 'pattern_list', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'reindexed_self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'reindexed_other'},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'reindexed_self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'copartition_datasets'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270', '275', '276']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '270', 'type': 'attribute', 'children': ['271', '274']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'reindex_left'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'reindex_right'},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'reindexed_other_list'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'reindexed_other'},{'id': '284', 'type': 'return_statement', 'children': ['285']},{'id': '285', 'type': 'expression_list', 'children': ['286', '287', '288']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'reindexed_self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'reindexed_other_list'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'joined_index'}
def copartition(self, axis, other, how_to_join, sort, force_repartition=False): if isinstance(other, type(self)): other = [other] index_obj = ( [o.index for o in other] if axis == 0 else [o.columns for o in other] ) joined_index = self._join_index_objects( axis ^ 1, index_obj, how_to_join, sort=sort ) left_old_idx = self.index if axis == 0 else self.columns right_old_idxes = index_obj reindexed_self = self.data reindexed_other_list = [] def compute_reindex(old_idx): def reindex_partition(df): if axis == 0: df.index = old_idx new_df = df.reindex(index=joined_index) new_df.index = pandas.RangeIndex(len(new_df.index)) else: df.columns = old_idx new_df = df.reindex(columns=joined_index) new_df.columns = pandas.RangeIndex(len(new_df.columns)) return new_df return reindex_partition for i in range(len(other)): if i != 0 or (left_old_idx.equals(joined_index) and not force_repartition): reindex_left = None else: reindex_left = self._prepare_method(compute_reindex(left_old_idx)) if right_old_idxes[i].equals(joined_index) and not force_repartition: reindex_right = None else: reindex_right = other[i]._prepare_method( compute_reindex(right_old_idxes[i]) ) reindexed_self, reindexed_other = reindexed_self.copartition_datasets( axis, other[i].data, reindex_left, reindex_right ) reindexed_other_list.append(reindexed_other) return reindexed_self, reindexed_other_list, joined_index
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '18', '29', '39', '48', '54', '89', '100', '110', '161']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': '"axis"'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '21', 'type': 'conditional_expression', 'children': ['22', '25', '26'], 'value': 'if'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': '"ascending"'},{'id': '38', 'type': 'True', 'children': []},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '47', 'type': 'False', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '52', 'type': 'string', 'children': [], 'value': '"ascending"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '54', 'type': 'function_definition', 'children': ['55', '56', '60']},{'id': '55', 'type': 'function_name', 'children': [], 'value': 'sort_index_builder'},{'id': '56', 'type': 'parameters', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '58', 'type': 'dictionary_splat_pattern', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '60', 'type': 'block', 'children': ['61', '78']},{'id': '61', 'type': 'if_statement', 'children': ['62', '63', '70']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', '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': 'identifier', 'children': [], 'value': 'index'},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '83', 'type': 'argument_list', 'children': ['84', '87']},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '87', 'type': 'dictionary_splat', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_prepare_method'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort_index_builder'},{'id': '98', 'type': 'dictionary_splat', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'new_data'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_map_across_full_axis'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '110', 'type': 'if_statement', 'children': ['111', '112', '136']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '112', 'type': 'block', 'children': ['113', '130']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'new_columns'},{'id': '116', 'type': 'call', 'children': ['117', '127']},{'id': '117', 'type': 'attribute', 'children': ['118', '126']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'Series'},{'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': 'columns'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'dictionary_splat', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138', '155']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '141', 'type': 'call', 'children': ['142', '152']},{'id': '142', 'type': 'attribute', 'children': ['143', '151']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'dictionary_splat', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'new_columns'},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': '__constructor__'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169', '170']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'new_data'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'new_columns'},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'dtypes'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '176', 'type': 'argument_list', 'children': []}
def sort_index(self, **kwargs): axis = kwargs.pop("axis", 0) index = self.columns if axis else self.index ascending = kwargs.pop("ascending", True) if ascending is None: ascending = False kwargs["ascending"] = ascending def sort_index_builder(df, **kwargs): if axis: df.columns = index else: df.index = index return df.sort_index(axis=axis, **kwargs) func = self._prepare_method(sort_index_builder, **kwargs) new_data = self._map_across_full_axis(axis, func) if axis: new_columns = pandas.Series(self.columns).sort_values(**kwargs) new_index = self.index else: new_index = pandas.Series(self.index).sort_values(**kwargs) new_columns = self.columns return self.__constructor__( new_data, new_index, new_columns, self.dtypes.copy() )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sample_row_keys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '32']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data_client'},{'id': '9', 'type': 'attribute', 'children': ['10', '15']},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_instance'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'table_data_client'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'response_iterator'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data_client'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sample_row_keys'},{'id': '23', 'type': 'argument_list', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'app_profile_id'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_app_profile_id'},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'response_iterator'}
def sample_row_keys(self): data_client = self._instance._client.table_data_client response_iterator = data_client.sample_row_keys( self.name, app_profile_id=self._app_profile_id ) return response_iterator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '53']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_profiles'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '39', '50']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'request_metadata'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'profile_query'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'disable_spell_check'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'case_sensitive_sort'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'histogram_queries'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '30', 'type': 'attribute', 'children': ['31', '38']},{'id': '31', 'type': 'attribute', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '39', 'type': 'default_parameter', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '41', 'type': 'attribute', 'children': ['42', '49']},{'id': '42', 'type': 'attribute', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '50', 'type': 'default_parameter', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'block', 'children': ['54', '107', '142', '190']},{'id': '54', 'type': 'if_statement', 'children': ['55', '60']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'not'},{'id': '56', 'type': 'string', 'children': [], 'value': '"search_profiles"'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '68']},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '67', 'type': 'string', 'children': [], 'value': '"search_profiles"'},{'id': '68', 'type': 'call', 'children': ['69', '78']},{'id': '69', 'type': 'attribute', 'children': ['70', '77']},{'id': '70', 'type': 'attribute', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'wrap_method'},{'id': '78', 'type': 'argument_list', 'children': ['79', '84', '93', '102']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'transport'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'search_profiles'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'default_retry'},{'id': '86', 'type': 'attribute', 'children': ['87', '92']},{'id': '87', 'type': 'subscript', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '91', 'type': 'string', 'children': [], 'value': '"SearchProfiles"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'default_timeout'},{'id': '95', 'type': 'attribute', 'children': ['96', '101']},{'id': '96', 'type': 'subscript', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '100', 'type': 'string', 'children': [], 'value': '"SearchProfiles"'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'client_info'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_client_info'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'profile_service_pb2'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'SearchProfilesRequest'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118', '121', '124', '127', '130', '133', '136', '139']},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'request_metadata'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'request_metadata'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'profile_query'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'profile_query'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'disable_spell_check'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'disable_spell_check'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'case_sensitive_sort'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'case_sensitive_sort'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'histogram_queries'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'histogram_queries'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '145', 'type': 'call', 'children': ['146', '153']},{'id': '146', 'type': 'attribute', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'page_iterator'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'GRPCIterator'},{'id': '153', 'type': 'argument_list', 'children': ['154', '157', '178', '181', '184', '187']},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '156', 'type': 'None', 'children': []},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '163', 'type': 'argument_list', 'children': ['164', '169', '172', '175']},{'id': '164', 'type': 'subscript', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '168', 'type': 'string', 'children': [], 'value': '"search_profiles"'},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'items_field'},{'id': '183', 'type': 'string', 'children': [], 'value': '"histogram_query_results"'},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'request_token_field'},{'id': '186', 'type': 'string', 'children': [], 'value': '"page_token"'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'response_token_field'},{'id': '189', 'type': 'string', 'children': [], 'value': '"next_page_token"'},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'iterator'}
def search_profiles( self, parent, request_metadata, profile_query=None, page_size=None, offset=None, disable_spell_check=None, order_by=None, case_sensitive_sort=None, histogram_queries=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): if "search_profiles" not in self._inner_api_calls: self._inner_api_calls[ "search_profiles" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.search_profiles, default_retry=self._method_configs["SearchProfiles"].retry, default_timeout=self._method_configs["SearchProfiles"].timeout, client_info=self._client_info, ) request = profile_service_pb2.SearchProfilesRequest( parent=parent, request_metadata=request_metadata, profile_query=profile_query, page_size=page_size, offset=offset, disable_spell_check=disable_spell_check, order_by=order_by, case_sensitive_sort=case_sensitive_sort, histogram_queries=histogram_queries, ) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["search_profiles"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="histogram_query_results", request_token_field="page_token", response_token_field="next_page_token", ) return iterator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '68']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_jobs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37', '40', '43', '54', '65']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'request_metadata'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'search_mode'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'job_query'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'enable_broadening'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'require_precise_result_size'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'histogram_queries'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'job_view'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'diversification_level'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'default_parameter', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'custom_ranking_info'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'default_parameter', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'disable_keyword_match'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'default_parameter', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '45', 'type': 'attribute', 'children': ['46', '53']},{'id': '46', 'type': 'attribute', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '54', 'type': 'default_parameter', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '56', 'type': 'attribute', 'children': ['57', '64']},{'id': '57', 'type': 'attribute', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '65', 'type': 'default_parameter', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'block', 'children': ['69', '122', '172', '220']},{'id': '69', 'type': 'if_statement', 'children': ['70', '75']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'},{'id': '71', 'type': 'string', 'children': [], 'value': '"search_jobs"'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '75', 'type': 'block', 'children': ['76']},{'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': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '82', 'type': 'string', 'children': [], 'value': '"search_jobs"'},{'id': '83', 'type': 'call', 'children': ['84', '93']},{'id': '84', 'type': 'attribute', 'children': ['85', '92']},{'id': '85', 'type': 'attribute', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'wrap_method'},{'id': '93', 'type': 'argument_list', 'children': ['94', '99', '108', '117']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'transport'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'search_jobs'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'default_retry'},{'id': '101', 'type': 'attribute', 'children': ['102', '107']},{'id': '102', 'type': 'subscript', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '106', 'type': 'string', 'children': [], 'value': '"SearchJobs"'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'default_timeout'},{'id': '110', 'type': 'attribute', 'children': ['111', '116']},{'id': '111', 'type': 'subscript', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '115', 'type': 'string', 'children': [], 'value': '"SearchJobs"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'client_info'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_client_info'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'job_service_pb2'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'SearchJobsRequest'},{'id': '129', 'type': 'argument_list', 'children': ['130', '133', '136', '139', '142', '145', '148', '151', '154', '157', '160', '163', '166', '169']},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'request_metadata'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'request_metadata'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'search_mode'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'search_mode'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'job_query'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'job_query'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'enable_broadening'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'enable_broadening'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'require_precise_result_size'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'require_precise_result_size'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'histogram_queries'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'histogram_queries'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'job_view'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'job_view'},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'diversification_level'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'diversification_level'},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'custom_ranking_info'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'custom_ranking_info'},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'disable_keyword_match'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'disable_keyword_match'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '175', 'type': 'call', 'children': ['176', '183']},{'id': '176', 'type': 'attribute', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'page_iterator'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'GRPCIterator'},{'id': '183', 'type': 'argument_list', 'children': ['184', '187', '208', '211', '214', '217']},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '193', 'type': 'argument_list', 'children': ['194', '199', '202', '205']},{'id': '194', 'type': 'subscript', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '198', 'type': 'string', 'children': [], 'value': '"search_jobs"'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'items_field'},{'id': '213', 'type': 'string', 'children': [], 'value': '"matching_jobs"'},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'request_token_field'},{'id': '216', 'type': 'string', 'children': [], 'value': '"page_token"'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'response_token_field'},{'id': '219', 'type': 'string', 'children': [], 'value': '"next_page_token"'},{'id': '220', 'type': 'return_statement', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'iterator'}
def search_jobs( self, parent, request_metadata, search_mode=None, job_query=None, enable_broadening=None, require_precise_result_size=None, histogram_queries=None, job_view=None, offset=None, page_size=None, order_by=None, diversification_level=None, custom_ranking_info=None, disable_keyword_match=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): if "search_jobs" not in self._inner_api_calls: self._inner_api_calls[ "search_jobs" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.search_jobs, default_retry=self._method_configs["SearchJobs"].retry, default_timeout=self._method_configs["SearchJobs"].timeout, client_info=self._client_info, ) request = job_service_pb2.SearchJobsRequest( parent=parent, request_metadata=request_metadata, search_mode=search_mode, job_query=job_query, enable_broadening=enable_broadening, require_precise_result_size=require_precise_result_size, histogram_queries=histogram_queries, job_view=job_view, offset=offset, page_size=page_size, order_by=order_by, diversification_level=diversification_level, custom_ranking_info=custom_ranking_info, disable_keyword_match=disable_keyword_match, ) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["search_jobs"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="matching_jobs", request_token_field="page_token", response_token_field="next_page_token", ) return iterator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '46']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_findings'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '32', '43']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'parent'},{'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': 'order_by'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'field_mask'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '23', 'type': 'attribute', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '34', 'type': 'attribute', 'children': ['35', '42']},{'id': '35', 'type': 'attribute', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '43', 'type': 'default_parameter', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47', '100', '126', '135', '142', '179', '227']},{'id': '47', 'type': 'if_statement', 'children': ['48', '53']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'not'},{'id': '49', 'type': 'string', 'children': [], 'value': '"list_findings"'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '61']},{'id': '56', 'type': 'subscript', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '60', 'type': 'string', 'children': [], 'value': '"list_findings"'},{'id': '61', 'type': 'call', 'children': ['62', '71']},{'id': '62', 'type': 'attribute', 'children': ['63', '70']},{'id': '63', 'type': 'attribute', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'wrap_method'},{'id': '71', 'type': 'argument_list', 'children': ['72', '77', '86', '95']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'transport'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'list_findings'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'default_retry'},{'id': '79', 'type': 'attribute', 'children': ['80', '85']},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '84', 'type': 'string', 'children': [], 'value': '"ListFindings"'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'default_timeout'},{'id': '88', 'type': 'attribute', 'children': ['89', '94']},{'id': '89', 'type': 'subscript', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '93', 'type': 'string', 'children': [], 'value': '"ListFindings"'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'client_info'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_client_info'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'securitycenter_service_pb2'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ListFindingsRequest'},{'id': '107', 'type': 'argument_list', 'children': ['108', '111', '114', '117', '120', '123']},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'filter_'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'field_mask'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'field_mask'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '134', 'type': 'list', 'children': [], 'value': '[]'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '142', 'type': 'try_statement', 'children': ['143', '151', '155']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '147', 'type': 'list', 'children': ['148'], 'value': '[("parent", parent)]'},{'id': '148', 'type': 'tuple', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': '"parent"'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '151', 'type': 'except_clause', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'pass_statement', 'children': []},{'id': '155', 'type': 'else_clause', 'children': ['156']},{'id': '156', 'type': 'block', 'children': ['157', '172']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'routing_metadata'},{'id': '160', 'type': 'call', 'children': ['161', '170']},{'id': '161', 'type': 'attribute', 'children': ['162', '169']},{'id': '162', 'type': 'attribute', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'to_grpc_metadata'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'routing_metadata'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '182', 'type': 'call', 'children': ['183', '190']},{'id': '183', 'type': 'attribute', 'children': ['184', '189']},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'page_iterator'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'GRPCIterator'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194', '215', '218', '221', '224']},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '193', 'type': 'None', 'children': []},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '200', 'type': 'argument_list', 'children': ['201', '206', '209', '212']},{'id': '201', 'type': 'subscript', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '205', 'type': 'string', 'children': [], 'value': '"list_findings"'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'items_field'},{'id': '220', 'type': 'string', 'children': [], 'value': '"findings"'},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'request_token_field'},{'id': '223', 'type': 'string', 'children': [], 'value': '"page_token"'},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'response_token_field'},{'id': '226', 'type': 'string', 'children': [], 'value': '"next_page_token"'},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'iterator'}
def list_findings( self, parent, filter_=None, order_by=None, read_time=None, field_mask=None, page_size=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): if "list_findings" not in self._inner_api_calls: self._inner_api_calls[ "list_findings" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.list_findings, default_retry=self._method_configs["ListFindings"].retry, default_timeout=self._method_configs["ListFindings"].timeout, client_info=self._client_info, ) request = securitycenter_service_pb2.ListFindingsRequest( parent=parent, filter=filter_, order_by=order_by, read_time=read_time, field_mask=field_mask, page_size=page_size, ) if metadata is None: metadata = [] metadata = list(metadata) try: routing_header = [("parent", parent)] except AttributeError: pass else: routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata( routing_header ) metadata.append(routing_metadata) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["list_findings"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="findings", request_token_field="page_token", response_token_field="next_page_token", ) return iterator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '49']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_traces'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '35', '46']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'project_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'filter_'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '26', 'type': 'attribute', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '37', 'type': 'attribute', 'children': ['38', '45']},{'id': '38', 'type': 'attribute', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '46', 'type': 'default_parameter', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'block', 'children': ['50', '103', '132', '141', '148', '185', '233']},{'id': '50', 'type': 'if_statement', 'children': ['51', '56']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'not'},{'id': '52', 'type': 'string', 'children': [], 'value': '"list_traces"'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '64']},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '63', 'type': 'string', 'children': [], 'value': '"list_traces"'},{'id': '64', 'type': 'call', 'children': ['65', '74']},{'id': '65', 'type': 'attribute', 'children': ['66', '73']},{'id': '66', 'type': 'attribute', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'wrap_method'},{'id': '74', 'type': 'argument_list', 'children': ['75', '80', '89', '98']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'transport'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'list_traces'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'default_retry'},{'id': '82', 'type': 'attribute', 'children': ['83', '88']},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '87', 'type': 'string', 'children': [], 'value': '"ListTraces"'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'default_timeout'},{'id': '91', 'type': 'attribute', 'children': ['92', '97']},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '96', 'type': 'string', 'children': [], 'value': '"ListTraces"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'client_info'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_client_info'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'trace_pb2'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ListTracesRequest'},{'id': '110', 'type': 'argument_list', 'children': ['111', '114', '117', '120', '123', '126', '129']},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'project_id'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'project_id'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'filter_'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '132', 'type': 'if_statement', 'children': ['133', '136']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '135', 'type': 'None', 'children': []},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '140', 'type': 'list', 'children': [], 'value': '[]'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '148', 'type': 'try_statement', 'children': ['149', '157', '161']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '153', 'type': 'list', 'children': ['154'], 'value': '[("project_id", project_id)]'},{'id': '154', 'type': 'tuple', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': '"project_id"'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'project_id'},{'id': '157', 'type': 'except_clause', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'pass_statement', 'children': []},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163', '178']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'routing_metadata'},{'id': '166', 'type': 'call', 'children': ['167', '176']},{'id': '167', 'type': 'attribute', 'children': ['168', '175']},{'id': '168', 'type': 'attribute', 'children': ['169', '174']},{'id': '169', 'type': 'attribute', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'to_grpc_metadata'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'routing_metadata'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '188', 'type': 'call', 'children': ['189', '196']},{'id': '189', 'type': 'attribute', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'page_iterator'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'GRPCIterator'},{'id': '196', 'type': 'argument_list', 'children': ['197', '200', '221', '224', '227', '230']},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '199', 'type': 'None', 'children': []},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '206', 'type': 'argument_list', 'children': ['207', '212', '215', '218']},{'id': '207', 'type': 'subscript', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '211', 'type': 'string', 'children': [], 'value': '"list_traces"'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'items_field'},{'id': '226', 'type': 'string', 'children': [], 'value': '"traces"'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'request_token_field'},{'id': '229', 'type': 'string', 'children': [], 'value': '"page_token"'},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'response_token_field'},{'id': '232', 'type': 'string', 'children': [], 'value': '"next_page_token"'},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'iterator'}
def list_traces( self, project_id, view=None, page_size=None, start_time=None, end_time=None, filter_=None, order_by=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): if "list_traces" not in self._inner_api_calls: self._inner_api_calls[ "list_traces" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.list_traces, default_retry=self._method_configs["ListTraces"].retry, default_timeout=self._method_configs["ListTraces"].timeout, client_info=self._client_info, ) request = trace_pb2.ListTracesRequest( project_id=project_id, view=view, page_size=page_size, start_time=start_time, end_time=end_time, filter=filter_, order_by=order_by, ) if metadata is None: metadata = [] metadata = list(metadata) try: routing_header = [("project_id", project_id)] except AttributeError: pass else: routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata( routing_header ) metadata.append(routing_metadata) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["list_traces"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="traces", request_token_field="page_token", response_token_field="next_page_token", ) return iterator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'order'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'block', 'children': ['7', '19']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '17', 'type': 'list', 'children': ['18'], 'value': '[value]'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '27']},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_order'},{'id': '25', 'type': 'slice', 'children': ['26']},{'id': '26', 'type': 'colon', 'children': []},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'value'}
def order(self, value): if isinstance(value, str): value = [value] self._order[:] = value
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_canonical_headers'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '5', 'type': 'block', 'children': ['6', '33', '41', '50', '91', '114', '128']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10', '15']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '9', 'type': 'None', 'children': []},{'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': 'headers'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'elif_clause', 'children': ['16', '21']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dict'},{'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': 'headers'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'if_statement', 'children': ['34', '36']},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'expression_list', 'children': ['39', '40']},{'id': '39', 'type': 'list', 'children': [], 'value': '[]'},{'id': '40', 'type': 'list', 'children': [], 'value': '[]'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'normalized'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '50', 'type': 'for_statement', 'children': ['51', '54', '55']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '55', 'type': 'block', 'children': ['56', '68', '82']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '59', 'type': 'call', 'children': ['60', '67']},{'id': '60', 'type': 'attribute', 'children': ['61', '66']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'MULTIPLE_SPACES'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': '" "'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'normalized'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ordered_headers'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '96', 'type': 'generator_expression', 'children': ['97', '105']},{'id': '97', 'type': 'tuple', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': '","'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '105', 'type': 'for_in_clause', 'children': ['106', '109']},{'id': '106', 'type': 'pattern_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'normalized'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'canonical_headers'},{'id': '117', 'type': 'list_comprehension', 'children': ['118', '125']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': '"{}:{}"'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'list_splat', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ordered_headers'},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'expression_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'canonical_headers'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ordered_headers'}
def get_canonical_headers(headers): if headers is None: headers = [] elif isinstance(headers, dict): headers = list(headers.items()) if not headers: return [], [] normalized = collections.defaultdict(list) for key, val in headers: key = key.lower().strip() val = MULTIPLE_SPACES.sub(" ", val.strip()) normalized[key].append(val) ordered_headers = sorted((key, ",".join(val)) for key, val in normalized.items()) canonical_headers = ["{}:{}".format(*item) for item in ordered_headers] return canonical_headers, ordered_headers
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_resource_labels'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '5', 'type': 'block', 'children': ['6', '18', '32']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '11', '14']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '11', 'type': 'for_in_clause', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'TOP_RESOURCE_LABELS'},{'id': '14', 'type': 'if_clause', 'children': ['15']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '23', 'type': 'generator_expression', 'children': ['24', '25', '28']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '28', 'type': 'if_clause', 'children': ['29']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'not'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'TOP_RESOURCE_LABELS'},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '+'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tail'}
def _sorted_resource_labels(labels): head = [label for label in TOP_RESOURCE_LABELS if label in labels] tail = sorted(label for label in labels if label not in TOP_RESOURCE_LABELS) return head + tail
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '45']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'partition_read'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20', '31', '42']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key_set'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'partition_options'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '22', 'type': 'attribute', 'children': ['23', '30']},{'id': '23', 'type': 'attribute', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '33', 'type': 'attribute', 'children': ['34', '41']},{'id': '34', 'type': 'attribute', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '42', 'type': 'default_parameter', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '99', '128', '137', '144', '181']},{'id': '46', 'type': 'if_statement', 'children': ['47', '52']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'},{'id': '48', 'type': 'string', 'children': [], 'value': '"partition_read"'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '60']},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '59', 'type': 'string', 'children': [], 'value': '"partition_read"'},{'id': '60', 'type': 'call', 'children': ['61', '70']},{'id': '61', 'type': 'attribute', 'children': ['62', '69']},{'id': '62', 'type': 'attribute', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'wrap_method'},{'id': '70', 'type': 'argument_list', 'children': ['71', '76', '85', '94']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'transport'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'partition_read'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'default_retry'},{'id': '78', 'type': 'attribute', 'children': ['79', '84']},{'id': '79', 'type': 'subscript', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '83', 'type': 'string', 'children': [], 'value': '"PartitionRead"'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'default_timeout'},{'id': '87', 'type': 'attribute', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '92', 'type': 'string', 'children': [], 'value': '"PartitionRead"'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'client_info'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_client_info'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'spanner_pb2'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'PartitionReadRequest'},{'id': '106', 'type': 'argument_list', 'children': ['107', '110', '113', '116', '119', '122', '125']},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'key_set'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'key_set'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'partition_options'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'partition_options'},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '131', 'type': 'None', 'children': []},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '136', 'type': 'list', 'children': [], 'value': '[]'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '144', 'type': 'try_statement', 'children': ['145', '153', '157']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '149', 'type': 'list', 'children': ['150'], 'value': '[("session", session)]'},{'id': '150', 'type': 'tuple', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"session"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '153', 'type': 'except_clause', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'pass_statement', 'children': []},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159', '174']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'routing_metadata'},{'id': '162', 'type': 'call', 'children': ['163', '172']},{'id': '163', 'type': 'attribute', 'children': ['164', '171']},{'id': '164', 'type': 'attribute', 'children': ['165', '170']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'to_grpc_metadata'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'routing_header'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'routing_metadata'},{'id': '181', 'type': 'return_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'subscript', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '187', 'type': 'string', 'children': [], 'value': '"partition_read"'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190', '193', '196']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'metadata'}
def partition_read( self, session, table, key_set, transaction=None, index=None, columns=None, partition_options=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): if "partition_read" not in self._inner_api_calls: self._inner_api_calls[ "partition_read" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.partition_read, default_retry=self._method_configs["PartitionRead"].retry, default_timeout=self._method_configs["PartitionRead"].timeout, client_info=self._client_info, ) request = spanner_pb2.PartitionReadRequest( session=session, table=table, key_set=key_set, transaction=transaction, index=index, columns=columns, partition_options=partition_options, ) if metadata is None: metadata = [] metadata = list(metadata) try: routing_header = [("session", session)] except AttributeError: pass else: routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata( routing_header ) metadata.append(routing_metadata) return self._inner_api_calls["partition_read"]( request, retry=retry, timeout=timeout, metadata=metadata )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '50']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_documents'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '36', '47']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'collection_id'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'show_missing'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '27', 'type': 'attribute', 'children': ['28', '35']},{'id': '28', 'type': 'attribute', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '36', 'type': 'default_parameter', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '38', 'type': 'attribute', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '47', 'type': 'default_parameter', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'block', 'children': ['51', '104', '120', '152', '200']},{'id': '51', 'type': 'if_statement', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'not'},{'id': '53', 'type': 'string', 'children': [], 'value': '"list_documents"'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '65']},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '64', 'type': 'string', 'children': [], 'value': '"list_documents"'},{'id': '65', 'type': 'call', 'children': ['66', '75']},{'id': '66', 'type': 'attribute', 'children': ['67', '74']},{'id': '67', 'type': 'attribute', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'gapic_v1'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'wrap_method'},{'id': '75', 'type': 'argument_list', 'children': ['76', '81', '90', '99']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'transport'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'list_documents'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'default_retry'},{'id': '83', 'type': 'attribute', 'children': ['84', '89']},{'id': '84', 'type': 'subscript', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '88', 'type': 'string', 'children': [], 'value': '"ListDocuments"'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'default_timeout'},{'id': '92', 'type': 'attribute', 'children': ['93', '98']},{'id': '93', 'type': 'subscript', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_method_configs'},{'id': '97', 'type': 'string', 'children': [], 'value': '"ListDocuments"'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'client_info'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_client_info'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '113']},{'id': '106', 'type': 'attribute', 'children': ['107', '112']},{'id': '107', 'type': 'attribute', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'protobuf_helpers'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'check_oneof'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'firestore_pb2'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'ListDocumentsRequest'},{'id': '127', 'type': 'argument_list', 'children': ['128', '131', '134', '137', '140', '143', '146', '149']},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'collection_id'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'collection_id'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'read_time'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'show_missing'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'show_missing'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '155', 'type': 'call', 'children': ['156', '163']},{'id': '156', 'type': 'attribute', 'children': ['157', '162']},{'id': '157', 'type': 'attribute', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'google'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'api_core'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'page_iterator'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'GRPCIterator'},{'id': '163', 'type': 'argument_list', 'children': ['164', '167', '188', '191', '194', '197']},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '173', 'type': 'argument_list', 'children': ['174', '179', '182', '185']},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_inner_api_calls'},{'id': '178', 'type': 'string', 'children': [], 'value': '"list_documents"'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'retry'},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'items_field'},{'id': '193', 'type': 'string', 'children': [], 'value': '"documents"'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'request_token_field'},{'id': '196', 'type': 'string', 'children': [], 'value': '"page_token"'},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'response_token_field'},{'id': '199', 'type': 'string', 'children': [], 'value': '"next_page_token"'},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'iterator'}
def list_documents( self, parent, collection_id, page_size=None, order_by=None, mask=None, transaction=None, read_time=None, show_missing=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): if "list_documents" not in self._inner_api_calls: self._inner_api_calls[ "list_documents" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.list_documents, default_retry=self._method_configs["ListDocuments"].retry, default_timeout=self._method_configs["ListDocuments"].timeout, client_info=self._client_info, ) google.api_core.protobuf_helpers.check_oneof( transaction=transaction, read_time=read_time ) request = firestore_pb2.ListDocumentsRequest( parent=parent, collection_id=collection_id, page_size=page_size, order_by=order_by, mask=mask, transaction=transaction, read_time=read_time, show_missing=show_missing, ) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["list_documents"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="documents", request_token_field="page_token", response_token_field="next_page_token", ) return iterator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'predict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '8', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'missing_value_action'},{'id': '11', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '12', 'type': 'block', 'children': ['13', '24']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_check_categorical_option_type'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']},{'id': '17', 'type': 'string', 'children': [], 'value': "'output_type'"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '19', 'type': 'list', 'children': ['20', '21', '22', '23'], 'value': "['class', 'margin', 'probability', 'probability_vector']"},{'id': '20', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'margin'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'probability'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'probability_vector'"},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '33']},{'id': '26', 'type': 'attribute', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_Classifier'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35', '38']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'missing_value_action'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'missing_value_action'}
def predict(self, dataset, output_type='class', missing_value_action='auto'): _check_categorical_option_type('output_type', output_type, ['class', 'margin', 'probability', 'probability_vector']) return super(_Classifier, self).predict(dataset, output_type=output_type, missing_value_action=missing_value_action)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_topk_votes'},{'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', '33']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '10', 'type': 'subscript', 'children': ['11', '30']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '13', 'type': 'argument_list', 'children': ['14', '19', '27']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'lambda', 'children': ['22', '24']},{'id': '22', 'type': 'lambda_parameters', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'slice', 'children': ['31', '32']},{'id': '31', 'type': 'colon', 'children': []},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'list_comprehension', 'children': ['35', '46']},{'id': '35', 'type': 'dictionary', 'children': ['36', '41']},{'id': '36', 'type': 'pair', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'votes'"},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'y'}
def _sort_topk_votes(x, k): y = sorted(x.items(), key=lambda x: x[1], reverse=True)[:k] return [{'class': i[0], 'votes': i[1]} for i in y]
{'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_column_names'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '18', '141', '158', '169', '226']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_column_names'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_column_orders'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'if_statement', 'children': ['19', '26', '32', '134']},{'id': '19', 'type': '()', 'children': ['20']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort_column_names'},{'id': '30', 'type': 'list', 'children': ['31'], 'value': '[key_column_names]'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '32', 'type': 'elif_clause', 'children': ['33', '40']},{'id': '33', 'type': '()', 'children': ['34']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': '=='},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '40', 'type': 'block', 'children': ['41', '55', '69', '83', '91']},{'id': '41', 'type': 'if_statement', 'children': ['42', '49']},{'id': '42', 'type': '()', 'children': ['43']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '=='},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'raise_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': '"Please provide at least one column to sort"'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'first_param_types'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'list_comprehension', 'children': ['62', '66']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '69', 'type': 'if_statement', 'children': ['70', '77']},{'id': '70', 'type': '()', 'children': ['71']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '76'], 'value': '!='},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'first_param_types'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'raise_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': '"key_column_names element are not of the same type"'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'first_param_type'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'first_param_types'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'if_statement', 'children': ['92', '96', '117', '127']},{'id': '92', 'type': '()', 'children': ['93']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'first_param_type'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '96', 'type': 'block', 'children': ['97', '107']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort_column_names'},{'id': '100', 'type': 'list_comprehension', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'integer', 'children': [], 'value': '0'},{'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sort_column_orders'},{'id': '110', 'type': 'list_comprehension', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '117', 'type': 'elif_clause', 'children': ['118', '122']},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '=='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'first_param_type'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sort_column_names'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'key_column_names'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'raise_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': '"key_column_names type is not supported"'},{'id': '134', 'type': 'else_clause', 'children': ['135']},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'raise_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': '"key_column_names type is not correct. Supported types are str, list of str or list of (str,bool) pair."'},{'id': '141', 'type': 'if_statement', 'children': ['142', '149']},{'id': '142', 'type': '()', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '148'], 'value': '=='},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sort_column_orders'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sort_column_orders'},{'id': '153', 'type': 'list_comprehension', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '155', 'type': 'for_in_clause', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'sort_column_names'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'my_column_names'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'sort_column_names'},{'id': '172', 'type': 'block', 'children': ['173', '187', '205']},{'id': '173', 'type': 'if_statement', 'children': ['174', '181']},{'id': '174', 'type': '()', 'children': ['175']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '180'], 'value': '!='},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'raise_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'string', 'children': [], 'value': '"Only string parameter can be passed in as column names"'},{'id': '187', 'type': 'if_statement', 'children': ['188', '192']},{'id': '188', 'type': '()', 'children': ['189']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'not'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'my_column_names'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'raise_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'binary_operator', 'children': ['198', '204'], 'value': '+'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '+'},{'id': '199', 'type': 'string', 'children': [], 'value': '"SFrame has no column named: \'"'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '204', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '205', 'type': 'if_statement', 'children': ['206', '220']},{'id': '206', 'type': '()', 'children': ['207']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '213'], 'value': 'not'},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '213', 'type': 'tuple', 'children': ['214', '215', '216', '217']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'raise_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'string', 'children': [], 'value': '"Only columns of type (str, int, float) can be sorted"'},{'id': '226', 'type': 'with_statement', 'children': ['227', '232']},{'id': '227', 'type': 'with_clause', 'children': ['228']},{'id': '228', 'type': 'with_item', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'cython_context'},{'id': '231', 'type': 'argument_list', 'children': []},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'SFrame'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': '_proxy'},{'id': '239', 'type': 'call', 'children': ['240', '245']},{'id': '240', 'type': 'attribute', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '243', 'type': 'identifier', 'children': [], 'value': '__proxy__'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'sort_column_names'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'sort_column_orders'}
def sort(self, key_column_names, ascending=True): sort_column_names = [] sort_column_orders = [] if (type(key_column_names) == str): sort_column_names = [key_column_names] elif (type(key_column_names) == list): if (len(key_column_names) == 0): raise ValueError("Please provide at least one column to sort") first_param_types = set([type(i) for i in key_column_names]) if (len(first_param_types) != 1): raise ValueError("key_column_names element are not of the same type") first_param_type = first_param_types.pop() if (first_param_type == tuple): sort_column_names = [i[0] for i in key_column_names] sort_column_orders = [i[1] for i in key_column_names] elif(first_param_type == str): sort_column_names = key_column_names else: raise TypeError("key_column_names type is not supported") else: raise TypeError("key_column_names type is not correct. Supported types are str, list of str or list of (str,bool) pair.") if (len(sort_column_orders) == 0): sort_column_orders = [ascending for i in sort_column_names] my_column_names = set(self.column_names()) for column in sort_column_names: if (type(column) != str): raise TypeError("Only string parameter can be passed in as column names") if (column not in my_column_names): raise ValueError("SFrame has no column named: '" + str(column) + "'") if (self[column].dtype not in (str, int, float,datetime.datetime)): raise TypeError("Only columns of type (str, int, float) can be sorted") with cython_context(): return SFrame(_proxy=self.__proxy__.sort(sort_column_names, sort_column_orders))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'MakeSimpleProtoClass'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '23', '44', '52', '67', '75', '108', '118', '150', '164']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'message_factory'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'MessageFactory'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'try_statement', 'children': ['29', '40']},{'id': '29', 'type': 'block', 'children': ['30', '38']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'proto_cls'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_GetMessageFromFactory'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'proto_cls'},{'id': '40', 'type': 'except_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'pass_statement', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'field_items'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'if_statement', 'children': ['53', '59']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'field_items'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'field_items'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fields_hash'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'for_statement', 'children': ['76', '79', '80']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'f_name'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'f_type'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'field_items'},{'id': '80', 'type': 'block', 'children': ['81', '93']},{'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': 'fields_hash'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'update'},{'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': 'f_name'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'fields_hash'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '106']},{'id': '100', 'type': 'attribute', 'children': ['101', '105']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'f_type'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'proto_file_name'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '117'], 'value': '+'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fields_hash'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'string', 'children': [], 'value': "'.proto'"},{'id': '118', 'type': 'if_statement', 'children': ['119', '122']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'is'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '121', 'type': 'None', 'children': []},{'id': '122', 'type': 'block', 'children': ['123', '134']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '126', 'type': '()', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'},{'id': '128', 'type': 'string', 'children': [], 'value': "'net.proto2.python.public.proto_builder.AnonymousProto_'"},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fields_hash'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'try_statement', 'children': ['135', '146']},{'id': '135', 'type': 'block', 'children': ['136', '144']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'proto_cls'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': '_GetMessageFromFactory'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'proto_cls'},{'id': '146', 'type': 'except_clause', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'pass_statement', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'Add'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_MakeFileDescriptorProto'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162', '163']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'proto_file_name'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'field_items'},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_GetMessageFromFactory'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'full_name'}
def MakeSimpleProtoClass(fields, full_name=None, pool=None): factory = message_factory.MessageFactory(pool=pool) if full_name is not None: try: proto_cls = _GetMessageFromFactory(factory, full_name) return proto_cls except KeyError: pass field_items = fields.items() if not isinstance(fields, OrderedDict): field_items = sorted(field_items) fields_hash = hashlib.sha1() for f_name, f_type in field_items: fields_hash.update(f_name.encode('utf-8')) fields_hash.update(str(f_type).encode('utf-8')) proto_file_name = fields_hash.hexdigest() + '.proto' if full_name is None: full_name = ('net.proto2.python.public.proto_builder.AnonymousProto_' + fields_hash.hexdigest()) try: proto_cls = _GetMessageFromFactory(factory, full_name) return proto_cls except KeyError: pass factory.pool.Add( _MakeFileDescriptorProto(proto_file_name, full_name, field_items)) return _GetMessageFromFactory(factory, full_name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'value_counts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '15']},{'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': 'sframe'},{'id': '11', 'type': 'aliased_import', 'children': ['12', '14']},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'SFrame'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_SFrame'},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '37']},{'id': '17', 'type': 'attribute', 'children': ['18', '36']},{'id': '18', 'type': 'call', 'children': ['19', '28']},{'id': '19', 'type': 'attribute', 'children': ['20', '27']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_SFrame'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'dictionary', 'children': ['24']},{'id': '24', 'type': 'pair', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '30', 'type': 'dictionary', 'children': ['31']},{'id': '31', 'type': 'pair', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_aggregate'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'COUNT'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '41', 'type': 'False', 'children': []}
def value_counts(self): from .sframe import SFrame as _SFrame return _SFrame({'value':self}).groupby('value', {'count':_aggregate.COUNT}).sort('count', ascending=False)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '36', '42', '48']},{'id': '9', 'type': 'import_from_statement', 'children': ['10', '14']},{'id': '10', 'type': 'relative_import', 'children': ['11', '12']},{'id': '11', 'type': 'import_prefix', 'children': []},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sframe'},{'id': '14', 'type': 'aliased_import', 'children': ['15', '17']},{'id': '15', 'type': 'dotted_name', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'SFrame'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_SFrame'},{'id': '18', 'type': 'if_statement', 'children': ['19', '30']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': 'not'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '23', 'type': 'tuple', 'children': ['24', '25', '26', '27']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'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': 'TypeError'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': '"Only sarray with type (int, float, str, datetime.datetime) can be sorted"'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_SFrame'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '46', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'subscript', 'children': ['50', '57']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '57', 'type': 'string', 'children': [], 'value': "'a'"}
def sort(self, ascending=True): from .sframe import SFrame as _SFrame if self.dtype not in (int, float, str, datetime.datetime): raise TypeError("Only sarray with type (int, float, str, datetime.datetime) can be sorted") sf = _SFrame() sf['a'] = self return sf.sort('a', ascending)['a']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'predict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '8', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '9', 'type': 'block', 'children': ['10', '18', '26', '30']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '13', 'type': 'subscript', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__proxy__'},{'id': '17', 'type': 'string', 'children': [], 'value': "'classifier'"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '__proxy__'},{'id': '25', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_BOW_FEATURE_EXTRACTOR'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '35', 'type': 'argument_list', 'children': ['36', '41']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'output_type'}
def predict(self, dataset, output_type='class'): m = self.__proxy__['classifier'] target = self.__proxy__['target'] f = _BOW_FEATURE_EXTRACTOR return m.predict(f(dataset, target), output_type=output_type)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'colored'},{'id': '6', 'type': 'block', 'children': ['7', '48']},{'id': '7', 'type': 'try_statement', 'children': ['8', '44']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', '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': 'event'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"{"'},{'id': '18', 'type': 'block', 'children': ['19', '30']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'msg_dict'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'msg_dict'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '43', 'type': 'integer', 'children': [], 'value': '2'},{'id': '44', 'type': 'except_clause', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'pass_statement', 'children': []},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'event'}
def format_json(event, colored): try: if event.message.startswith("{"): msg_dict = json.loads(event.message) event.message = json.dumps(msg_dict, indent=2) except Exception: pass return event
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'explain_instance_with_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'neighborhood_data'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'neighborhood_labels'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'distances'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'num_features'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'feature_selection'},{'id': '12', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'model_regressor'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '26', '34', '47', '69', '73', '88', '105', '124', '152']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kernel_fn'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'distances'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'labels_column'},{'id': '29', 'type': 'subscript', 'children': ['30', '31', '33']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'neighborhood_labels'},{'id': '31', 'type': 'slice', 'children': ['32']},{'id': '32', 'type': 'colon', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'used_features'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'feature_selection'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '44', '45', '46']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'neighborhood_data'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'labels_column'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'num_features'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'feature_selection'},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'model_regressor'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'model_regressor'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'Ridge'},{'id': '57', 'type': 'argument_list', 'children': ['58', '61', '64']},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'fit_intercept'},{'id': '63', 'type': 'True', 'children': []},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'easy_model'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'model_regressor'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'easy_model'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '78', 'type': 'argument_list', 'children': ['79', '84', '85']},{'id': '79', 'type': 'subscript', 'children': ['80', '81', '83']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'neighborhood_data'},{'id': '81', 'type': 'slice', 'children': ['82']},{'id': '82', 'type': 'colon', 'children': []},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'used_features'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'labels_column'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sample_weight'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'prediction_score'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'easy_model'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '95', 'type': 'argument_list', 'children': ['96', '101', '102']},{'id': '96', 'type': 'subscript', 'children': ['97', '98', '100']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'neighborhood_data'},{'id': '98', 'type': 'slice', 'children': ['99']},{'id': '99', 'type': 'colon', 'children': []},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'used_features'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'labels_column'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sample_weight'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'local_pred'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'easy_model'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '120']},{'id': '114', 'type': 'attribute', 'children': ['115', '119']},{'id': '115', 'type': 'subscript', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'neighborhood_data'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'used_features'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122']},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'unary_operator', 'children': ['123'], 'value': '-'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '128', 'type': 'block', 'children': ['129', '137', '143']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'Intercept'"},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'easy_model'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'intercept_'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': "'Prediction_local'"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'local_pred'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'Right:'"},{'id': '148', 'type': 'subscript', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'neighborhood_labels'},{'id': '150', 'type': 'integer', 'children': [], 'value': '0'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '152', 'type': 'return_statement', 'children': ['153']},{'id': '153', 'type': 'tuple', 'children': ['154', '157', '183', '184']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'easy_model'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'intercept_'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '159', 'type': 'argument_list', 'children': ['160', '167', '180']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'used_features'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'easy_model'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'coef_'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '169', 'type': 'lambda', 'children': ['170', '172']},{'id': '170', 'type': 'lambda_parameters', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '179', 'type': 'integer', 'children': [], 'value': '1'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '182', 'type': 'True', 'children': []},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'prediction_score'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'local_pred'}
def explain_instance_with_data(self, neighborhood_data, neighborhood_labels, distances, label, num_features, feature_selection='auto', model_regressor=None): weights = self.kernel_fn(distances) labels_column = neighborhood_labels[:, label] used_features = self.feature_selection(neighborhood_data, labels_column, weights, num_features, feature_selection) if model_regressor is None: model_regressor = Ridge(alpha=1, fit_intercept=True, random_state=self.random_state) easy_model = model_regressor easy_model.fit(neighborhood_data[:, used_features], labels_column, sample_weight=weights) prediction_score = easy_model.score( neighborhood_data[:, used_features], labels_column, sample_weight=weights) local_pred = easy_model.predict(neighborhood_data[0, used_features].reshape(1, -1)) if self.verbose: print('Intercept', easy_model.intercept_) print('Prediction_local', local_pred,) print('Right:', neighborhood_labels[0, label]) return (easy_model.intercept_, sorted(zip(used_features, easy_model.coef_), key=lambda x: np.abs(x[1]), reverse=True), prediction_score, local_pred)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'serialize_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '13', 'type': 'block', 'children': ['14', '16', '35', '49', '66', '77']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': '\'\'\' Return a serialized JSON representation of objects, suitable to\n send to BokehJS.\n This function is typically used to serialize single python objects in\n the manner expected by BokehJS. In particular, many datetime values are\n automatically normalized to an expected format. Some Bokeh objects can\n also be passed, but note that Bokeh models are typically properly\n serialized in the context of an entire Bokeh document.\n The resulting JSON always has sorted keys. By default. the output is\n as compact as possible unless pretty output or indentation is requested.\n Args:\n obj (obj) : the object to serialize to JSON format\n pretty (bool, optional) :\n Whether to generate prettified output. If ``True``, spaces are\n added after added after separators, and indentation and newlines\n are applied. (default: False)\n Pretty output can also be enabled with the environment variable\n ``BOKEH_PRETTY``, which overrides this argument, if set.\n indent (int or None, optional) :\n Amount of indentation to use in generated JSON output. If ``None``\n then no indentation is used, unless pretty output is enabled,\n in which case two spaces are used. (default: None)\n Any additional keyword arguments are passed to ``json.dumps``, except for\n some that are computed internally, and cannot be overridden:\n * allow_nan\n * indent\n * separators\n * sort_keys\n Examples:\n .. code-block:: python\n >>> data = dict(b=np.datetime64(\'2017-01-01\'), a = np.arange(3))\n >>>print(serialize_json(data))\n {"a":[0,1,2],"b":1483228800000.0}\n >>> print(serialize_json(data, pretty=True))\n {\n "a": [\n 0,\n 1,\n 2\n ],\n "b": 1483228800000.0\n }\n \'\'\''},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '22']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '18', 'type': 'list', 'children': ['19', '20', '21'], 'value': "['allow_nan', 'separators', 'sort_keys']"},{'id': '19', 'type': 'string', 'children': [], 'value': "'allow_nan'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'separators'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'sort_keys'"},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'in'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '%'},{'id': '33', 'type': 'string', 'children': [], 'value': '"The value of %r is computed internally, overriding is not permissable."'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'False', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '51', '58']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '55', 'type': 'tuple', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': '","'},{'id': '57', 'type': 'string', 'children': [], 'value': '": "'},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '63', 'type': 'tuple', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': '","'},{'id': '65', 'type': 'string', 'children': [], 'value': '":"'},{'id': '66', 'type': 'if_statement', 'children': ['67', '72']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '69'], 'value': 'and'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '76', 'type': 'integer', 'children': [], 'value': '2'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84', '87', '90', '93', '96', '99']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'BokehJSONEncoder'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'allow_nan'},{'id': '89', 'type': 'False', 'children': []},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '98', 'type': 'True', 'children': []},{'id': '99', 'type': 'dictionary_splat', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def serialize_json(obj, pretty=None, indent=None, **kwargs): ''' Return a serialized JSON representation of objects, suitable to send to BokehJS. This function is typically used to serialize single python objects in the manner expected by BokehJS. In particular, many datetime values are automatically normalized to an expected format. Some Bokeh objects can also be passed, but note that Bokeh models are typically properly serialized in the context of an entire Bokeh document. The resulting JSON always has sorted keys. By default. the output is as compact as possible unless pretty output or indentation is requested. Args: obj (obj) : the object to serialize to JSON format pretty (bool, optional) : Whether to generate prettified output. If ``True``, spaces are added after added after separators, and indentation and newlines are applied. (default: False) Pretty output can also be enabled with the environment variable ``BOKEH_PRETTY``, which overrides this argument, if set. indent (int or None, optional) : Amount of indentation to use in generated JSON output. If ``None`` then no indentation is used, unless pretty output is enabled, in which case two spaces are used. (default: None) Any additional keyword arguments are passed to ``json.dumps``, except for some that are computed internally, and cannot be overridden: * allow_nan * indent * separators * sort_keys Examples: .. code-block:: python >>> data = dict(b=np.datetime64('2017-01-01'), a = np.arange(3)) >>>print(serialize_json(data)) {"a":[0,1,2],"b":1483228800000.0} >>> print(serialize_json(data, pretty=True)) { "a": [ 0, 1, 2 ], "b": 1483228800000.0 } ''' for name in ['allow_nan', 'separators', 'sort_keys']: if name in kwargs: raise ValueError("The value of %r is computed internally, overriding is not permissable." % name) if pretty is None: pretty = settings.pretty(False) if pretty: separators=(",", ": ") else: separators=(",", ":") if pretty and indent is None: indent = 2 return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_item_children'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '5', 'type': 'block', 'children': ['6', '26', '49']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '16']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'childCount'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '32']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '30', 'type': 'slice', 'children': ['31']},{'id': '31', 'type': 'colon', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '40']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_item_children'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'augmented_assignment', 'children': ['47', '48'], 'value': '+='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'lambda', 'children': ['57', '59']},{'id': '57', 'type': 'lambda_parameters', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'line'}
def get_item_children(item): children = [item.child(index) for index in range(item.childCount())] for child in children[:]: others = get_item_children(child) if others is not None: children += others return sorted(children, key=lambda child: child.line)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__sort_toplevel_items'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '34', '93']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'show_all_files'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'current_ordered_items'},{'id': '17', 'type': 'list_comprehension', 'children': ['18', '24']},{'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': 'topLevelItem'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'topLevelItemCount'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '38', '63']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort_files_alphabetically'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'new_ordered_items'},{'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': 'current_ordered_items'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'lambda', 'children': ['49', '51']},{'id': '49', 'type': 'lambda_parameters', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'osp'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '62', 'type': 'argument_list', 'children': []},{'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', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'new_ordered_items'},{'id': '68', 'type': 'list_comprehension', 'children': ['69', '77', '82']},{'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': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'editor_items'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'e_id'},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'e_id'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ordered_editor_ids'},{'id': '82', 'type': 'if_clause', 'children': ['83']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '92'], 'value': 'is'},{'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': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'editor_items'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'e_id'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '!='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'current_ordered_items'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'new_ordered_items'},{'id': '97', 'type': 'block', 'children': ['98', '106', '112', '130', '147', '153', '159']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'selected_items'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'selectedItems'},{'id': '105', 'type': 'argument_list', 'children': []},{'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': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'save_expanded_state'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'for_statement', 'children': ['113', '114', '122']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'topLevelItemCount'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'takeTopLevelItem'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'for_statement', 'children': ['131', '134', '138']},{'id': '131', 'type': 'pattern_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'new_ordered_items'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'insertTopLevelItem'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'item'},{'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': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'restore_expanded_state'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'clearSelection'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'if_statement', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'selected_items'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '170']},{'id': '164', 'type': 'attribute', 'children': ['165', '169']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'selected_items'},{'id': '167', 'type': 'unary_operator', 'children': ['168'], 'value': '-'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'setSelected'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'True', 'children': []}
def __sort_toplevel_items(self): if self.show_all_files is False: return current_ordered_items = [self.topLevelItem(index) for index in range(self.topLevelItemCount())] if self.sort_files_alphabetically: new_ordered_items = sorted( current_ordered_items, key=lambda item: osp.basename(item.path.lower())) else: new_ordered_items = [ self.editor_items.get(e_id) for e_id in self.ordered_editor_ids if self.editor_items.get(e_id) is not None] if current_ordered_items != new_ordered_items: selected_items = self.selectedItems() self.save_expanded_state() for index in range(self.topLevelItemCount()): self.takeTopLevelItem(0) for index, item in enumerate(new_ordered_items): self.insertTopLevelItem(index, item) self.restore_expanded_state() self.clearSelection() if selected_items: selected_items[-1].setSelected(True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortByColumn'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'block', 'children': ['7', '24', '34', '42', '96']},{'id': '7', 'type': 'if_statement', 'children': ['8', '14']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '=='},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort_old'},{'id': '12', 'type': 'list', 'children': ['13'], 'value': '[None]'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'header_class'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'setSortIndicatorShown'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'header_class'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sortIndicatorOrder'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'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': 'sig_sort_by_column'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'if_statement', 'children': ['43', '55']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '52']},{'id': '45', 'type': 'attribute', 'children': ['46', '51']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '55', 'type': 'block', 'children': ['56', '95']},{'id': '56', 'type': 'if_statement', 'children': ['57', '65', '75']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '64'], 'value': '!='},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort_old'},{'id': '64', 'type': 'integer', 'children': [], 'value': '2'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'header_class'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'setSortIndicatorShown'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'False', 'children': []},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'header_class'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'setSortIndicator'},{'id': '84', 'type': 'argument_list', 'children': ['85', '90']},{'id': '85', 'type': 'subscript', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort_old'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'subscript', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort_old'},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'return_statement', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sort_old'},{'id': '101', 'type': 'list', 'children': ['102', '103'], 'value': '[index, self.header_class.sortIndicatorOrder()]'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'header_class'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sortIndicatorOrder'},{'id': '109', 'type': 'argument_list', 'children': []}
def sortByColumn(self, index): if self.sort_old == [None]: self.header_class.setSortIndicatorShown(True) sort_order = self.header_class.sortIndicatorOrder() self.sig_sort_by_column.emit() if not self.model().sort(index, sort_order): if len(self.sort_old) != 2: self.header_class.setSortIndicatorShown(False) else: self.header_class.setSortIndicator(self.sort_old[0], self.sort_old[1]) return self.sort_old = [index, self.header_class.sortIndicatorOrder()]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'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': 'column'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'AscendingOrder'},{'id': '11', 'type': 'block', 'children': ['12', '20', '34']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '=='},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'AscendingOrder'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '27']},{'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': 'model'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '27', 'type': 'argument_list', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'COLUMN_INDEX'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'True', 'children': []}
def sort(self, column, order=Qt.AscendingOrder): ascending = order == Qt.AscendingOrder self.model.sort(self.COLUMN_INDEX, order=ascending) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortByIndex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'block', 'children': ['7', '20', '34', '48']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '18']},{'id': '9', 'type': 'attribute', 'children': ['10', '17']},{'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': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'table_level'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'horizontalHeader'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'setSortIndicatorShown'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '23', 'type': 'call', 'children': ['24', '33']},{'id': '24', 'type': 'attribute', 'children': ['25', '32']},{'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': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'table_level'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'horizontalHeader'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sortIndicatorOrder'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '45']},{'id': '36', 'type': 'attribute', 'children': ['37', '44']},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'table_index'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'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': '_sort_update'},{'id': '53', 'type': 'argument_list', 'children': []}
def sortByIndex(self, index): self.table_level.horizontalHeader().setSortIndicatorShown(True) sort_order = self.table_level.horizontalHeader().sortIndicatorOrder() self.table_index.model().sort(index, sort_order) self._sort_update()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_file_tabs_alphabetically'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'while_statement', 'children': ['7', '14']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '13'], 'value': 'is'},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '32']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'call', 'children': ['22', '31']},{'id': '22', 'type': 'attribute', 'children': ['23', '30']},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'tabs'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'tabBar'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'if_statement', 'children': ['34', '62']},{'id': '34', 'type': '()', 'children': ['35']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '48'], 'value': '>'},{'id': '36', 'type': 'call', 'children': ['37', '46']},{'id': '37', 'type': 'attribute', 'children': ['38', '45']},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'tabs'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tabBar'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tabText'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '48', 'type': 'call', 'children': ['49', '58']},{'id': '49', 'type': 'attribute', 'children': ['50', '57']},{'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': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tabs'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tabBar'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tabText'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '74']},{'id': '65', 'type': 'attribute', 'children': ['66', '73']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'tabs'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'tabBar'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'moveTab'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '+'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'}
def sort_file_tabs_alphabetically(self): while self.sorted() is False: for i in range(0, self.tabs.tabBar().count()): if(self.tabs.tabBar().tabText(i) > self.tabs.tabBar().tabText(i + 1)): self.tabs.tabBar().moveTab(i, i + 1)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_top_level_items'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '13', '39', '56']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'save_expanded_state'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19', '36']},{'id': '19', 'type': 'list_comprehension', 'children': ['20', '26']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'takeTopLevelItem'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'topLevelItemCount'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'for_statement', 'children': ['40', '43', '47']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'insertTopLevelItem'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'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': 'restore_expanded_state'},{'id': '61', 'type': 'argument_list', 'children': []}
def sort_top_level_items(self, key): self.save_expanded_state() items = sorted([self.takeTopLevelItem(0) for index in range(self.topLevelItemCount())], key=key) for index, item in enumerate(items): self.insertTopLevelItem(index, item) self.restore_expanded_state()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_sorting'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '6', 'type': 'block', 'children': ['7', '15']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '14']},{'id': '9', 'type': 'subscript', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '13', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '24']},{'id': '17', 'type': 'attribute', 'children': ['18', '23']},{'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': 'header'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'setSectionsClickable'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ON'}
def set_sorting(self, flag): self.sorting['status'] = flag self.header().setSectionsClickable(flag == ON)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_filter'},{'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', '41']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_search_regex'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '30']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'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': '_parent'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'setSortingEnabled'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'else_clause', 'children': ['31']},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'setSortingEnabled'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'True', 'children': []},{'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': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'invalidateFilter'},{'id': '46', 'type': 'argument_list', 'children': []}
def set_filter(self, text): self.pattern = get_search_regex(text) if self.pattern: self._parent.setSortingEnabled(False) else: self._parent.setSortingEnabled(True) self.invalidateFilter()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_content_hash'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '16', '33', '56']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_local_config'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'relevant_content'},{'id': '15', 'type': 'dictionary', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '21']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_relevant_keys'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'relevant_content'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'content_hash'},{'id': '36', 'type': 'call', 'children': ['37', '55']},{'id': '37', 'type': 'attribute', 'children': ['38', '54']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sha256'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '53']},{'id': '42', 'type': 'attribute', 'children': ['43', '52']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'relevant_content'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '51', 'type': 'True', 'children': []},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'content_hash'}
def _get_content_hash(self): content = self._local_config relevant_content = {} for key in self._relevant_keys: relevant_content[key] = content.get(key) content_hash = sha256( json.dumps(relevant_content, sort_keys=True).encode() ).hexdigest() return content_hash
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'missing_datetimes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'finite_datetimes'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'list_comprehension', 'children': ['9', '10', '13']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '10', 'type': 'for_in_clause', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'finite_datetimes'},{'id': '13', 'type': 'if_clause', 'children': ['14']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '29']},{'id': '16', 'type': 'attribute', 'children': ['17', '28']},{'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': '_instantiate_task_cls'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'datetime_to_parameter'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'complete'},{'id': '29', 'type': 'argument_list', 'children': []}
def missing_datetimes(self, finite_datetimes): return [d for d in finite_datetimes if not self._instantiate_task_cls(self.datetime_to_parameter(d)).complete()]