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', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_and_sort_nodes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'if_statement', 'children': ['7', '15', '143', '189']},{'id': '7', 'type': 'boolean_operator', 'children': ['8', '11'], 'value': 'and'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'node_grouping'},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'node_order'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '22', '59']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': '=='},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'group_order'},{'id': '21', 'type': 'string', 'children': [], 'value': '"alphabetically"'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '28', 'type': 'list_comprehension', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '34']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '36', 'type': 'argument_list', 'children': ['37', '47']},{'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': 'graph'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '46', 'type': 'True', 'children': []},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '49', 'type': 'lambda', 'children': ['50', '52']},{'id': '50', 'type': 'lambda_parameters', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'node_grouping'},{'id': '59', 'type': 'elif_clause', 'children': ['60', '65']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': '=='},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'group_order'},{'id': '64', 'type': 'string', 'children': [], 'value': '"default"'},{'id': '65', 'type': 'block', 'children': ['66', '89', '99', '103', '137']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'grp'},{'id': '69', 'type': 'list_comprehension', 'children': ['70', '75']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'node_grouping'},{'id': '75', 'type': 'for_in_clause', 'children': ['76', '79']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '88', 'type': 'True', 'children': []},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'grp_name'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'unique_everseen'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'grp'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '102', 'type': 'list', 'children': [], 'value': '[]'},{'id': '103', 'type': 'for_statement', 'children': ['104', '105', '106']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'grp_name'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'list_comprehension', 'children': ['114', '115', '129']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '119']},{'id': '116', 'type': 'pattern_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '128', 'type': 'True', 'children': []},{'id': '129', 'type': 'if_clause', 'children': ['130']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '143', 'type': 'elif_clause', 'children': ['144', '152']},{'id': '144', 'type': 'boolean_operator', 'children': ['145', '148'], 'value': 'and'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'node_order'},{'id': '148', 'type': 'not_operator', 'children': ['149']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'node_grouping'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '158', 'type': 'list_comprehension', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '164']},{'id': '161', 'type': 'pattern_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '163', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '166', 'type': 'argument_list', 'children': ['167', '177']},{'id': '167', 'type': 'call', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '176', 'type': 'True', 'children': []},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '179', 'type': 'lambda', 'children': ['180', '182']},{'id': '180', 'type': 'lambda_parameters', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '182', 'type': 'subscript', 'children': ['183', '186']},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'node_order'},{'id': '189', 'type': 'elif_clause', 'children': ['190', '197']},{'id': '190', 'type': 'boolean_operator', 'children': ['191', '194'], 'value': 'and'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'node_grouping'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'node_order'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'if_statement', 'children': ['199', '204', '249']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '203'], 'value': '=='},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'group_order'},{'id': '203', 'type': 'string', 'children': [], 'value': '"alphabetically"'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '210', 'type': 'list_comprehension', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '212', 'type': 'for_in_clause', 'children': ['213', '216']},{'id': '213', 'type': 'pattern_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '218', 'type': 'argument_list', 'children': ['219', '229']},{'id': '219', 'type': 'call', 'children': ['220', '225']},{'id': '220', 'type': 'attribute', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '228', 'type': 'True', 'children': []},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '231', 'type': 'lambda', 'children': ['232', '234']},{'id': '232', 'type': 'lambda_parameters', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '234', 'type': 'tuple', 'children': ['235', '242']},{'id': '235', 'type': 'subscript', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '238', 'type': 'integer', 'children': [], 'value': '1'},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'node_grouping'},{'id': '242', 'type': 'subscript', 'children': ['243', '246']},{'id': '243', 'type': 'subscript', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '245', 'type': 'integer', 'children': [], 'value': '1'},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'node_order'},{'id': '249', 'type': 'elif_clause', 'children': ['250', '255']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '254'], 'value': '=='},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'group_order'},{'id': '254', 'type': 'string', 'children': [], 'value': '"default"'},{'id': '255', 'type': 'block', 'children': ['256', '279', '289', '293', '342']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'grp'},{'id': '259', 'type': 'list_comprehension', 'children': ['260', '265']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'node_grouping'},{'id': '265', 'type': 'for_in_clause', 'children': ['266', '269']},{'id': '266', 'type': 'pattern_list', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '269', 'type': 'call', 'children': ['270', '275']},{'id': '270', 'type': 'attribute', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '278', 'type': 'True', 'children': []},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'grp_name'},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'unique_everseen'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'grp'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '292', 'type': 'list', 'children': [], 'value': '[]'},{'id': '293', 'type': 'for_statement', 'children': ['294', '295', '296']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'grp_name'},{'id': '296', 'type': 'block', 'children': ['297']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'list_comprehension', 'children': ['304', '305', '334']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '305', 'type': 'for_in_clause', 'children': ['306', '309']},{'id': '306', 'type': 'pattern_list', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '311', 'type': 'argument_list', 'children': ['312', '322']},{'id': '312', 'type': 'call', 'children': ['313', '318']},{'id': '313', 'type': 'attribute', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '321', 'type': 'True', 'children': []},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '324', 'type': 'lambda', 'children': ['325', '327']},{'id': '325', 'type': 'lambda_parameters', 'children': ['326']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '327', 'type': 'subscript', 'children': ['328', '331']},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '330', 'type': 'integer', 'children': [], 'value': '1'},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'node_order'},{'id': '334', 'type': 'if_clause', 'children': ['335']},{'id': '335', 'type': 'comparison_operator', 'children': ['336', '337'], 'value': 'in'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '337', 'type': 'call', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '341', 'type': 'argument_list', 'children': []},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'nodes'} | def group_and_sort_nodes(self):
if self.node_grouping and not self.node_order:
if self.group_order == "alphabetically":
self.nodes = [
n
for n, d in sorted(
self.graph.nodes(data=True),
key=lambda x: x[1][self.node_grouping],
)
]
elif self.group_order == "default":
grp = [
d[self.node_grouping]
for _, d in self.graph.nodes(data=True)
]
grp_name = list(unique_everseen(grp))
nodes = []
for key in grp_name:
nodes.extend(
[
n
for n, d in self.graph.nodes(data=True)
if key in d.values()
]
)
self.nodes = nodes
elif self.node_order and not self.node_grouping:
self.nodes = [
n
for n, _ in sorted(
self.graph.nodes(data=True),
key=lambda x: x[1][self.node_order],
)
]
elif self.node_grouping and self.node_order:
if self.group_order == "alphabetically":
self.nodes = [
n
for n, d in sorted(
self.graph.nodes(data=True),
key=lambda x: (
x[1][self.node_grouping],
x[1][self.node_order],
),
)
]
elif self.group_order == "default":
grp = [
d[self.node_grouping]
for _, d in self.graph.nodes(data=True)
]
grp_name = list(unique_everseen(grp))
nodes = []
for key in grp_name:
nodes.extend(
[
n
for n, d in sorted(
self.graph.nodes(data=True),
key=lambda x: x[1][self.node_order],
)
if key in d.values()
]
)
self.nodes = nodes |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sets'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sets'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '17', 'type': 'generator_expression', 'children': ['18', '22']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sets'} | def to_json(self):
sets = self.sets()
return sorted(sorted(x) for x in sets) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reload'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '14', '20']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'Generate histrow for each row and then reverse-sort by length.'"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'discreteBinning'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '25']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nonKeyVisibleCols'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_cachedValues'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '35', 'type': 'argument_list', 'children': []} | def reload(self):
'Generate histrow for each row and then reverse-sort by length.'
self.rows = []
self.discreteBinning()
for c in self.nonKeyVisibleCols:
c._cachedValues = collections.OrderedDict() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'resolve_colors'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'colorstack'},{'id': '6', 'type': 'block', 'children': ['7', '9', '15', '37']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'Returns the curses attribute for the colorstack, a list of color option names sorted highest-precedence color first.'"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'CursesAttr'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'coloropt'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'colorstack'},{'id': '18', 'type': 'block', 'children': ['19', '28']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'},{'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': 'get_color'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'coloropt'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'update_attr'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'attr'} | def resolve_colors(self, colorstack):
'Returns the curses attribute for the colorstack, a list of color option names sorted highest-precedence color first.'
attr = CursesAttr()
for coloropt in colorstack:
c = self.get_color(coloropt)
attr = attr.update_attr(c)
return attr |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_mentions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '16', '169']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'if_statement', 'children': ['17', '18', '109']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '18', 'type': 'block', 'children': ['19', '33']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '22', 'type': 'conditional_expression', 'children': ['23', '24', '31'], 'value': 'if'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '28', 'type': 'tuple', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '31', 'type': 'list', 'children': ['32'], 'value': '[docs]'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '38']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mention_class'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'mention_classes'},{'id': '38', 'type': 'block', 'children': ['39', '80', '102']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '42', 'type': '()', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '79']},{'id': '44', 'type': 'attribute', 'children': ['45', '78']},{'id': '45', 'type': 'call', 'children': ['46', '74']},{'id': '46', 'type': 'attribute', 'children': ['47', '73']},{'id': '47', 'type': 'call', 'children': ['48', '58']},{'id': '48', 'type': 'attribute', 'children': ['49', '57']},{'id': '49', 'type': 'call', 'children': ['50', '55']},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'mention_class'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mention_class'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'document_id'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'in_'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'mention_class'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'if_statement', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '92', 'type': 'lambda', 'children': ['93', '95']},{'id': '93', 'type': 'lambda_parameters', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'call', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '99', 'type': 'integer', 'children': [], 'value': '0'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_stable_id'},{'id': '101', 'type': 'argument_list', 'children': []},{'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': 'result'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'for_statement', 'children': ['112', '113', '116']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'mention_class'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'mention_classes'},{'id': '116', 'type': 'block', 'children': ['117', '140', '162']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '139']},{'id': '122', 'type': 'attribute', 'children': ['123', '138']},{'id': '123', 'type': 'call', 'children': ['124', '134']},{'id': '124', 'type': 'attribute', 'children': ['125', '133']},{'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': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mention_class'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'mention_class'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'if_statement', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '152', 'type': 'lambda', 'children': ['153', '155']},{'id': '153', 'type': 'lambda_parameters', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '155', 'type': 'call', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'get_stable_id'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'mentions'},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'result'} | def get_mentions(self, docs=None, sort=False):
result = []
if docs:
docs = docs if isinstance(docs, (list, tuple)) else [docs]
for mention_class in self.mention_classes:
mentions = (
self.session.query(mention_class)
.filter(mention_class.document_id.in_([doc.id for doc in docs]))
.order_by(mention_class.id)
.all()
)
if sort:
mentions = sorted(mentions, key=lambda x: x[0].get_stable_id())
result.append(mentions)
else:
for mention_class in self.mention_classes:
mentions = (
self.session.query(mention_class).order_by(mention_class.id).all()
)
if sort:
mentions = sorted(mentions, key=lambda x: x[0].get_stable_id())
result.append(mentions)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_candidates'},{'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': 'docs'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '19', '245']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'if_statement', 'children': ['20', '21', '129']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '21', 'type': 'block', 'children': ['22', '36']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '25', 'type': 'conditional_expression', 'children': ['26', '27', '34'], 'value': 'if'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'docs'},{'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': 'docs'},{'id': '31', 'type': 'tuple', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '34', 'type': 'list', 'children': ['35'], 'value': '[docs]'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '41']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'candidate_classes'},{'id': '41', 'type': 'block', 'children': ['42', '83', '122']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '45', 'type': '()', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '82']},{'id': '47', 'type': 'attribute', 'children': ['48', '81']},{'id': '48', 'type': 'call', 'children': ['49', '77']},{'id': '49', 'type': 'attribute', 'children': ['50', '76']},{'id': '50', 'type': 'call', 'children': ['51', '61']},{'id': '51', 'type': 'attribute', 'children': ['52', '60']},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'document_id'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'in_'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'list_comprehension', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'if_statement', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'lambda', 'children': ['96', '98']},{'id': '96', 'type': 'lambda_parameters', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': '" "'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'list_comprehension', 'children': ['104', '113']},{'id': '104', 'type': 'call', 'children': ['105', '112']},{'id': '105', 'type': 'attribute', 'children': ['106', '111']},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'get_stable_id'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'for_statement', 'children': ['132', '133', '136']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'candidate_classes'},{'id': '136', 'type': 'block', 'children': ['137', '164', '199', '238']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sub_query'},{'id': '140', 'type': '()', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '163']},{'id': '142', 'type': 'attribute', 'children': ['143', '162']},{'id': '143', 'type': 'call', 'children': ['144', '156']},{'id': '144', 'type': 'attribute', 'children': ['145', '155']},{'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': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'Candidate'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '=='},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'Candidate'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'subquery'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '167', 'type': '()', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '198']},{'id': '169', 'type': 'attribute', 'children': ['170', '197']},{'id': '170', 'type': 'call', 'children': ['171', '193']},{'id': '171', 'type': 'attribute', 'children': ['172', '192']},{'id': '172', 'type': 'call', 'children': ['173', '183']},{'id': '173', 'type': 'attribute', 'children': ['174', '182']},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '190']},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'in_'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sub_query'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'candidate_class'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '198', 'type': 'argument_list', 'children': []},{'id': '199', 'type': 'if_statement', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '211', 'type': 'lambda', 'children': ['212', '214']},{'id': '212', 'type': 'lambda_parameters', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'string', 'children': [], 'value': '" "'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'list_comprehension', 'children': ['220', '229']},{'id': '220', 'type': 'call', 'children': ['221', '228']},{'id': '221', 'type': 'attribute', 'children': ['222', '227']},{'id': '222', 'type': 'subscript', 'children': ['223', '226']},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'get_stable_id'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'for_in_clause', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'cands'},{'id': '245', 'type': 'return_statement', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'result'} | def get_candidates(self, docs=None, split=0, sort=False):
result = []
if docs:
docs = docs if isinstance(docs, (list, tuple)) else [docs]
for candidate_class in self.candidate_classes:
cands = (
self.session.query(candidate_class)
.filter(candidate_class.document_id.in_([doc.id for doc in docs]))
.order_by(candidate_class.id)
.all()
)
if sort:
cands = sorted(
cands,
key=lambda x: " ".join(
[x[i][0].get_stable_id() for i in range(len(x))]
),
)
result.append(cands)
else:
for candidate_class in self.candidate_classes:
sub_query = (
self.session.query(Candidate.id)
.filter(Candidate.split == split)
.subquery()
)
cands = (
self.session.query(candidate_class)
.filter(candidate_class.id.in_(sub_query))
.order_by(candidate_class.id)
.all()
)
if sort:
cands = sorted(
cands,
key=lambda x: " ".join(
[x[i][0].get_stable_id() for i in range(len(x))]
),
)
result.append(cands)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'checked'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '29', '35', '41', '52', '60', '67']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ListItem'},{'id': '18', 'type': 'argument_list', 'children': ['19', '24']},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parent_server_id'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'server_id'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'checked'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'checked'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '41', 'type': 'if_statement', 'children': ['42', '45']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '59', 'type': 'True', 'children': []},{'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': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'touch'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'True', 'children': []},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'node'} | def add(self, text, checked=False, sort=None):
node = ListItem(parent_id=self.id, parent_server_id=self.server_id)
node.checked = checked
node.text = text
if sort is not None:
node.sort = sort
self.append(node, True)
self.touch(True)
return node |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'items_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '6', 'type': 'block', 'children': ['7', '148', '188']},{'id': '7', 'type': 'class_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '9', 'type': 'argument_list', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '11', 'type': 'block', 'children': ['12', '58', '73', '88', '103', '118', '133']},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '17']},{'id': '13', 'type': 'function_name', 'children': [], 'value': '__cmp__'},{'id': '14', 'type': 'parameters', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '17', 'type': 'block', 'children': ['18', '56']},{'id': '18', 'type': 'for_statement', 'children': ['19', '22', '31']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'b'},{'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': 'six'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'moves'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'zip_longest'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '!='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '36', 'type': 'block', 'children': ['37', '44', '52']},{'id': '37', 'type': 'if_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '-'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'function_definition', 'children': ['59', '60', '63']},{'id': '59', 'type': 'function_name', 'children': [], 'value': '__lt__'},{'id': '60', 'type': 'parameters', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '72'], 'value': '<'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '__cmp__'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'function_definition', 'children': ['74', '75', '78']},{'id': '74', 'type': 'function_name', 'children': [], 'value': '__gt_'},{'id': '75', 'type': 'parameters', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '87'], 'value': '>'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '__cmp__'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'function_definition', 'children': ['89', '90', '93']},{'id': '89', 'type': 'function_name', 'children': [], 'value': '__le__'},{'id': '90', 'type': 'parameters', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '102'], 'value': '<='},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '__cmp__'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'function_definition', 'children': ['104', '105', '108']},{'id': '104', 'type': 'function_name', 'children': [], 'value': '__ge_'},{'id': '105', 'type': 'parameters', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '117'], 'value': '>='},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '__cmp__'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'function_definition', 'children': ['119', '120', '123']},{'id': '119', 'type': 'function_name', 'children': [], 'value': '__eq__'},{'id': '120', 'type': 'parameters', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '132'], 'value': '=='},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '__cmp__'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'function_definition', 'children': ['134', '135', '138']},{'id': '134', 'type': 'function_name', 'children': [], 'value': '__ne__'},{'id': '135', 'type': 'parameters', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '147'], 'value': '!='},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '__cmp__'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'function_definition', 'children': ['149', '150', '152']},{'id': '149', 'type': 'function_name', 'children': [], 'value': 'key_func'},{'id': '150', 'type': 'parameters', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '152', 'type': 'block', 'children': ['153', '177']},{'id': '153', 'type': 'if_statement', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'indented'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'tuple', 'children': ['163', '171']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'parent_item'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'tuple', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193', '196']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '198', 'type': 'True', 'children': []} | def items_sort(cls, items):
class t(tuple):
def __cmp__(self, other):
for a, b in six.moves.zip_longest(self, other):
if a != b:
if a is None:
return 1
if b is None:
return -1
return a - b
return 0
def __lt__(self, other):
return self.__cmp__(other) < 0
def __gt_(self, other):
return self.__cmp__(other) > 0
def __le__(self, other):
return self.__cmp__(other) <= 0
def __ge_(self, other):
return self.__cmp__(other) >= 0
def __eq__(self, other):
return self.__cmp__(other) == 0
def __ne__(self, other):
return self.__cmp__(other) != 0
def key_func(x):
if x.indented:
return t((int(x.parent_item.sort), int(x.sort)))
return t((int(x.sort), ))
return sorted(items, key=key_func, reverse=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'checked'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '27', '40', '47']},{'id': '13', 'type': 'if_statement', 'children': ['14', '19']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': 'is'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'InvalidException'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': "'Item has no parent'"},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'checked'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'node'} | def add(self, text, checked=False, sort=None):
if self.parent is None:
raise exception.InvalidException('Item has no parent')
node = self.parent.add(text, checked, sort)
self.indent(node)
return node |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_subsections'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'srcdir'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'examples_dir'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sortkey'},{'id': '7', 'type': 'block', 'children': ['8', '39', '51', '67', '77']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'subfolders'},{'id': '11', 'type': 'list_comprehension', 'children': ['12', '13', '21']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'subfolder'},{'id': '13', 'type': 'for_in_clause', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'subfolder'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'examples_dir'},{'id': '21', 'type': 'if_clause', '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': 'os'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'examples_dir'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'subfolder'},{'id': '38', 'type': 'string', 'children': [], 'value': "'README.txt'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'base_examples_dir_path'},{'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': 'relpath'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'examples_dir'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'srcdir'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'subfolders_with_path'},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '64']},{'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': 'os'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'base_examples_dir_path'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'subfolders'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted_subfolders'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'subfolders_with_path'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sortkey'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'list_comprehension', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'subfolders'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'list_comprehension', 'children': ['85', '91']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'subfolders_with_path'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sorted_subfolders'} | def get_subsections(srcdir, examples_dir, sortkey):
subfolders = [subfolder for subfolder in os.listdir(examples_dir)
if os.path.exists(os.path.join(
examples_dir, subfolder, 'README.txt'))]
base_examples_dir_path = os.path.relpath(examples_dir, srcdir)
subfolders_with_path = [os.path.join(base_examples_dir_path, item)
for item in subfolders]
sorted_subfolders = sorted(subfolders_with_path, key=sortkey)
return [subfolders[i] for i in [subfolders_with_path.index(item)
for item in sorted_subfolders]] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'alphabetical_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'list_to_sort'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'generic_type', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '15', 'type': 'type_parameter', 'children': ['16']},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'list_to_sort'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'norm_fold'} | def alphabetical_sort(list_to_sort: Iterable[str]) -> List[str]:
return sorted(list_to_sort, key=norm_fold) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'natural_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'list_to_sort'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'generic_type', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '15', 'type': 'type_parameter', 'children': ['16']},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'list_to_sort'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'natural_keys'} | def natural_sort(list_to_sort: Iterable[str]) -> List[str]:
return sorted(list_to_sort, key=natural_keys) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': '_clauses'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '21', '31', '41', '51', '61', '71', '84', '93', '105', '124', '140', '148', '174']},{'id': '10', 'type': 'if_statement', 'children': ['11', '15']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_limit'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': "'_limit'"},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_offset'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'_offset'"},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'order_by'"},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_streamed'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': "'_streamed'"},{'id': '60', 'type': 'False', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'_step'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'QUERY_STEP'},{'id': '71', 'type': 'if_statement', 'children': ['72', '79']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '76'], 'value': 'or'},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '75', 'type': 'False', 'children': []},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'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': '_step'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_args_to_order_by'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_args_to_clause'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'clauses'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_clauses'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118', '121']},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'whereclause'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_limit'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_offset'},{'id': '124', 'type': 'if_statement', 'children': ['125', '129']},{'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': 'order_by'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'list_splat', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'executable'},{'id': '148', 'type': 'if_statement', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_streamed'},{'id': '150', 'type': 'block', 'children': ['151', '163']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '154', 'type': 'call', 'children': ['155', '162']},{'id': '155', 'type': 'attribute', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'execution_options'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'stream_results'},{'id': '173', 'type': 'True', 'children': []},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ResultIter'},{'id': '177', 'type': 'argument_list', 'children': ['178', '184', '191']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'row_type'},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'row_type'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_step'} | def find(self, *_clauses, **kwargs):
if not self.exists:
return iter([])
_limit = kwargs.pop('_limit', None)
_offset = kwargs.pop('_offset', 0)
order_by = kwargs.pop('order_by', None)
_streamed = kwargs.pop('_streamed', False)
_step = kwargs.pop('_step', QUERY_STEP)
if _step is False or _step == 0:
_step = None
order_by = self._args_to_order_by(order_by)
args = self._args_to_clause(kwargs, clauses=_clauses)
query = self.table.select(whereclause=args,
limit=_limit,
offset=_offset)
if len(order_by):
query = query.order_by(*order_by)
conn = self.db.executable
if _streamed:
conn = self.db.engine.connect()
conn = conn.execution_options(stream_results=True)
return ResultIter(conn.execute(query),
row_type=self.db.row_type,
step=_step) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_write_contribs'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'type', 'children': ['5']},{'id': '5', 'type': 'None', 'children': []},{'id': '6', 'type': 'block', 'children': ['7', '11', '40', '47', '70', '77', '88', '95']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'map_file_auth'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '17']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'scantree'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'cltk'"},{'id': '17', 'type': 'block', 'children': ['18', '24', '31']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'authors_list'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_authors'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '31', 'type': 'if_statement', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'authors_list'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'map_file_auth'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'authors_list'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'map_auth_file'},{'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', '51', '56']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'authors_file'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'map_file_auth'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'authors_file'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'map_auth_file'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'map_auth_file'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sort_def_dict'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'map_auth_file'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'map_auth_file_sorted'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'map_auth_file'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'map_auth_file'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'map_auth_file_sorted'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'write_contribs'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'map_auth_file'} | def find_write_contribs() -> None:
map_file_auth = {}
for filename in scantree('cltk'):
filepath = filename.path
authors_list = get_authors(filepath)
if authors_list:
map_file_auth[filepath] = authors_list
map_auth_file = defaultdict(list)
for file, authors_file in map_file_auth.items():
for author in authors_file:
map_auth_file[author].append(file)
map_auth_file = sort_def_dict(map_auth_file)
map_auth_file_sorted = sorted(map_auth_file.items())
map_auth_file = OrderedDict(map_auth_file_sorted)
write_contribs(map_auth_file) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_files'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '5', 'type': 'block', 'children': ['6', '26', '32', '71', '87']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '11', '19']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '11', 'type': 'for_in_clause', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '19', 'type': 'if_clause', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"left"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '41']},{'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': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '41', 'type': 'block', 'children': ['42', '59']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'insert_string'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': '"right{}"'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '56']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '*'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '55', 'type': 'integer', 'children': [], 'value': '2'},{'id': '56', 'type': 'slice', 'children': ['57', '58']},{'id': '57', 'type': 'integer', 'children': [], 'value': '4'},{'id': '58', 'type': 'colon', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '64', 'type': 'argument_list', 'children': ['65', '70']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '69'], 'value': '+'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '*'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '68', 'type': 'integer', 'children': [], 'value': '2'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'insert_string'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '74', 'type': 'list_comprehension', 'children': ['75', '84']},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'files'} | def find_files(folder):
files = [i for i in os.listdir(folder) if i.startswith("left")]
files.sort()
for i in range(len(files)):
insert_string = "right{}".format(files[i * 2][4:])
files.insert(i * 2 + 1, insert_string)
files = [os.path.join(folder, filename) for filename in files]
return files |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cdx_load'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '18', '25', '33', '49', '55', '67', '101']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'create_merged_cdx_gen'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'page_count'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'make_obj_iter'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '33', 'type': 'if_statement', 'children': ['34', '40']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '36'], 'value': 'and'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'secondary_index_only'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'process_cdx'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'custom_ops'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'custom_ops'},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '58']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'custom_ops'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '67', 'type': 'if_statement', 'children': ['68', '73', '84']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': '=='},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '72', 'type': 'string', 'children': [], 'value': "'text'"},{'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': 'cdx_iter'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'cdx_to_text'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '84', 'type': 'elif_clause', 'children': ['85', '90']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '=='},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '89', 'type': 'string', 'children': [], 'value': "'json'"},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cdx_to_json'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'} | def cdx_load(sources, query, process=True):
cdx_iter = create_merged_cdx_gen(sources, query)
if query.page_count:
return cdx_iter
cdx_iter = make_obj_iter(cdx_iter, query)
if process and not query.secondary_index_only:
cdx_iter = process_cdx(cdx_iter, query)
custom_ops = query.custom_ops
for op in custom_ops:
cdx_iter = op(cdx_iter, query)
if query.output == 'text':
cdx_iter = cdx_to_text(cdx_iter, query.fields)
elif query.output == 'json':
cdx_iter = cdx_to_json(cdx_iter, query.fields)
return cdx_iter |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cdx_sort_closest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'closest'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '8', 'type': 'integer', 'children': [], 'value': '10'},{'id': '9', 'type': 'block', 'children': ['10', '14', '18', '25', '104']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'closest_cdx'},{'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': 'closest_keys'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'closest_sec'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'timestamp_to_sec'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'closest'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cdx'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cdx_iter'},{'id': '28', 'type': 'block', 'children': ['29', '38', '47', '57', '65', '73', '90']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sec'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'timestamp_to_sec'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cdx'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'TIMESTAMP'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '-'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'closest_sec'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sec'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'bisect_right'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'closest_keys'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'closest_keys'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'closest_cdx'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'cdx'},{'id': '73', 'type': 'if_statement', 'children': ['74', '80']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '=='},{'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': 'closest_cdx'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'if_statement', 'children': ['82', '88']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '>'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'closest_keys'},{'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '-'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'break_statement', 'children': []},{'id': '90', 'type': 'if_statement', 'children': ['91', '97']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '96'], 'value': '>'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'closest_cdx'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'closest_cdx'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'for_statement', 'children': ['105', '106', '107']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'cdx'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'closest_cdx'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'yield', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cdx'} | def cdx_sort_closest(closest, cdx_iter, limit=10):
closest_cdx = []
closest_keys = []
closest_sec = timestamp_to_sec(closest)
for cdx in cdx_iter:
sec = timestamp_to_sec(cdx[TIMESTAMP])
key = abs(closest_sec - sec)
i = bisect.bisect_right(closest_keys, key)
closest_keys.insert(i, key)
closest_cdx.insert(i, cdx)
if len(closest_cdx) == limit:
if key > closest_keys[-1]:
break
if len(closest_cdx) > limit:
closest_cdx.pop()
for cdx in closest_cdx:
yield cdx |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_prefix'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'takewhile'},{'id': '12', 'type': 'argument_list', 'children': ['13', '22']},{'id': '13', 'type': 'lambda', 'children': ['14', '16']},{'id': '14', 'type': 'lambda_parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'} | def iter_prefix(reader, key):
return itertools.takewhile(
lambda line: line.startswith(key),
search(reader, key)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_basis_dict'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '5', 'type': 'block', 'children': ['6', '50', '67', '91', '110', '163']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_keyorder'},{'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49'], 'value': "[\n 'molssi_bse_schema', 'schema_type', 'schema_version',\n 'jkfit', 'jfit', 'rifit', 'admmfit', 'dftxfit', 'dftjfit',\n 'name', 'names', 'aliases', 'flags', 'family', 'description', 'role', 'auxiliaries',\n 'notes', 'function_types',\n 'reference_description', 'reference_keys',\n 'version', 'revision_description',\n 'data_source',\n 'elements', 'references', 'ecp_electrons',\n 'electron_shells', 'ecp_potentials', 'components',\n 'function_type', 'region', 'angular_momentum', 'exponents',\n 'coefficients',\n 'ecp_type', 'angular_momentum', 'r_exponents', 'gaussian_exponents',\n 'coefficients'\n ]"},{'id': '10', 'type': 'string', 'children': [], 'value': "'molssi_bse_schema'"},{'id': '11', 'type': 'string', 'children': [], 'value': "'schema_type'"},{'id': '12', 'type': 'string', 'children': [], 'value': "'schema_version'"},{'id': '13', 'type': 'string', 'children': [], 'value': "'jkfit'"},{'id': '14', 'type': 'string', 'children': [], 'value': "'jfit'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'rifit'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'admmfit'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'dftxfit'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'dftjfit'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'names'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'aliases'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'flags'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'family'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'role'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'auxiliaries'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'notes'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'function_types'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'reference_description'"},{'id': '30', 'type': 'string', 'children': [], 'value': "'reference_keys'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '32', 'type': 'string', 'children': [], 'value': "'revision_description'"},{'id': '33', 'type': 'string', 'children': [], 'value': "'data_source'"},{'id': '34', 'type': 'string', 'children': [], 'value': "'elements'"},{'id': '35', 'type': 'string', 'children': [], 'value': "'references'"},{'id': '36', 'type': 'string', 'children': [], 'value': "'ecp_electrons'"},{'id': '37', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'ecp_potentials'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'components'"},{'id': '40', 'type': 'string', 'children': [], 'value': "'function_type'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'region'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '44', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'ecp_type'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'r_exponents'"},{'id': '48', 'type': 'string', 'children': [], 'value': "'gaussian_exponents'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_keyorder'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'list_comprehension', 'children': ['57', '61']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'integer', 'children': [], 'value': '150'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '72', 'type': 'argument_list', 'children': ['73', '78']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '80', 'type': 'lambda', 'children': ['81', '83']},{'id': '81', 'type': 'lambda_parameters', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_keyorder'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'if_statement', 'children': ['92', '93', '101']},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_use_odict'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '110', 'type': 'for_statement', 'children': ['111', '114', '119']},{'id': '111', 'type': 'pattern_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'if_statement', 'children': ['121', '126', '136']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'sort_basis_dict'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '136', 'type': 'elif_clause', 'children': ['137', '142']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '148', 'type': 'list_comprehension', 'children': ['149', '160']},{'id': '149', 'type': 'conditional_expression', 'children': ['150', '154', '159'], 'value': 'if'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'sort_basis_dict'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': 'x'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '163', 'type': 'return_statement', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'bs_sorted'} | def sort_basis_dict(bs):
_keyorder = [
'molssi_bse_schema', 'schema_type', 'schema_version',
'jkfit', 'jfit', 'rifit', 'admmfit', 'dftxfit', 'dftjfit',
'name', 'names', 'aliases', 'flags', 'family', 'description', 'role', 'auxiliaries',
'notes', 'function_types',
'reference_description', 'reference_keys',
'version', 'revision_description',
'data_source',
'elements', 'references', 'ecp_electrons',
'electron_shells', 'ecp_potentials', 'components',
'function_type', 'region', 'angular_momentum', 'exponents',
'coefficients',
'ecp_type', 'angular_momentum', 'r_exponents', 'gaussian_exponents',
'coefficients'
]
_keyorder.extend([str(x) for x in range(150)])
bs_sorted = sorted(bs.items(), key=lambda x: _keyorder.index(x[0]))
if _use_odict:
bs_sorted = OrderedDict(bs_sorted)
else:
bs_sorted = dict(bs_sorted)
for k, v in bs_sorted.items():
if isinstance(v, dict):
bs_sorted[k] = sort_basis_dict(v)
elif isinstance(v, list):
bs_sorted[k] = [sort_basis_dict(x) if isinstance(x, dict) else x for x in v]
return bs_sorted |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_shell'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '21', '38', '66', '77', '96', '114', '124', '136', '151', '179', '187', '205', '215', '221']},{'id': '9', 'type': 'if_statement', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'list_splat', 'children': ['35']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '37', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nonzero_idx'},{'id': '41', 'type': 'list_comprehension', 'children': ['42', '63']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '44', 'type': 'argument_list', 'children': ['45', '62']},{'id': '45', 'type': 'generator_expression', 'children': ['46', '47', '55']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '51']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '55', 'type': 'if_clause', 'children': ['56']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '!='},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '61', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'for_in_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '71', 'type': 'argument_list', 'children': ['72', '75', '76']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '74', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'nonzero_idx'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '86', 'type': 'lambda', 'children': ['87', '89']},{'id': '87', 'type': 'lambda_parameters', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '89', 'type': 'unary_operator', 'children': ['90'], 'value': '-'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'integer', 'children': [], 'value': '0'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '105', 'type': 'lambda', 'children': ['106', '108']},{'id': '106', 'type': 'lambda_parameters', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '113', 'type': 'integer', 'children': [], 'value': '2'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '117', 'type': 'list_comprehension', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '128', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '129', 'type': 'list_comprehension', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'for_in_clause', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'list_splat', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'nonzero_idx'},{'id': '154', 'type': 'list_comprehension', 'children': ['155', '176']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '157', 'type': 'argument_list', 'children': ['158', '175']},{'id': '158', 'type': 'generator_expression', 'children': ['159', '160', '168']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '164']},{'id': '161', 'type': 'pattern_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '168', 'type': 'if_clause', 'children': ['169']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '174'], 'value': '!='},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '174', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '175', 'type': 'None', 'children': []},{'id': '176', 'type': 'for_in_clause', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'nonzero_idx'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '196', 'type': 'lambda', 'children': ['197', '199']},{'id': '197', 'type': 'lambda_parameters', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '208', 'type': 'list_comprehension', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '211', 'type': 'integer', 'children': [], 'value': '0'},{'id': '212', 'type': 'for_in_clause', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '220']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '219', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'tmp_c'},{'id': '221', 'type': 'return_statement', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'shell'} | def sort_shell(shell, use_copy=True):
if use_copy:
shell = copy.deepcopy(shell)
tmp_c = list(map(list, zip(*shell['coefficients'])))
nonzero_idx = [next((i for i, x in enumerate(c) if float(x) != 0.0), None) for c in tmp_c]
tmp = zip(shell['exponents'], tmp_c, nonzero_idx)
tmp = sorted(tmp, key=lambda x: -float(x[0]))
tmp = sorted(tmp, key=lambda x: int(x[2]))
tmp_c = [x[1] for x in tmp]
shell['exponents'] = [x[0] for x in tmp]
tmp_c = list(map(list, zip(*tmp_c)))
nonzero_idx = [next((i for i, x in enumerate(c) if float(x) != 0.0), None) for c in tmp_c]
tmp = zip(tmp_c, nonzero_idx)
tmp = sorted(tmp, key=lambda x: int(x[1]))
tmp_c = [x[0] for x in tmp]
shell['coefficients'] = tmp_c
return shell |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_shells'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'shells'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '21', '33']},{'id': '9', 'type': 'if_statement', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'shells'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'shells'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'shells'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '30']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_shell'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'shells'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'shells'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'lambda', 'children': ['44', '46']},{'id': '44', 'type': 'lambda_parameters', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'tuple', 'children': ['47', '53', '60', '67']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '53', 'type': 'unary_operator', 'children': ['54'], 'value': '-'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '59', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '60', 'type': 'unary_operator', 'children': ['61'], 'value': '-'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '66', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '67', 'type': 'unary_operator', 'children': ['68'], 'value': '-'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'string', 'children': [], 'value': "'exponents'"} | def sort_shells(shells, use_copy=True):
if use_copy:
shells = copy.deepcopy(shells)
shells = [sort_shell(sh, False) for sh in shells]
return list(
sorted(
shells,
key=lambda x: (max(x['angular_momentum']), -len(x['exponents']), -len(x['coefficients']), -float(
max(x['exponents']))))) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_potentials'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'potentials'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '21', '39', '51']},{'id': '9', 'type': 'if_statement', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'potentials'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'potentials'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'potentials'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'potentials'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'lambda', 'children': ['34', '36']},{'id': '34', 'type': 'lambda_parameters', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'potentials'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'potentials'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'potentials'} | def sort_potentials(potentials, use_copy=True):
if use_copy:
potentials = copy.deepcopy(potentials)
potentials = list(sorted(potentials, key=lambda x: x['angular_momentum']))
potentials.insert(0, potentials.pop())
return potentials |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_basis'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '21', '67']},{'id': '9', 'type': 'if_statement', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '21', 'type': 'for_statement', 'children': ['22', '25', '32']},{'id': '22', 'type': 'pattern_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '29', 'type': 'string', 'children': [], 'value': "'elements'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '50']},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'in'},{'id': '35', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '42', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_shells'},{'id': '45', 'type': 'argument_list', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '48', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '49', 'type': 'False', 'children': []},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'string', 'children': [], 'value': "'ecp_potentials'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '59', 'type': 'string', 'children': [], 'value': "'ecp_potentials'"},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_potentials'},{'id': '62', 'type': 'argument_list', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '65', 'type': 'string', 'children': [], 'value': "'ecp_potentials'"},{'id': '66', 'type': 'False', 'children': []},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort_basis_dict'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'basis'} | def sort_basis(basis, use_copy=True):
if use_copy:
basis = copy.deepcopy(basis)
for k, el in basis['elements'].items():
if 'electron_shells' in el:
el['electron_shells'] = sort_shells(el['electron_shells'], False)
if 'ecp_potentials' in el:
el['ecp_potentials'] = sort_potentials(el['ecp_potentials'], False)
return sort_basis_dict(basis) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_single_reference'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ref_entry'},{'id': '5', 'type': 'block', 'children': ['6', '29', '53']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_keyorder'},{'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28'], 'value': "[\n 'schema_type', 'schema_version',\n 'type',\n 'authors', 'title', 'booktitle', 'series', 'editors', 'journal',\n 'institution', 'volume', 'number', 'page', 'year', 'note', 'publisher',\n 'address', 'isbn', 'doi'\n ]"},{'id': '10', 'type': 'string', 'children': [], 'value': "'schema_type'"},{'id': '11', 'type': 'string', 'children': [], 'value': "'schema_version'"},{'id': '12', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '13', 'type': 'string', 'children': [], 'value': "'authors'"},{'id': '14', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'booktitle'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'series'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'editors'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'journal'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'institution'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'volume'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'number'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'note'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'publisher'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'address'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'isbn'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'doi'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted_entry'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '34', 'type': 'argument_list', 'children': ['35', '40']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ref_entry'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': 'lambda', 'children': ['43', '45']},{'id': '43', 'type': 'lambda_parameters', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_keyorder'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'if_statement', 'children': ['54', '55', '61']},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_use_odict'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sorted_entry'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted_entry'} | def sort_single_reference(ref_entry):
_keyorder = [
'schema_type', 'schema_version',
'type',
'authors', 'title', 'booktitle', 'series', 'editors', 'journal',
'institution', 'volume', 'number', 'page', 'year', 'note', 'publisher',
'address', 'isbn', 'doi'
]
sorted_entry = sorted(ref_entry.items(), key=lambda x: _keyorder.index(x[0]))
if _use_odict:
return OrderedDict(sorted_entry)
else:
return dict(sorted_entry) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_references_dict'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '5', 'type': 'block', 'children': ['6', '23', '31', '53']},{'id': '6', 'type': 'if_statement', 'children': ['7', '8', '15']},{'id': '7', 'type': 'identifier', 'children': [], 'value': '_use_odict'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'refs_sorted'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'else_clause', 'children': ['16']},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'refs_sorted'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'refs_sorted'},{'id': '27', 'type': 'string', 'children': [], 'value': "'molssi_bse_schema'"},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '30', 'type': 'string', 'children': [], 'value': "'molssi_bse_schema'"},{'id': '31', 'type': 'for_statement', 'children': ['32', '35', '43']},{'id': '32', 'type': 'pattern_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'refs_sorted'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort_single_reference'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'refs_sorted'} | def sort_references_dict(refs):
if _use_odict:
refs_sorted = OrderedDict()
else:
refs_sorted = dict()
refs_sorted['molssi_bse_schema'] = refs['molssi_bse_schema']
for k, v in sorted(refs.items()):
refs_sorted[k] = sort_single_reference(v)
return refs_sorted |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_general'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '22', '276']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'zero'},{'id': '12', 'type': 'string', 'children': [], 'value': "'0.00000000'"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'uncontract_spdf'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'use_copy'},{'id': '22', 'type': 'for_statement', 'children': ['23', '26', '33']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '30', 'type': 'string', 'children': [], 'value': "'elements'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '41', '45', '68', '75', '79', '270']},{'id': '34', 'type': 'if_statement', 'children': ['35', '39']},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'in'},{'id': '37', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'continue_statement', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'all_am'},{'id': '44', 'type': 'list', 'children': [], 'value': '[]'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '49', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'if_statement', 'children': ['52', '58']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': 'in'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '56', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'all_am'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'all_am'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '67', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'all_am'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'all_am'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'newshells'},{'id': '78', 'type': 'list', 'children': [], 'value': '[]'},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'am'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'all_am'},{'id': '82', 'type': 'block', 'children': ['83', '102', '127', '136', '140', '263']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'newsh'},{'id': '86', 'type': 'dictionary', 'children': ['87', '90', '93', '96', '99']},{'id': '87', 'type': 'pair', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'am'},{'id': '90', 'type': 'pair', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '92', 'type': 'list', 'children': [], 'value': '[]'},{'id': '93', 'type': 'pair', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '95', 'type': 'list', 'children': [], 'value': '[]'},{'id': '96', 'type': 'pair', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': "'region'"},{'id': '98', 'type': 'string', 'children': [], 'value': "''"},{'id': '99', 'type': 'pair', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': "'function_type'"},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': 'for_statement', 'children': ['103', '104', '107']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '106', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '107', 'type': 'block', 'children': ['108', '116']},{'id': '108', 'type': 'if_statement', 'children': ['109', '114']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '!='},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '112', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'am'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'continue_statement', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'newsh'},{'id': '121', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '126', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'nprim'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'newsh'},{'id': '135', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'cur_prim'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '145']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '144', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '145', 'type': 'block', 'children': ['146', '154', '169', '175', '181', '195', '204', '254']},{'id': '146', 'type': 'if_statement', 'children': ['147', '152']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '151'], 'value': '!='},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '150', 'type': 'string', 'children': [], 'value': "'angular_momentum'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'am'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'continue_statement', 'children': []},{'id': '154', 'type': 'if_statement', 'children': ['155', '160']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '159'], 'value': 'is'},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'newsh'},{'id': '158', 'type': 'string', 'children': [], 'value': "'function_type'"},{'id': '159', 'type': 'None', 'children': []},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'newsh'},{'id': '165', 'type': 'string', 'children': [], 'value': "'function_type'"},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '168', 'type': 'string', 'children': [], 'value': "'function_type'"},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'ft1'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'newsh'},{'id': '174', 'type': 'string', 'children': [], 'value': "'function_type'"},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ft2'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '180', 'type': 'string', 'children': [], 'value': "'function_type'"},{'id': '181', 'type': 'if_statement', 'children': ['182', '189']},{'id': '182', 'type': 'boolean_operator', 'children': ['183', '186'], 'value': 'and'},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'not'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ft1'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ft2'},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'not'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ft2'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ft1'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'raise_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'string', 'children': [], 'value': '"Cannot make general contraction of different function types"'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ngen'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '203', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '204', 'type': 'for_statement', 'children': ['205', '206', '210']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ngen'},{'id': '210', 'type': 'block', 'children': ['211', '218', '229', '245']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '217'], 'value': '*'},{'id': '215', 'type': 'list', 'children': ['216'], 'value': '[zero]'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'zero'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'cur_prim'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'subscript', 'children': ['225', '228']},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '227', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'binary_operator', 'children': ['236', '238'], 'value': '*'},{'id': '236', 'type': 'list', 'children': ['237'], 'value': '[zero]'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'zero'},{'id': '238', 'type': '()', 'children': ['239']},{'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '-'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'nprim'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'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': 'newsh'},{'id': '250', 'type': 'string', 'children': [], 'value': "'coefficients'"},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'augmented_assignment', 'children': ['256', '257'], 'value': '+='},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'cur_prim'},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'sh'},{'id': '262', 'type': 'string', 'children': [], 'value': "'exponents'"},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'newshells'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'newsh'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '275']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '274', 'type': 'string', 'children': [], 'value': "'electron_shells'"},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'newshells'},{'id': '276', 'type': 'return_statement', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'basis'} | def make_general(basis, use_copy=True):
zero = '0.00000000'
basis = uncontract_spdf(basis, 0, use_copy)
for k, el in basis['elements'].items():
if not 'electron_shells' in el:
continue
all_am = []
for sh in el['electron_shells']:
if not sh['angular_momentum'] in all_am:
all_am.append(sh['angular_momentum'])
all_am = sorted(all_am)
newshells = []
for am in all_am:
newsh = {
'angular_momentum': am,
'exponents': [],
'coefficients': [],
'region': '',
'function_type': None,
}
for sh in el['electron_shells']:
if sh['angular_momentum'] != am:
continue
newsh['exponents'].extend(sh['exponents'])
nprim = len(newsh['exponents'])
cur_prim = 0
for sh in el['electron_shells']:
if sh['angular_momentum'] != am:
continue
if newsh['function_type'] is None:
newsh['function_type'] = sh['function_type']
ft1 = newsh['function_type']
ft2 = sh['function_type']
if ft1 not in ft2 and ft2 not in ft1:
raise RuntimeError("Cannot make general contraction of different function types")
ngen = len(sh['coefficients'])
for g in range(ngen):
coef = [zero] * cur_prim
coef.extend(sh['coefficients'][g])
coef.extend([zero] * (nprim - len(coef)))
newsh['coefficients'].append(coef)
cur_prim += len(sh['exponents'])
newshells.append(newsh)
el['electron_shells'] = newshells
return basis |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ComputeApplicationUniquifier'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hash_obj'},{'id': '5', 'type': 'block', 'children': ['6', '144', '193', '259']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '14']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'ProcessDirectory'},{'id': '8', 'type': 'parameters', 'children': ['9', '10', '11']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'relative_path'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'block', 'children': ['15', '21', '36', '42']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '>'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_MAX_DEPTH'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': []},{'id': '21', 'type': 'try_statement', 'children': ['22', '32']},{'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': 'names'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '32', 'type': 'except_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '48']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '48', 'type': 'block', 'children': ['49', '61']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'current_path'},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '61', 'type': 'if_statement', 'children': ['62', '71', '121']},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'current_path'},{'id': '71', 'type': 'block', 'children': ['72', '85', '94', '100', '107']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'pattern_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '77', 'type': 'call', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'if_statement', 'children': ['86', '92']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'not'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '88', 'type': 'tuple', 'children': ['89', '90', '91']},{'id': '89', 'type': 'string', 'children': [], 'value': "'.py'"},{'id': '90', 'type': 'string', 'children': [], 'value': "'.pyc'"},{'id': '91', 'type': 'string', 'children': [], 'value': "'.pyo'"},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'continue_statement', 'children': []},{'id': '94', 'type': 'if_statement', 'children': ['95', '98']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'continue_statement', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ProcessApplicationFile'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'current_path'},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'relative_path'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '121', 'type': 'elif_clause', 'children': ['122', '126']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'IsPackage'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'current_path'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ProcessDirectory'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132', '141']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'current_path'},{'id': '132', 'type': 'call', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'relative_path'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '+'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'function_definition', 'children': ['145', '146', '148']},{'id': '145', 'type': 'function_name', 'children': [], 'value': 'IsPackage'},{'id': '146', 'type': 'parameters', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '148', 'type': 'block', 'children': ['149', '161']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'init_base_path'},{'id': '152', 'type': 'call', 'children': ['153', '158']},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '160', 'type': 'string', 'children': [], 'value': "'__init__.py'"},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': '()', 'children': ['163']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '183'], 'value': 'or'},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '173'], 'value': 'or'},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'init_base_path'},{'id': '173', 'type': 'call', 'children': ['174', '179']},{'id': '174', 'type': 'attribute', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '+'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'init_base_path'},{'id': '182', 'type': 'string', 'children': [], 'value': "'c'"},{'id': '183', 'type': 'call', 'children': ['184', '189']},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '+'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'init_base_path'},{'id': '192', 'type': 'string', 'children': [], 'value': "'o'"},{'id': '193', 'type': 'function_definition', 'children': ['194', '195', '198']},{'id': '194', 'type': 'function_name', 'children': [], 'value': 'ProcessApplicationFile'},{'id': '195', 'type': 'parameters', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'relative_path'},{'id': '198', 'type': 'block', 'children': ['199', '210', '221', '248']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'hash_obj'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'relative_path'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'hash_obj'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'string', 'children': [], 'value': "':'"},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'try_statement', 'children': ['222', '244']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'hash_obj'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '243']},{'id': '230', 'type': 'attribute', 'children': ['231', '242']},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'attribute', 'children': ['235', '241']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'st_size'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'except_clause', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'pass_statement', 'children': []},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'hash_obj'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '258', 'type': 'argument_list', 'children': []},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'ProcessDirectory'},{'id': '262', 'type': 'argument_list', 'children': ['263', '268']},{'id': '263', 'type': 'subscript', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '267', 'type': 'integer', 'children': [], 'value': '0'},{'id': '268', 'type': 'string', 'children': [], 'value': "''"} | def ComputeApplicationUniquifier(hash_obj):
def ProcessDirectory(path, relative_path, depth=1):
if depth > _MAX_DEPTH:
return
try:
names = os.listdir(path)
except BaseException:
return
modules = set()
for name in sorted(names):
current_path = os.path.join(path, name)
if not os.path.isdir(current_path):
file_name, ext = os.path.splitext(name)
if ext not in ('.py', '.pyc', '.pyo'):
continue
if file_name in modules:
continue
modules.add(file_name)
ProcessApplicationFile(current_path, os.path.join(relative_path, name))
elif IsPackage(current_path):
ProcessDirectory(current_path,
os.path.join(relative_path, name),
depth + 1)
def IsPackage(path):
init_base_path = os.path.join(path, '__init__.py')
return (os.path.isfile(init_base_path) or
os.path.isfile(init_base_path + 'c') or
os.path.isfile(init_base_path + 'o'))
def ProcessApplicationFile(path, relative_path):
hash_obj.update(relative_path.encode())
hash_obj.update(':'.encode())
try:
hash_obj.update(str(os.stat(path).st_size).encode())
except BaseException:
pass
hash_obj.update('\n'.encode())
ProcessDirectory(sys.path[0], '') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_player'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '114', '141', '152', '158']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'players'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '21']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_mpris_players'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '87']},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'not'},{'id': '24', 'type': 'string', 'children': [], 'value': '"_priority"'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '26', 'type': 'block', 'children': ['27', '76']},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '70']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'player_priority'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'try_statement', 'children': ['33', '47']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'priority'},{'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': 'player_priority'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '46', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '47', 'type': 'except_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'try_statement', 'children': ['51', '63']},{'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': 'priority'},{'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': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'player_priority'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '63', 'type': 'except_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '69', 'type': 'None', 'children': []},{'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', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '85', 'type': 'string', 'children': [], 'value': '"_priority"'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '87', 'type': 'if_statement', 'children': ['88', '96']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '95'], 'value': 'is'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': '"_priority"'},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'players'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'tuple', 'children': ['104', '107', '110', '113']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '106', 'type': 'string', 'children': [], 'value': '"_state_priority"'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '109', 'type': 'string', 'children': [], 'value': '"_priority"'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '112', 'type': 'string', 'children': [], 'value': '"index"'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '114', 'type': 'if_statement', 'children': ['115', '116', '135']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'players'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'top_player'},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_mpris_players'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'subscript', 'children': ['128', '134']},{'id': '128', 'type': 'subscript', 'children': ['129', '133']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'players'},{'id': '133', 'type': 'integer', 'children': [], 'value': '0'},{'id': '134', 'type': 'integer', 'children': [], 'value': '3'},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'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': 'top_player'},{'id': '140', 'type': 'dictionary', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_player'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'top_player'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': '"_dbus_player"'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_player_details'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'top_player'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '165']},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'py3'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '165', 'type': 'argument_list', 'children': []} | def _set_player(self):
players = []
for name, p in self._mpris_players.items():
if "_priority" not in p:
if self.player_priority:
try:
priority = self.player_priority.index(p["name"])
except ValueError:
try:
priority = self.player_priority.index("*")
except ValueError:
priority = None
else:
priority = 0
if priority is not None:
p["_priority"] = priority
if p.get("_priority") is not None:
players.append((p["_state_priority"], p["_priority"], p["index"], name))
if players:
top_player = self._mpris_players.get(sorted(players)[0][3])
else:
top_player = {}
self._player = top_player.get("_dbus_player")
self._player_details = top_player
self.py3.update() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'file_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'my_list'},{'id': '5', 'type': 'block', 'children': ['6', '33', '42']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'alphanum_key'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'list_comprehension', 'children': ['13', '24']},{'id': '13', 'type': 'conditional_expression', 'children': ['14', '18', '23'], 'value': 'if'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '"([0-9]+)"'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'my_list'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'alphanum_key'},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'my_list'} | def file_sort(my_list):
def alphanum_key(key):
return [int(s) if s.isdigit() else s for s in re.split("([0-9]+)", key)]
my_list.sort(key=alphanum_key)
return my_list |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'squad'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 't_out'},{'id': '7', 'type': 'block', 'children': ['8', '33', '47', '119', '214', '222', '232', '242', '264', '275', '297', '308', '319', '340', '357', '376']},{'id': '8', 'type': 'if_statement', 'children': ['9', '20']},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '15'], 'value': 'or'},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': '=='},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '19'], 'value': '=='},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 't_out'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'tuple', 'children': []},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'quaternion'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'i_in_for_out'},{'id': '36', 'type': 'binary_operator', 'children': ['37', '46'], 'value': '-'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 't_out'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '45', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '*'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'binary_operator', 'children': ['58', '118'], 'value': '*'},{'id': '58', 'type': '()', 'children': ['59']},{'id': '59', 'type': 'binary_operator', 'children': ['60', '78'], 'value': '+'},{'id': '60', 'type': 'unary_operator', 'children': ['61'], 'value': '-'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '70'], 'value': '*'},{'id': '67', 'type': '()', 'children': ['68']},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '~'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'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': 'roll'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '76', 'type': 'unary_operator', 'children': ['77'], 'value': '-'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '95'], 'value': '*'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '94'], 'value': '*'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '~'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '95', 'type': '()', 'children': ['96']},{'id': '96', 'type': 'binary_operator', 'children': ['97', '108'], 'value': '/'},{'id': '97', 'type': '()', 'children': ['98']},{'id': '98', 'type': 'binary_operator', 'children': ['99', '107'], 'value': '-'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '108', 'type': '()', 'children': ['109']},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '-'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'float', 'children': [], 'value': '0.25'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '131'], 'value': '*'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '129', 'type': 'unary_operator', 'children': ['130'], 'value': '-'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'binary_operator', 'children': ['137', '212'], 'value': '*'},{'id': '137', 'type': '()', 'children': ['138']},{'id': '138', 'type': 'binary_operator', 'children': ['139', '195'], 'value': '-'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '164'], 'value': '*'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'binary_operator', 'children': ['146', '156'], 'value': '*'},{'id': '146', 'type': '()', 'children': ['147']},{'id': '147', 'type': 'unary_operator', 'children': ['148'], 'value': '~'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '154', 'type': 'unary_operator', 'children': ['155'], 'value': '-'},{'id': '155', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'roll'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '162', 'type': 'unary_operator', 'children': ['163'], 'value': '-'},{'id': '163', 'type': 'integer', 'children': [], 'value': '2'},{'id': '164', 'type': '()', 'children': ['165']},{'id': '165', 'type': 'binary_operator', 'children': ['166', '177'], 'value': '/'},{'id': '166', 'type': '()', 'children': ['167']},{'id': '167', 'type': 'binary_operator', 'children': ['168', '176'], 'value': '-'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '174', 'type': 'unary_operator', 'children': ['175'], 'value': '-'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '177', 'type': '()', 'children': ['178']},{'id': '178', 'type': 'binary_operator', 'children': ['179', '187'], 'value': '-'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '185', 'type': 'unary_operator', 'children': ['186'], 'value': '-'},{'id': '186', 'type': 'integer', 'children': [], 'value': '2'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '193', 'type': 'unary_operator', 'children': ['194'], 'value': '-'},{'id': '194', 'type': 'integer', 'children': [], 'value': '1'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '204'], 'value': '*'},{'id': '201', 'type': '()', 'children': ['202']},{'id': '202', 'type': 'unary_operator', 'children': ['203'], 'value': '~'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '210', 'type': 'unary_operator', 'children': ['211'], 'value': '-'},{'id': '211', 'type': 'integer', 'children': [], 'value': '1'},{'id': '212', 'type': 'unary_operator', 'children': ['213'], 'value': '-'},{'id': '213', 'type': 'float', 'children': [], 'value': '0.25'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '219']},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '218', 'type': 'integer', 'children': [], 'value': '0'},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '228']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '226', 'type': 'unary_operator', 'children': ['227'], 'value': '-'},{'id': '227', 'type': 'integer', 'children': [], 'value': '1'},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '230', 'type': 'unary_operator', 'children': ['231'], 'value': '-'},{'id': '231', 'type': 'integer', 'children': [], 'value': '1'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '238']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '236', 'type': 'unary_operator', 'children': ['237'], 'value': '-'},{'id': '237', 'type': 'integer', 'children': [], 'value': '2'},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '240', 'type': 'unary_operator', 'children': ['241'], 'value': '-'},{'id': '241', 'type': 'integer', 'children': [], 'value': '1'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '248']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '246', 'type': 'unary_operator', 'children': ['247'], 'value': '-'},{'id': '247', 'type': 'integer', 'children': [], 'value': '1'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '260'], 'value': '*'},{'id': '249', 'type': 'binary_operator', 'children': ['250', '254'], 'value': '*'},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '252', 'type': 'unary_operator', 'children': ['253'], 'value': '-'},{'id': '253', 'type': 'integer', 'children': [], 'value': '1'},{'id': '254', 'type': '()', 'children': ['255']},{'id': '255', 'type': 'unary_operator', 'children': ['256'], 'value': '~'},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '258', 'type': 'unary_operator', 'children': ['259'], 'value': '-'},{'id': '259', 'type': 'integer', 'children': [], 'value': '2'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '262', 'type': 'unary_operator', 'children': ['263'], 'value': '-'},{'id': '263', 'type': 'integer', 'children': [], 'value': '1'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'R_ip1'},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '271', 'type': 'argument_list', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '273', 'type': 'unary_operator', 'children': ['274'], 'value': '-'},{'id': '274', 'type': 'integer', 'children': [], 'value': '1'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '281']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'R_ip1'},{'id': '279', 'type': 'unary_operator', 'children': ['280'], 'value': '-'},{'id': '280', 'type': 'integer', 'children': [], 'value': '1'},{'id': '281', 'type': 'binary_operator', 'children': ['282', '293'], 'value': '*'},{'id': '282', 'type': 'binary_operator', 'children': ['283', '287'], 'value': '*'},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '285', 'type': 'unary_operator', 'children': ['286'], 'value': '-'},{'id': '286', 'type': 'integer', 'children': [], 'value': '1'},{'id': '287', 'type': '()', 'children': ['288']},{'id': '288', 'type': 'unary_operator', 'children': ['289'], 'value': '~'},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '291', 'type': 'unary_operator', 'children': ['292'], 'value': '-'},{'id': '292', 'type': 'integer', 'children': [], 'value': '2'},{'id': '293', 'type': 'subscript', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '295', 'type': 'unary_operator', 'children': ['296'], 'value': '-'},{'id': '296', 'type': 'integer', 'children': [], 'value': '1'},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'assignment', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'R_ip1'},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'subscript', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'R_ip1'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'i_in_for_out'},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 't_inp1'},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'roll'},{'id': '315', 'type': 'argument_list', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '317', 'type': 'unary_operator', 'children': ['318'], 'value': '-'},{'id': '318', 'type': 'integer', 'children': [], 'value': '1'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '325']},{'id': '321', 'type': 'subscript', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 't_inp1'},{'id': '323', 'type': 'unary_operator', 'children': ['324'], 'value': '-'},{'id': '324', 'type': 'integer', 'children': [], 'value': '1'},{'id': '325', 'type': 'binary_operator', 'children': ['326', '330'], 'value': '+'},{'id': '326', 'type': 'subscript', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '328', 'type': 'unary_operator', 'children': ['329'], 'value': '-'},{'id': '329', 'type': 'integer', 'children': [], 'value': '1'},{'id': '330', 'type': '()', 'children': ['331']},{'id': '331', 'type': 'binary_operator', 'children': ['332', '336'], 'value': '-'},{'id': '332', 'type': 'subscript', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '334', 'type': 'unary_operator', 'children': ['335'], 'value': '-'},{'id': '335', 'type': 'integer', 'children': [], 'value': '1'},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '338', 'type': 'unary_operator', 'children': ['339'], 'value': '-'},{'id': '339', 'type': 'integer', 'children': [], 'value': '2'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'tau'},{'id': '343', 'type': 'binary_operator', 'children': ['344', '350'], 'value': '/'},{'id': '344', 'type': '()', 'children': ['345']},{'id': '345', 'type': 'binary_operator', 'children': ['346', '347'], 'value': '-'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 't_out'},{'id': '347', 'type': 'subscript', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'i_in_for_out'},{'id': '350', 'type': '()', 'children': ['351']},{'id': '351', 'type': 'subscript', 'children': ['352', '356']},{'id': '352', 'type': '()', 'children': ['353']},{'id': '353', 'type': 'binary_operator', 'children': ['354', '355'], 'value': '-'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 't_inp1'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 't_in'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'i_in_for_out'},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'assignment', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'R_out'},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'squad_vectorized'},{'id': '364', 'type': 'argument_list', 'children': ['365', '366', '369', '372', '375']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'tau'},{'id': '366', 'type': 'subscript', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'R_in'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'i_in_for_out'},{'id': '369', 'type': 'subscript', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'i_in_for_out'},{'id': '372', 'type': 'subscript', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'i_in_for_out'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'R_ip1'},{'id': '376', 'type': 'return_statement', 'children': ['377']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'R_out'} | def squad(R_in, t_in, t_out):
if R_in.size == 0 or t_out.size == 0:
return np.array((), dtype=np.quaternion)
i_in_for_out = t_in.searchsorted(t_out, side='right')-1
A = R_in * np.exp((- np.log((~R_in) * np.roll(R_in, -1))
+ np.log((~np.roll(R_in, 1)) * R_in) * ((np.roll(t_in, -1) - t_in) / (t_in - np.roll(t_in, 1)))
) * 0.25)
B = np.roll(R_in, -1) * np.exp((np.log((~np.roll(R_in, -1)) * np.roll(R_in, -2))
* ((np.roll(t_in, -1) - t_in) / (np.roll(t_in, -2) - np.roll(t_in, -1)))
- np.log((~R_in) * np.roll(R_in, -1))) * -0.25)
A[0] = R_in[0]
A[-1] = R_in[-1]
B[-2] = R_in[-1]
B[-1] = R_in[-1] * (~R_in[-2]) * R_in[-1]
R_ip1 = np.roll(R_in, -1)
R_ip1[-1] = R_in[-1]*(~R_in[-2])*R_in[-1]
R_ip1 = np.array(R_ip1[i_in_for_out])
t_inp1 = np.roll(t_in, -1)
t_inp1[-1] = t_in[-1] + (t_in[-1] - t_in[-2])
tau = (t_out - t_in[i_in_for_out]) / ((t_inp1 - t_in)[i_in_for_out])
R_out = np.squad_vectorized(tau, R_in[i_in_for_out], A[i_in_for_out], B[i_in_for_out], R_ip1)
return R_out |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_resource_id'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '7', 'type': 'block', 'children': ['8', '15', '43']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'if_statement', 'children': ['20', '29']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': 'not'},{'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': 'part'},{'id': '25', 'type': 'tuple', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'float'},{'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': 'ValueError'},{'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': "'Supported data types: int, float, list, tuple, str. Got: {}'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'{}-{}'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '50', 'type': 'subscript', 'children': ['51', '67']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_hash'},{'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': "'-'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '67', 'type': 'slice', 'children': ['68', '70']},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'},{'id': '69', 'type': 'integer', 'children': [], 'value': '16'},{'id': '70', 'type': 'colon', 'children': []} | def get_resource_id(prefix, *data):
parts = flatten(data)
for part in parts:
if type(part) not in (str, int, float):
raise ValueError('Supported data types: int, float, list, tuple, str. Got: {}'.format(type(part)))
return '{}-{}'.format(
prefix,
get_hash('-'.join(sorted(map(str, parts))))[-16:]
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '16', '28', '36', '43', '224', '236', '242', '255']},{'id': '13', 'type': 'global_statement', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'MemoryBytesSpilled'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DiskBytesSpilled'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '21', 'type': 'expression_list', 'children': ['22', '23']},{'id': '22', 'type': 'integer', 'children': [], 'value': '100'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_next_limit'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'pattern_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '33', 'type': 'expression_list', 'children': ['34', '35']},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '43', 'type': 'while_statement', 'children': ['44', '45']},{'id': '44', 'type': 'True', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '59', '66', '75', '81']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'islice'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '66', 'type': 'if_statement', 'children': ['67', '73']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '72'], 'value': '<'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'break_statement', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_used_memory'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'if_statement', 'children': ['82', '85', '207']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '>'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '85', 'type': 'block', 'children': ['86', '98', '110', '132', '157', '171', '175', '189', '200']},{'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': 'current_chunk'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '91', 'type': 'argument_list', 'children': ['92', '95']},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': '_get_path'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '110', 'type': 'with_statement', 'children': ['111', '121']},{'id': '111', 'type': 'with_clause', 'children': ['112']},{'id': '112', 'type': 'with_item', 'children': ['113']},{'id': '113', 'type': 'as_pattern', 'children': ['114', '119']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '118', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '119', 'type': 'as_pattern_target', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dump_stream'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '132', 'type': 'function_definition', 'children': ['133', '134', '136']},{'id': '133', 'type': 'function_name', 'children': [], 'value': 'load'},{'id': '134', 'type': 'parameters', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '136', 'type': 'block', 'children': ['137', '151']},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '147']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'load_stream'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'yield', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '170', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '174', 'type': 'list', 'children': [], 'value': '[]'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'augmented_assignment', 'children': ['177', '178'], 'value': '+='},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'MemoryBytesSpilled'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '188'], 'value': '<<'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '181', 'type': 'argument_list', 'children': ['182', '187']},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '-'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'get_used_memory'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'integer', 'children': [], 'value': '0'},{'id': '188', 'type': 'integer', 'children': [], 'value': '20'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'augmented_assignment', 'children': ['191', '192'], 'value': '+='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'DiskBytesSpilled'},{'id': '192', 'type': 'call', 'children': ['193', '198']},{'id': '193', 'type': 'attribute', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'getsize'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'unlink'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '207', 'type': 'elif_clause', 'children': ['208', '210']},{'id': '208', 'type': 'not_operator', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '216', 'type': 'argument_list', 'children': ['217', '223']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '*'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '222', 'type': 'float', 'children': [], 'value': '1.5'},{'id': '223', 'type': 'integer', 'children': [], 'value': '10000'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '229', 'type': 'argument_list', 'children': ['230', '233']},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '236', 'type': 'if_statement', 'children': ['237', '239']},{'id': '237', 'type': 'not_operator', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '242', 'type': 'if_statement', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'current_chunk'},{'id': '255', 'type': 'return_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '260', 'type': 'argument_list', 'children': ['261', '262', '265']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'reverse'} | def sorted(self, iterator, key=None, reverse=False):
global MemoryBytesSpilled, DiskBytesSpilled
batch, limit = 100, self._next_limit()
chunks, current_chunk = [], []
iterator = iter(iterator)
while True:
chunk = list(itertools.islice(iterator, batch))
current_chunk.extend(chunk)
if len(chunk) < batch:
break
used_memory = get_used_memory()
if used_memory > limit:
current_chunk.sort(key=key, reverse=reverse)
path = self._get_path(len(chunks))
with open(path, 'wb') as f:
self.serializer.dump_stream(current_chunk, f)
def load(f):
for v in self.serializer.load_stream(f):
yield v
f.close()
chunks.append(load(open(path, 'rb')))
current_chunk = []
MemoryBytesSpilled += max(used_memory - get_used_memory(), 0) << 20
DiskBytesSpilled += os.path.getsize(path)
os.unlink(path)
elif not chunks:
batch = min(int(batch * 1.5), 10000)
current_chunk.sort(key=key, reverse=reverse)
if not chunks:
return current_chunk
if current_chunk:
chunks.append(iter(current_chunk))
return heapq.merge(chunks, key=key, reverse=reverse) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_merge_sorted_items'},{'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', '63', '79', '144']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'load_partition'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '11', 'type': 'block', 'children': ['12', '21', '36']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_get_spill_dir'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '36', 'type': 'with_statement', 'children': ['37', '48']},{'id': '37', 'type': 'with_clause', 'children': ['38']},{'id': '38', 'type': 'with_item', 'children': ['39']},{'id': '39', 'type': 'as_pattern', 'children': ['40', '46']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '44', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '45', 'type': 'integer', 'children': [], 'value': '65536'},{'id': '46', 'type': 'as_pattern_target', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '59']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'load_stream'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'yield', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'disk_items'},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '71']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'load_partition'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'spills'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83', '101']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted_items'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'disk_items'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103', '111', '121']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ser'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'flattened_serializer'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ExternalSorter'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'memory_limit'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ser'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sorted_items'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '128', 'type': 'argument_list', 'children': ['129', '136']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'list_splat', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'disk_items'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'generator_expression', 'children': ['146', '149']},{'id': '146', 'type': 'tuple', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'vs'},{'id': '149', 'type': 'for_in_clause', 'children': ['150', '153']},{'id': '150', 'type': 'pattern_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'vs'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'GroupByKey'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sorted_items'} | def _merge_sorted_items(self, index):
def load_partition(j):
path = self._get_spill_dir(j)
p = os.path.join(path, str(index))
with open(p, 'rb', 65536) as f:
for v in self.serializer.load_stream(f):
yield v
disk_items = [load_partition(j) for j in range(self.spills)]
if self._sorted:
sorted_items = heapq.merge(disk_items, key=operator.itemgetter(0))
else:
ser = self.flattened_serializer()
sorter = ExternalSorter(self.memory_limit, ser)
sorted_items = sorter.sorted(itertools.chain(*disk_items),
key=operator.itemgetter(0))
return ((k, vs) for k, vs in GroupByKey(sorted_items)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'preservesPartitioning'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '25']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'func'},{'id': '12', 'type': 'parameters', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '19', 'type': 'argument_list', 'children': ['20', '24']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'fail_on_stopiteration'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mapPartitionsWithIndex'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'preservesPartitioning'} | def map(self, f, preservesPartitioning=False):
def func(_, iterator):
return map(fail_on_stopiteration(f), iterator)
return self.mapPartitionsWithIndex(func, preservesPartitioning) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'flatMap'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'preservesPartitioning'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '30']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'func'},{'id': '12', 'type': 'parameters', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'from_iterable'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '24', 'type': 'argument_list', 'children': ['25', '29']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'fail_on_stopiteration'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'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': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mapPartitionsWithIndex'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'preservesPartitioning'} | def flatMap(self, f, preservesPartitioning=False):
def func(s, iterator):
return chain.from_iterable(map(fail_on_stopiteration(f), iterator))
return self.mapPartitionsWithIndex(func, preservesPartitioning) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'distinct'},{'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': 'numPartitions'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'return_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '36']},{'id': '11', 'type': 'attribute', 'children': ['12', '34', '35']},{'id': '12', 'type': 'call', 'children': ['13', '27']},{'id': '13', 'type': 'attribute', 'children': ['14', '25', '26']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'lambda', 'children': ['20', '22']},{'id': '20', 'type': 'lambda_parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'tuple', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'reduceByKey'},{'id': '27', 'type': 'argument_list', 'children': ['28', '33']},{'id': '28', 'type': 'lambda', 'children': ['29', '32']},{'id': '29', 'type': 'lambda_parameters', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '34', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'lambda', 'children': ['38', '40']},{'id': '38', 'type': 'lambda_parameters', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'} | def distinct(self, numPartitions=None):
return self.map(lambda x: (x, None)) \
.reduceByKey(lambda x, _: x, numPartitions) \
.map(lambda x: x[0]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'repartitionAndSortWithinPartitions'},{'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': 'numPartitions'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'portable_hash'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keyfunc'},{'id': '16', 'type': 'lambda', 'children': ['17', '19']},{'id': '17', 'type': 'lambda_parameters', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'block', 'children': ['21', '34', '51', '57', '98']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'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': '_defaultReducePartitions'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_parse_memory'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '48']},{'id': '41', 'type': 'attribute', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_conf'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': '"spark.python.worker.memory"'},{'id': '50', 'type': 'string', 'children': [], 'value': '"512m"'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_jrdd_deserializer'},{'id': '57', 'type': 'function_definition', 'children': ['58', '59', '61']},{'id': '58', 'type': 'function_name', 'children': [], 'value': 'sortPartition'},{'id': '59', 'type': 'parameters', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '61', 'type': 'block', 'children': ['62', '74']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '65', 'type': 'attribute', 'children': ['66', '73']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ExternalSorter'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '*'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '71', 'type': 'float', 'children': [], 'value': '0.9'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '93']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '84', 'type': 'lambda', 'children': ['85', '87']},{'id': '85', 'type': 'lambda_parameters', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'k_v'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'keyfunc'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'k_v'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '95', 'type': '()', 'children': ['96']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '109']},{'id': '100', 'type': 'attribute', 'children': ['101', '108']},{'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': 'partitionBy'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'mapPartitions'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sortPartition'},{'id': '111', 'type': 'True', 'children': []} | def repartitionAndSortWithinPartitions(self, numPartitions=None, partitionFunc=portable_hash,
ascending=True, keyfunc=lambda x: x):
if numPartitions is None:
numPartitions = self._defaultReducePartitions()
memory = _parse_memory(self.ctx._conf.get("spark.python.worker.memory", "512m"))
serializer = self._jrdd_deserializer
def sortPartition(iterator):
sort = ExternalSorter(memory * 0.9, serializer).sorted
return iter(sort(iterator, key=lambda k_v: keyfunc(k_v[0]), reverse=(not ascending)))
return self.partitionBy(numPartitions, partitionFunc).mapPartitions(sortPartition, True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortBy'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'keyfunc'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '29']},{'id': '15', 'type': 'attribute', 'children': ['16', '28']},{'id': '16', 'type': 'call', 'children': ['17', '25']},{'id': '17', 'type': 'attribute', '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': 'keyBy'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'keyfunc'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortByKey'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '29', 'type': 'argument_list', 'children': []} | def sortBy(self, keyfunc, ascending=True, numPartitions=None):
return self.keyBy(keyfunc).sortByKey(ascending, numPartitions).values() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'groupBy'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'portable_hash'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '31']},{'id': '15', 'type': 'attribute', 'children': ['16', '30']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'lambda', 'children': ['22', '24']},{'id': '22', 'type': 'lambda_parameters', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'tuple', 'children': ['25', '29']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'groupByKey'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'} | def groupBy(self, f, numPartitions=None, partitionFunc=portable_hash):
return self.map(lambda x: (f(x), x)).groupByKey(numPartitions, partitionFunc) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'top'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '27', '46']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'topIterator'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'yield', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nlargest'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'function_definition', 'children': ['28', '29', '32']},{'id': '28', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '29', 'type': 'parameters', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'nlargest'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40', '43']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '56']},{'id': '48', 'type': 'attribute', 'children': ['49', '55']},{'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': 'mapPartitions'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'topIterator'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'merge'} | def top(self, num, key=None):
def topIterator(iterator):
yield heapq.nlargest(num, iterator, key=key)
def merge(a, b):
return heapq.nlargest(num, a + b, key=key)
return self.mapPartitions(topIterator).reduce(merge) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'saveAsTextFile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'compressionCodecClass'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '56', '65', '71']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'func'},{'id': '12', 'type': 'parameters', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '19', 'type': 'block', 'children': ['20', '37', '53']},{'id': '20', 'type': 'if_statement', 'children': ['21', '29']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'if_statement', 'children': ['38', '43']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'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': 'x'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'yield', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'keyed'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mapPartitionsWithIndex'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'keyed'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_bypass_serializer'},{'id': '70', 'type': 'True', 'children': []},{'id': '71', 'type': 'if_statement', 'children': ['72', '73', '116']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'compressionCodecClass'},{'id': '73', 'type': 'block', 'children': ['74', '93']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'compressionCodec'},{'id': '77', 'type': 'call', 'children': ['78', '91']},{'id': '78', 'type': 'attribute', 'children': ['79', '90']},{'id': '79', 'type': 'attribute', 'children': ['80', '89']},{'id': '80', 'type': 'attribute', 'children': ['81', '88']},{'id': '81', 'type': 'attribute', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_jvm'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'java'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'Class'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'forName'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'compressionCodecClass'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '113']},{'id': '95', 'type': 'attribute', 'children': ['96', '112']},{'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': 'keyed'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_jrdd'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '111']},{'id': '104', 'type': 'attribute', 'children': ['105', '110']},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_jvm'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'BytesToString'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'saveAsTextFile'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'compressionCodec'},{'id': '116', 'type': 'else_clause', 'children': ['117']},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '138']},{'id': '120', 'type': 'attribute', 'children': ['121', '137']},{'id': '121', 'type': 'call', 'children': ['122', '127']},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'keyed'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_jrdd'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '136']},{'id': '129', 'type': 'attribute', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_jvm'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'BytesToString'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'saveAsTextFile'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'path'} | def saveAsTextFile(self, path, compressionCodecClass=None):
def func(split, iterator):
for x in iterator:
if not isinstance(x, (unicode, bytes)):
x = unicode(x)
if isinstance(x, unicode):
x = x.encode("utf-8")
yield x
keyed = self.mapPartitionsWithIndex(func)
keyed._bypass_serializer = True
if compressionCodecClass:
compressionCodec = self.ctx._jvm.java.lang.Class.forName(compressionCodecClass)
keyed._jrdd.map(self.ctx._jvm.BytesToString()).saveAsTextFile(path, compressionCodec)
else:
keyed._jrdd.map(self.ctx._jvm.BytesToString()).saveAsTextFile(path) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reduceByKey'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'portable_hash'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'combineByKey'},{'id': '18', 'type': 'argument_list', 'children': ['19', '23', '24', '25', '26']},{'id': '19', 'type': 'lambda', 'children': ['20', '22']},{'id': '20', 'type': 'lambda_parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'} | def reduceByKey(self, func, numPartitions=None, partitionFunc=portable_hash):
return self.combineByKey(lambda x: x, func, func, numPartitions, partitionFunc) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reduceByKeyLocally'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '6', 'type': 'block', 'children': ['7', '14', '49', '84']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'fail_on_stopiteration'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']},{'id': '15', 'type': 'function_name', 'children': [], 'value': 'reducePartition'},{'id': '16', 'type': 'parameters', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '18', 'type': 'block', 'children': ['19', '23', '46']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '22', 'type': 'dictionary', 'children': []},{'id': '23', 'type': 'for_statement', 'children': ['24', '27', '28']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '34', 'type': 'conditional_expression', 'children': ['35', '42', '45'], 'value': 'if'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '37', 'type': 'argument_list', 'children': ['38', '41']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'yield', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '49', 'type': 'function_definition', 'children': ['50', '51', '54']},{'id': '50', 'type': 'function_name', 'children': [], 'value': 'mergeMaps'},{'id': '51', 'type': 'parameters', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'm1'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'm2'},{'id': '54', 'type': 'block', 'children': ['55', '82']},{'id': '55', 'type': 'for_statement', 'children': ['56', '59', '64']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'm2'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'm1'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '70', 'type': 'conditional_expression', 'children': ['71', '78', '81'], 'value': 'if'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '73', 'type': 'argument_list', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'm1'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'm1'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'm1'},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '94']},{'id': '86', 'type': 'attribute', 'children': ['87', '93']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'mapPartitions'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'reducePartition'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'mergeMaps'} | def reduceByKeyLocally(self, func):
func = fail_on_stopiteration(func)
def reducePartition(iterator):
m = {}
for k, v in iterator:
m[k] = func(m[k], v) if k in m else v
yield m
def mergeMaps(m1, m2):
for k, v in m2.items():
m1[k] = func(m1[k], v) if k in m1 else v
return m1
return self.mapPartitions(reducePartition).reduce(mergeMaps) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'combineByKey'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'createCombiner'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mergeValue'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'mergeCombiners'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'portable_hash'},{'id': '14', 'type': 'block', 'children': ['15', '28', '36', '44', '53', '82', '94', '104', '131']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_defaultReducePartitions'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_memory_limit'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'agg'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'Aggregator'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'createCombiner'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'mergeValue'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'mergeCombiners'},{'id': '53', 'type': 'function_definition', 'children': ['54', '55', '57']},{'id': '54', 'type': 'function_name', 'children': [], 'value': 'combineLocally'},{'id': '55', 'type': 'parameters', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '57', 'type': 'block', 'children': ['58', '69', '76']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ExternalMerger'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '68']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'agg'},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '*'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '67', 'type': 'float', 'children': [], 'value': '0.9'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'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': 'merger'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'mergeValues'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'locally_combined'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mapPartitions'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'combineLocally'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'preservesPartitioning'},{'id': '93', 'type': 'True', 'children': []},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'locally_combined'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'partitionBy'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '104', 'type': 'function_definition', 'children': ['105', '106', '108']},{'id': '105', 'type': 'function_name', 'children': [], 'value': '_mergeCombiners'},{'id': '106', 'type': 'parameters', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '108', 'type': 'block', 'children': ['109', '118', '125']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ExternalMerger'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116', '117']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'agg'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'mergeCombiners'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'mapPartitions'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_mergeCombiners'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'preservesPartitioning'},{'id': '140', 'type': 'True', 'children': []} | def combineByKey(self, createCombiner, mergeValue, mergeCombiners,
numPartitions=None, partitionFunc=portable_hash):
if numPartitions is None:
numPartitions = self._defaultReducePartitions()
serializer = self.ctx.serializer
memory = self._memory_limit()
agg = Aggregator(createCombiner, mergeValue, mergeCombiners)
def combineLocally(iterator):
merger = ExternalMerger(agg, memory * 0.9, serializer)
merger.mergeValues(iterator)
return merger.items()
locally_combined = self.mapPartitions(combineLocally, preservesPartitioning=True)
shuffled = locally_combined.partitionBy(numPartitions, partitionFunc)
def _mergeCombiners(iterator):
merger = ExternalMerger(agg, memory, serializer)
merger.mergeCombiners(iterator)
return merger.items()
return shuffled.mapPartitions(_mergeCombiners, preservesPartitioning=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'groupByKey'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'portable_hash'},{'id': '11', 'type': 'block', 'children': ['12', '20', '35', '50', '58', '64', '73', '102', '114', '124', '151']},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']},{'id': '13', 'type': 'function_name', 'children': [], 'value': 'createCombiner'},{'id': '14', 'type': 'parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'list', 'children': ['19'], 'value': '[x]'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'function_definition', 'children': ['21', '22', '25']},{'id': '21', 'type': 'function_name', 'children': [], 'value': 'mergeValue'},{'id': '22', 'type': 'parameters', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'block', 'children': ['26', '33']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '35', 'type': 'function_definition', 'children': ['36', '37', '40']},{'id': '36', 'type': 'function_name', 'children': [], 'value': 'mergeCombiners'},{'id': '37', 'type': 'parameters', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '40', 'type': 'block', 'children': ['41', '48']},{'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': 'a'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'memory'},{'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': '_memory_limit'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_jrdd_deserializer'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'agg'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'Aggregator'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'createCombiner'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'mergeValue'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'mergeCombiners'},{'id': '73', 'type': 'function_definition', 'children': ['74', '75', '77']},{'id': '74', 'type': 'function_name', 'children': [], 'value': 'combine'},{'id': '75', 'type': 'parameters', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '77', 'type': 'block', 'children': ['78', '89', '96']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ExternalMerger'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '88']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'agg'},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '*'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '87', 'type': 'float', 'children': [], 'value': '0.9'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'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': 'merger'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'mergeValues'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'locally_combined'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'mapPartitions'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'combine'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'preservesPartitioning'},{'id': '113', 'type': 'True', 'children': []},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'locally_combined'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'partitionBy'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'numPartitions'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'partitionFunc'},{'id': '124', 'type': 'function_definition', 'children': ['125', '126', '128']},{'id': '125', 'type': 'function_name', 'children': [], 'value': 'groupByKey'},{'id': '126', 'type': 'parameters', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '128', 'type': 'block', 'children': ['129', '138', '145']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ExternalGroupBy'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'agg'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mergeCombiners'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'merger'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'return_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '162']},{'id': '153', 'type': 'attribute', 'children': ['154', '161']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mapPartitions'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'groupByKey'},{'id': '160', 'type': 'True', 'children': []},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'mapValues'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'ResultIterable'} | def groupByKey(self, numPartitions=None, partitionFunc=portable_hash):
def createCombiner(x):
return [x]
def mergeValue(xs, x):
xs.append(x)
return xs
def mergeCombiners(a, b):
a.extend(b)
return a
memory = self._memory_limit()
serializer = self._jrdd_deserializer
agg = Aggregator(createCombiner, mergeValue, mergeCombiners)
def combine(iterator):
merger = ExternalMerger(agg, memory * 0.9, serializer)
merger.mergeValues(iterator)
return merger.items()
locally_combined = self.mapPartitions(combine, preservesPartitioning=True)
shuffled = locally_combined.partitionBy(numPartitions, partitionFunc)
def groupByKey(it):
merger = ExternalGroupBy(agg, memory, serializer)
merger.mergeCombiners(it)
return merger.items()
return shuffled.mapPartitions(groupByKey, True).mapValues(ResultIterable) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lookup'},{'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', '27', '54']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '10', 'type': 'call', 'children': ['11', '26']},{'id': '11', 'type': 'attribute', 'children': ['12', '25']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'lambda', 'children': ['18', '20']},{'id': '18', 'type': 'lambda_parameters', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '=='},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'if_statement', 'children': ['28', '33']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': 'is'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'partitioner'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_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': 'ctx'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'runJob'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '47']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '43', 'type': 'lambda', 'children': ['44', '46']},{'id': '44', 'type': 'lambda_parameters', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'list', 'children': ['48'], 'value': '[self.partitioner(key)]'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'partitioner'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'collect'},{'id': '59', 'type': 'argument_list', 'children': []} | def lookup(self, key):
values = self.filter(lambda kv: kv[0] == key).values()
if self.partitioner is not None:
return self.ctx.runJob(values, lambda x: x, [self.partitioner(key)])
return values.collect() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'describeTopics'},{'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': 'maxTermsPerTopic'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '35']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13', '23']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'maxTermsPerTopic'},{'id': '12', 'type': 'None', 'children': []},{'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': 'topics'},{'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': 'call'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': '"describeTopics"'},{'id': '23', 'type': 'else_clause', 'children': ['24']},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'topics'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': '"describeTopics"'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'maxTermsPerTopic'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'topics'} | def describeTopics(self, maxTermsPerTopic=None):
if maxTermsPerTopic is None:
topics = self.call("describeTopics")
else:
topics = self.call("describeTopics", maxTermsPerTopic)
return topics |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_cols'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '17', '39', '50', '60', '125']},{'id': '8', 'type': 'if_statement', 'children': ['9', '11']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'raise_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"should sort by at least one column"'},{'id': '17', 'type': 'if_statement', 'children': ['18', '32']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '25'], 'value': 'and'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '24'], 'value': '=='},{'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': 'cols'},{'id': '24', 'type': 'integer', 'children': [], 'value': '1'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'cols'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'jcols'},{'id': '42', 'type': 'list_comprehension', 'children': ['43', '47']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_to_java_column'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'ascending'"},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'if_statement', 'children': ['61', '68', '85', '113']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '65', 'type': 'tuple', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '72']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'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': 'jcols'},{'id': '76', 'type': 'list_comprehension', 'children': ['77', '82']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'jc'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'jc'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'jcols'},{'id': '85', 'type': 'elif_clause', 'children': ['86', '91']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'jcols'},{'id': '95', 'type': 'list_comprehension', 'children': ['96', '104']},{'id': '96', 'type': 'conditional_expression', 'children': ['97', '98', '99'], 'value': 'if'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'jc'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'jc'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'for_in_clause', 'children': ['105', '108']},{'id': '105', 'type': 'pattern_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'jc'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'jcols'},{'id': '113', 'type': 'else_clause', 'children': ['114']},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'raise_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'},{'id': '120', 'type': 'string', 'children': [], 'value': '"ascending can only be boolean or list, but got %s"'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_jseq'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'jcols'} | def _sort_cols(self, cols, kwargs):
if not cols:
raise ValueError("should sort by at least one column")
if len(cols) == 1 and isinstance(cols[0], list):
cols = cols[0]
jcols = [_to_java_column(c) for c in cols]
ascending = kwargs.get('ascending', True)
if isinstance(ascending, (bool, int)):
if not ascending:
jcols = [jc.desc() for jc in jcols]
elif isinstance(ascending, list):
jcols = [jc if asc else jc.desc()
for asc, jc in zip(ascending, jcols)]
else:
raise TypeError("ascending can only be boolean or list, but got %s" % type(ascending))
return self._jseq(jcols) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_list_function_infos'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'jvm'},{'id': '5', 'type': 'block', 'children': ['6', '28', '32', '136']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'jinfos'},{'id': '9', 'type': 'call', 'children': ['10', '27']},{'id': '10', 'type': 'attribute', 'children': ['11', '26']},{'id': '11', 'type': 'attribute', 'children': ['12', '25']},{'id': '12', 'type': 'attribute', 'children': ['13', '24']},{'id': '13', 'type': 'attribute', 'children': ['14', '23']},{'id': '14', 'type': 'attribute', 'children': ['15', '22']},{'id': '15', 'type': 'attribute', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'jvm'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'apache'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'spark'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'python'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'PythonSQLUtils'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'listBuiltinFunctionInfos'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'infos'},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'jinfos'},{'id': '35', 'type': 'block', 'children': ['36', '44', '52', '67']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'getName'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'getUsage'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '55', 'type': 'conditional_expression', 'children': ['56', '63', '66'], 'value': 'if'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': '"_FUNC_"'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'infos'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ExpressionInfo'},{'id': '75', 'type': 'argument_list', 'children': ['76', '83', '86', '89', '102', '115', '122', '129']},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'className'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'getClassName'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '91', 'type': 'call', 'children': ['92', '99']},{'id': '92', 'type': 'attribute', 'children': ['93', '98']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'getArguments'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': '"_FUNC_"'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'examples'},{'id': '104', 'type': 'call', 'children': ['105', '112']},{'id': '105', 'type': 'attribute', 'children': ['106', '111']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'getExamples'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': '"_FUNC_"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'note'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'getNote'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'getSince'},{'id': '128', 'type': 'argument_list', 'children': []},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'deprecated'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'jinfo'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'getDeprecated'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'infos'},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '143', 'type': 'lambda', 'children': ['144', '146']},{'id': '144', 'type': 'lambda_parameters', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'} | def _list_function_infos(jvm):
jinfos = jvm.org.apache.spark.sql.api.python.PythonSQLUtils.listBuiltinFunctionInfos()
infos = []
for jinfo in jinfos:
name = jinfo.getName()
usage = jinfo.getUsage()
usage = usage.replace("_FUNC_", name) if usage is not None else usage
infos.append(ExpressionInfo(
className=jinfo.getClassName(),
name=name,
usage=usage,
arguments=jinfo.getArguments().replace("_FUNC_", name),
examples=jinfo.getExamples().replace("_FUNC_", name),
note=jinfo.getNote(),
since=jinfo.getSince(),
deprecated=jinfo.getDeprecated()))
return sorted(infos, key=lambda i: i.name) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '14', '18', '24', '62', '177', '217', '222', '286']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': "'''Merge multiple sorted inputs into a single sorted output.\n Similar to sorted(itertools.chain(*iterables)) but returns a generator,\n does not pull the data into memory all at once, and assumes that each of\n the input streams is already sorted (smallest to largest).\n >>> list(merge([1,3,5,7], [0,2,4,8], [5,10,15,20], [], [25]))\n [0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25]\n If *key* is not None, applies a key function to each element to determine\n its sort order.\n >>> list(merge(['dog', 'horse'], ['cat', 'fish', 'kangaroo'], key=len))\n ['dog', 'cat', 'fish', 'horse', 'kangaroo']\n '''"},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'h_append'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '24', 'type': 'if_statement', 'children': ['25', '26', '44']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '26', 'type': 'block', 'children': ['27', '31', '35', '39']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_heapify'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_heapify_max'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_heappop'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_heappop_max'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_heapreplace_max'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'else_clause', 'children': ['45']},{'id': '45', 'type': 'block', 'children': ['46', '50', '54', '58']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_heapify'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'heapify'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_heappop'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'heappop'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'heapreplace'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'if_statement', 'children': ['63', '66']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'block', 'children': ['67', '99', '104', '154', '176']},{'id': '67', 'type': 'for_statement', 'children': ['68', '71', '79']},{'id': '68', 'type': 'pattern_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'try_statement', 'children': ['81', '95']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'h_append'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'list', 'children': ['87', '91', '94'], 'value': '[next(it), order * direction, it]'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '*'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '95', 'type': 'except_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'pass_statement', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_heapify'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '104', 'type': 'while_statement', 'children': ['105', '111']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '110'], 'value': '>'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'try_statement', 'children': ['113', '146']},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'while_statement', 'children': ['115', '116']},{'id': '115', 'type': 'True', 'children': []},{'id': '116', 'type': 'block', 'children': ['117', '128', '131', '140']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '123']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'yield', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '136']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '135', 'type': 'integer', 'children': [], 'value': '0'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '146', 'type': 'except_clause', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_heappop'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '154', 'type': 'if_statement', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '156', 'type': 'block', 'children': ['157', '166', '169']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '163']},{'id': '159', 'type': 'pattern_list', 'children': ['160', '161', '162']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'yield', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'yield', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '176', 'type': 'return_statement', 'children': []},{'id': '177', 'type': 'for_statement', 'children': ['178', '181', '189']},{'id': '178', 'type': 'pattern_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'try_statement', 'children': ['191', '213']},{'id': '191', 'type': 'block', 'children': ['192', '199']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'h_append'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'list', 'children': ['204', '208', '211', '212'], 'value': '[key(value), order * direction, value, it]'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '*'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '213', 'type': 'except_clause', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'pass_statement', 'children': []},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': '_heapify'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '222', 'type': 'while_statement', 'children': ['223', '229']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '228'], 'value': '>'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '228', 'type': 'integer', 'children': [], 'value': '1'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'try_statement', 'children': ['231', '278']},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'while_statement', 'children': ['233', '234']},{'id': '233', 'type': 'True', 'children': []},{'id': '234', 'type': 'block', 'children': ['235', '247', '250', '257', '266', '272']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '242']},{'id': '237', 'type': 'pattern_list', 'children': ['238', '239', '240', '241']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'key_value'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '246', 'type': 'integer', 'children': [], 'value': '0'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'yield', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '262']},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '261', 'type': 'integer', 'children': [], 'value': '0'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '271']},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '270', 'type': 'integer', 'children': [], 'value': '2'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '278', 'type': 'except_clause', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': '_heappop'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '286', 'type': 'if_statement', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '288', 'type': 'block', 'children': ['289', '299', '302']},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '296']},{'id': '291', 'type': 'pattern_list', 'children': ['292', '293', '294', '295']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'key_value'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '298', 'type': 'integer', 'children': [], 'value': '0'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'yield', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '302', 'type': 'for_statement', 'children': ['303', '304', '305']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'yield', 'children': ['308']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'value'} | def merge(iterables, key=None, reverse=False):
'''Merge multiple sorted inputs into a single sorted output.
Similar to sorted(itertools.chain(*iterables)) but returns a generator,
does not pull the data into memory all at once, and assumes that each of
the input streams is already sorted (smallest to largest).
>>> list(merge([1,3,5,7], [0,2,4,8], [5,10,15,20], [], [25]))
[0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25]
If *key* is not None, applies a key function to each element to determine
its sort order.
>>> list(merge(['dog', 'horse'], ['cat', 'fish', 'kangaroo'], key=len))
['dog', 'cat', 'fish', 'horse', 'kangaroo']
'''
h = []
h_append = h.append
if reverse:
_heapify = _heapify_max
_heappop = _heappop_max
_heapreplace = _heapreplace_max
direction = -1
else:
_heapify = heapify
_heappop = heappop
_heapreplace = heapreplace
direction = 1
if key is None:
for order, it in enumerate(map(iter, iterables)):
try:
h_append([next(it), order * direction, it])
except StopIteration:
pass
_heapify(h)
while len(h) > 1:
try:
while True:
value, order, it = s = h[0]
yield value
s[0] = next(it)
_heapreplace(h, s)
except StopIteration:
_heappop(h)
if h:
value, order, it = h[0]
yield value
for value in it:
yield value
return
for order, it in enumerate(map(iter, iterables)):
try:
value = next(it)
h_append([key(value), order * direction, value, it])
except StopIteration:
pass
_heapify(h)
while len(h) > 1:
try:
while True:
key_value, order, value, it = s = h[0]
yield value
value = next(it)
s[0] = key(value)
s[2] = value
_heapreplace(h, s)
except StopIteration:
_heappop(h)
if h:
key_value, order, value, it = h[0]
yield value
for value in it:
yield value |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nsmallest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '66', '100', '201', '208', '231', '237', '242', '250', '254', '258', '295', '301']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '=='},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'block', 'children': ['15', '22', '28', '58']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '32', '43']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'None', 'children': []},{'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': 'result'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '43', 'type': 'else_clause', 'children': ['44']},{'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': 'result'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'conditional_expression', 'children': ['60', '61', '64'], 'value': 'if'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '64', 'type': 'list', 'children': ['65'], 'value': '[result]'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '66', 'type': 'try_statement', 'children': ['67', '75', '81']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '75', 'type': 'except_clause', 'children': ['76', '79']},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'pass_statement', 'children': []},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '>='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'subscript', 'children': ['90', '97']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '97', 'type': 'slice', 'children': ['98', '99']},{'id': '98', 'type': 'colon', 'children': []},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '100', 'type': 'if_statement', 'children': ['101', '104']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'block', 'children': ['105', '112', '131', '137', '142', '150', '154', '158', '187', '193']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '115', 'type': 'list_comprehension', 'children': ['116', '119']},{'id': '116', 'type': 'tuple', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '119', 'type': 'for_in_clause', 'children': ['120', '123']},{'id': '120', 'type': 'pattern_list', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '125', 'type': 'argument_list', 'children': ['126', '130']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '131', 'type': 'if_statement', 'children': ['132', '134']},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': '_heapify_max'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '145', 'type': 'subscript', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'integer', 'children': [], 'value': '0'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_heapreplace_max'},{'id': '158', 'type': 'for_statement', 'children': ['159', '160', '161']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'if_statement', 'children': ['163', '166']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '<'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '166', 'type': 'block', 'children': ['167', '175', '183']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '172', 'type': 'tuple', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '178', 'type': 'subscript', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'augmented_assignment', 'children': ['185', '186'], 'value': '+='},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'return_statement', 'children': ['194']},{'id': '194', 'type': 'list_comprehension', 'children': ['195', '198']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '197', 'type': 'integer', 'children': [], 'value': '0'},{'id': '198', 'type': 'for_in_clause', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '211', 'type': 'list_comprehension', 'children': ['212', '219']},{'id': '212', 'type': 'tuple', 'children': ['213', '217', '218']},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '219', 'type': 'for_in_clause', 'children': ['220', '223']},{'id': '220', 'type': 'pattern_list', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '225', 'type': 'argument_list', 'children': ['226', '230']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '231', 'type': 'if_statement', 'children': ['232', '234']},{'id': '232', 'type': 'not_operator', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'return_statement', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': '_heapify_max'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '245', 'type': 'subscript', 'children': ['246', '249']},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '248', 'type': 'integer', 'children': [], 'value': '0'},{'id': '249', 'type': 'integer', 'children': [], 'value': '0'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '257', 'type': 'identifier', 'children': [], 'value': '_heapreplace_max'},{'id': '258', 'type': 'for_statement', 'children': ['259', '260', '261']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '261', 'type': 'block', 'children': ['262', '269']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '269', 'type': 'if_statement', 'children': ['270', '273']},{'id': '270', 'type': 'comparison_operator', 'children': ['271', '272'], 'value': '<'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '273', 'type': 'block', 'children': ['274', '283', '291']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '279', 'type': 'tuple', 'children': ['280', '281', '282']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '286', 'type': 'subscript', 'children': ['287', '290']},{'id': '287', 'type': 'subscript', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '289', 'type': 'integer', 'children': [], 'value': '0'},{'id': '290', 'type': 'integer', 'children': [], 'value': '0'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'augmented_assignment', 'children': ['293', '294'], 'value': '+='},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '294', 'type': 'integer', 'children': [], 'value': '1'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '300', 'type': 'argument_list', 'children': []},{'id': '301', 'type': 'return_statement', 'children': ['302']},{'id': '302', 'type': 'list_comprehension', 'children': ['303', '306']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '305', 'type': 'integer', 'children': [], 'value': '2'},{'id': '306', 'type': 'for_in_clause', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'result'} | def nsmallest(n, iterable, key=None):
if n == 1:
it = iter(iterable)
sentinel = object()
if key is None:
result = min(it, default=sentinel)
else:
result = min(it, default=sentinel, key=key)
return [] if result is sentinel else [result]
try:
size = len(iterable)
except (TypeError, AttributeError):
pass
else:
if n >= size:
return sorted(iterable, key=key)[:n]
if key is None:
it = iter(iterable)
result = [(elem, i) for i, elem in zip(range(n), it)]
if not result:
return result
_heapify_max(result)
top = result[0][0]
order = n
_heapreplace = _heapreplace_max
for elem in it:
if elem < top:
_heapreplace(result, (elem, order))
top = result[0][0]
order += 1
result.sort()
return [r[0] for r in result]
it = iter(iterable)
result = [(key(elem), i, elem) for i, elem in zip(range(n), it)]
if not result:
return result
_heapify_max(result)
top = result[0][0]
order = n
_heapreplace = _heapreplace_max
for elem in it:
k = key(elem)
if k < top:
_heapreplace(result, (k, order, elem))
top = result[0][0]
order += 1
result.sort()
return [r[2] for r in result] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nlargest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '66', '103', '212', '219', '246', '252', '257', '265', '270', '274', '311', '320']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '=='},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'block', 'children': ['15', '22', '28', '58']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '32', '43']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'None', 'children': []},{'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': 'result'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '43', 'type': 'else_clause', 'children': ['44']},{'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': 'result'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'conditional_expression', 'children': ['60', '61', '64'], 'value': 'if'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '64', 'type': 'list', 'children': ['65'], 'value': '[result]'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '66', 'type': 'try_statement', 'children': ['67', '75', '81']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '75', 'type': 'except_clause', 'children': ['76', '79']},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'pass_statement', 'children': []},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '>='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'subscript', 'children': ['90', '100']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94', '97']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '99', 'type': 'True', 'children': []},{'id': '100', 'type': 'slice', 'children': ['101', '102']},{'id': '101', 'type': 'colon', 'children': []},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '106', 'type': 'None', 'children': []},{'id': '107', 'type': 'block', 'children': ['108', '115', '138', '144', '149', '157', '162', '166', '195', '204']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '118', 'type': 'list_comprehension', 'children': ['119', '122']},{'id': '119', 'type': 'tuple', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'for_in_clause', 'children': ['123', '126']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '128', 'type': 'argument_list', 'children': ['129', '137']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '135']},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'unary_operator', 'children': ['134'], 'value': '-'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '135', 'type': 'unary_operator', 'children': ['136'], 'value': '-'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '138', 'type': 'if_statement', 'children': ['139', '141']},{'id': '139', 'type': 'not_operator', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'heapify'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '152', 'type': 'subscript', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'integer', 'children': [], 'value': '0'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '160', 'type': 'unary_operator', 'children': ['161'], 'value': '-'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'heapreplace'},{'id': '166', 'type': 'for_statement', 'children': ['167', '168', '169']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'if_statement', 'children': ['171', '174']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': '<'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '174', 'type': 'block', 'children': ['175', '183', '191']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '180', 'type': 'tuple', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '186', 'type': 'subscript', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'augmented_assignment', 'children': ['193', '194'], 'value': '-='},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '194', 'type': 'integer', 'children': [], 'value': '1'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '203', 'type': 'True', 'children': []},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'list_comprehension', 'children': ['206', '209']},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '208', 'type': 'integer', 'children': [], 'value': '0'},{'id': '209', 'type': 'for_in_clause', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '222', 'type': 'list_comprehension', 'children': ['223', '230']},{'id': '223', 'type': 'tuple', 'children': ['224', '228', '229']},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '230', 'type': 'for_in_clause', 'children': ['231', '234']},{'id': '231', 'type': 'pattern_list', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '236', 'type': 'argument_list', 'children': ['237', '245']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241', '243']},{'id': '240', 'type': 'integer', 'children': [], 'value': '0'},{'id': '241', 'type': 'unary_operator', 'children': ['242'], 'value': '-'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '243', 'type': 'unary_operator', 'children': ['244'], 'value': '-'},{'id': '244', 'type': 'integer', 'children': [], 'value': '1'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '246', 'type': 'if_statement', 'children': ['247', '249']},{'id': '247', 'type': 'not_operator', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'return_statement', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'heapify'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '260', 'type': 'subscript', 'children': ['261', '264']},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '263', 'type': 'integer', 'children': [], 'value': '0'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '268', 'type': 'unary_operator', 'children': ['269'], 'value': '-'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'heapreplace'},{'id': '274', 'type': 'for_statement', 'children': ['275', '276', '277']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '277', 'type': 'block', 'children': ['278', '285']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '285', 'type': 'if_statement', 'children': ['286', '289']},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '288'], 'value': '<'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '289', 'type': 'block', 'children': ['290', '299', '307']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': '_heapreplace'},{'id': '293', 'type': 'argument_list', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '295', 'type': 'tuple', 'children': ['296', '297', '298']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '302', 'type': 'subscript', 'children': ['303', '306']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '305', 'type': 'integer', 'children': [], 'value': '0'},{'id': '306', 'type': 'integer', 'children': [], 'value': '0'},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'augmented_assignment', 'children': ['309', '310'], 'value': '-='},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '310', 'type': 'integer', 'children': [], 'value': '1'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'keyword_argument', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '319', 'type': 'True', 'children': []},{'id': '320', 'type': 'return_statement', 'children': ['321']},{'id': '321', 'type': 'list_comprehension', 'children': ['322', '325']},{'id': '322', 'type': 'subscript', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '324', 'type': 'integer', 'children': [], 'value': '2'},{'id': '325', 'type': 'for_in_clause', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'result'} | def nlargest(n, iterable, key=None):
if n == 1:
it = iter(iterable)
sentinel = object()
if key is None:
result = max(it, default=sentinel)
else:
result = max(it, default=sentinel, key=key)
return [] if result is sentinel else [result]
try:
size = len(iterable)
except (TypeError, AttributeError):
pass
else:
if n >= size:
return sorted(iterable, key=key, reverse=True)[:n]
if key is None:
it = iter(iterable)
result = [(elem, i) for i, elem in zip(range(0, -n, -1), it)]
if not result:
return result
heapify(result)
top = result[0][0]
order = -n
_heapreplace = heapreplace
for elem in it:
if top < elem:
_heapreplace(result, (elem, order))
top = result[0][0]
order -= 1
result.sort(reverse=True)
return [r[0] for r in result]
it = iter(iterable)
result = [(key(elem), i, elem) for i, elem in zip(range(0, -n, -1), it)]
if not result:
return result
heapify(result)
top = result[0][0]
order = -n
_heapreplace = heapreplace
for elem in it:
k = key(elem)
if top < k:
_heapreplace(result, (k, order, elem))
top = result[0][0]
order -= 1
result.sort(reverse=True)
return [r[2] for r in result] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortBy'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '8', 'type': 'block', 'children': ['9', '48', '75', '97']},{'id': '9', 'type': 'if_statement', 'children': ['10', '17']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '14', 'type': 'tuple', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '17', 'type': 'block', 'children': ['18', '34']},{'id': '18', 'type': 'if_statement', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"col is a {0} but cols are not empty"'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '39', 'type': 'expression_list', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '45', 'type': 'slice', 'children': ['46', '47']},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'colon', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '69']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '62'], 'value': 'or'},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '53', 'type': 'generator_expression', 'children': ['54', '59']},{'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': 'c'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': '()', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'raise_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': '"all names should be `str`"'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_jwrite'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_jwrite'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sortBy'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_to_seq'},{'id': '90', 'type': 'argument_list', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_spark'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_sc'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'} | def sortBy(self, col, *cols):
if isinstance(col, (list, tuple)):
if cols:
raise ValueError("col is a {0} but cols are not empty".format(type(col)))
col, cols = col[0], col[1:]
if not all(isinstance(c, basestring) for c in cols) or not(isinstance(col, basestring)):
raise TypeError("all names should be `str`")
self._jwrite = self._jwrite.sortBy(col, _to_seq(self._spark._sc, cols))
return self |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'saveAsLibSVMFile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dir'},{'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': 'lines'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'lambda', 'children': ['16', '18']},{'id': '16', 'type': 'lambda_parameters', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'MLUtils'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_convert_labeled_point_to_libsvm'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'saveAsTextFile'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dir'} | def saveAsLibSVMFile(data, dir):
lines = data.map(lambda p: MLUtils._convert_labeled_point_to_libsvm(p))
lines.saveAsTextFile(dir) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'union'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '6', 'type': 'block', 'children': ['7', '15', '40', '58', '73', '94']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'first_jrdd_deserializer'},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_jrdd_deserializer'},{'id': '15', 'type': 'if_statement', 'children': ['16', '27']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '18', 'type': 'generator_expression', 'children': ['19', '24']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '!='},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_jrdd_deserializer'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'first_jrdd_deserializer'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '31', 'type': 'list_comprehension', 'children': ['32', '37']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_reserialize'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '43', 'type': 'attribute', 'children': ['44', '57']},{'id': '44', 'type': 'attribute', 'children': ['45', '56']},{'id': '45', 'type': 'attribute', 'children': ['46', '55']},{'id': '46', 'type': 'attribute', 'children': ['47', '54']},{'id': '47', 'type': 'attribute', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'SparkContext'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_jvm'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'apache'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'spark'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'java'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'JavaRDD'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'jrdds'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'SparkContext'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_gateway'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'new_array'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '83']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'jrdds'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_jrdd'},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'RDD'},{'id': '97', 'type': 'argument_list', 'children': ['98', '106', '107']},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_jsc'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'jrdds'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'attribute', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'rdds'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_jrdd_deserializer'} | def union(self, rdds):
first_jrdd_deserializer = rdds[0]._jrdd_deserializer
if any(x._jrdd_deserializer != first_jrdd_deserializer for x in rdds):
rdds = [x._reserialize() for x in rdds]
cls = SparkContext._jvm.org.apache.spark.api.java.JavaRDD
jrdds = SparkContext._gateway.new_array(cls, len(rdds))
for i in range(0, len(rdds)):
jrdds[i] = rdds[i]._jrdd
return RDD(self._jsc.union(jrdds), self, rdds[0]._jrdd_deserializer) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortlevel'},{'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': 'level'},{'id': '7', 'type': 'None', 'children': []},{'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': 'sort_remaining'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '20', 'type': 'argument_list', 'children': ['21', '24']},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'return_indexer'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ascending'} | def sortlevel(self, level=None, ascending=True, sort_remaining=None):
return self.sort_values(return_indexer=True, ascending=ascending) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_duplicates'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '20']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '11', 'type': 'argument_list', 'children': ['12', '16', '17']},{'id': '12', 'type': 'concatenated_string', 'children': ['13', '14', '15']},{'id': '13', 'type': 'string', 'children': [], 'value': '"\'get_duplicates\' is deprecated and will be removed in "'},{'id': '14', 'type': 'string', 'children': [], 'value': '"a future release. You can use "'},{'id': '15', 'type': 'string', 'children': [], 'value': '"idx[idx.duplicated()].unique() instead"'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'FutureWarning'},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'stacklevel'},{'id': '19', 'type': 'integer', 'children': [], 'value': '2'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '31']},{'id': '22', 'type': 'attribute', 'children': ['23', '30']},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'duplicated'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '31', 'type': 'argument_list', 'children': []} | def get_duplicates(self):
warnings.warn("'get_duplicates' is deprecated and will be removed in "
"a future release. You can use "
"idx[idx.duplicated()].unique() instead",
FutureWarning, stacklevel=2)
return self[self.duplicated()].unique() |
{'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', '31', '53', '68', '108', '133', '158', '319']},{'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', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ensure_index'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '31', 'type': 'if_statement', 'children': ['32', '45']},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '39'], 'value': 'or'},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '38'], 'value': '=='},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_get_reconciled_name_object'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '53', 'type': 'if_statement', 'children': ['54', '60']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '59'], 'value': '=='},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_get_reconciled_name_object'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'if_statement', 'children': ['69', '79']},{'id': '69', 'type': 'not_operator', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'is_dtype_union_equal'},{'id': '72', 'type': 'argument_list', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '79', 'type': 'block', 'children': ['80', '89', '98']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': "'O'"},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'string', 'children': [], 'value': "'O'"},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '108', 'type': 'if_statement', 'children': ['109', '118', '125']},{'id': '109', 'type': 'boolean_operator', 'children': ['110', '114'], 'value': 'or'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'is_period_dtype'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'is_datetime64tz_dtype'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'lvals'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_ndarray_values'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'lvals'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_values'},{'id': '133', 'type': 'if_statement', 'children': ['134', '143', '150']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '139'], 'value': 'or'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'is_period_dtype'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'is_datetime64tz_dtype'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'other'},{'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': 'rvals'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_ndarray_values'},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'rvals'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_values'},{'id': '158', 'type': 'if_statement', 'children': ['159', '170', '217']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '167'], 'value': 'and'},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '164'], 'value': 'and'},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'is'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '163', 'type': 'None', 'children': []},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'is_monotonic'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'is_monotonic'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'try_statement', 'children': ['172', '185']},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '176', 'type': 'subscript', 'children': ['177', '184']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': '_outer_indexer'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'lvals'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'rvals'},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'except_clause', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '187', 'type': 'block', 'children': ['188', '195', '202']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'lvals'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'value_set'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'lvals'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'list_comprehension', 'children': ['209', '210', '213']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '210', 'type': 'for_in_clause', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'rvals'},{'id': '213', 'type': 'if_clause', 'children': ['214']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'not'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'value_set'},{'id': '217', 'type': 'else_clause', 'children': ['218']},{'id': '218', 'type': 'block', 'children': ['219', '228', '241', '279']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'get_indexer'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '232']},{'id': '230', 'type': 'pattern_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '232', 'type': 'call', 'children': ['233', '240']},{'id': '233', 'type': 'attribute', 'children': ['234', '239']},{'id': '234', 'type': '()', 'children': ['235']},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': '=='},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '237', 'type': 'unary_operator', 'children': ['238'], 'value': '-'},{'id': '238', 'type': 'integer', 'children': [], 'value': '1'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'nonzero'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'if_statement', 'children': ['242', '248', '273']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '247'], 'value': '>'},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '247', 'type': 'integer', 'children': [], 'value': '0'},{'id': '248', 'type': 'block', 'children': ['249', '262']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'other_diff'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'algos'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'take_nd'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258', '259']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'rvals'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'allow_fill'},{'id': '261', 'type': 'False', 'children': []},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': '_concat'},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_concat_compat'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'tuple', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'lvals'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'other_diff'},{'id': '273', 'type': 'else_clause', 'children': ['274']},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'lvals'},{'id': '279', 'type': 'if_statement', 'children': ['280', '283']},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': 'is'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '282', 'type': 'None', 'children': []},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'try_statement', 'children': ['285', '295']},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'safe_sort'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '295', 'type': 'except_clause', 'children': ['296', '300']},{'id': '296', 'type': 'as_pattern', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '298', 'type': 'as_pattern_target', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '306', 'type': 'argument_list', 'children': ['307', '315', '316']},{'id': '307', 'type': 'call', 'children': ['308', '313']},{'id': '308', 'type': 'attribute', 'children': ['309', '312']},{'id': '309', 'type': 'concatenated_string', 'children': ['310', '311']},{'id': '310', 'type': 'string', 'children': [], 'value': '"{}, sort order is undefined for "'},{'id': '311', 'type': 'string', 'children': [], 'value': '"incomparable objects"'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'RuntimeWarning'},{'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'stacklevel'},{'id': '318', 'type': 'integer', 'children': [], 'value': '3'},{'id': '319', 'type': 'return_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '323', 'type': 'identifier', 'children': [], 'value': '_wrap_setop_result'},{'id': '324', 'type': 'argument_list', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'result'} | def union(self, other, sort=None):
self._validate_sort_keyword(sort)
self._assert_can_do_setop(other)
other = ensure_index(other)
if len(other) == 0 or self.equals(other):
return self._get_reconciled_name_object(other)
if len(self) == 0:
return other._get_reconciled_name_object(self)
if not is_dtype_union_equal(self.dtype, other.dtype):
this = self.astype('O')
other = other.astype('O')
return this.union(other, sort=sort)
if is_period_dtype(self) or is_datetime64tz_dtype(self):
lvals = self._ndarray_values
else:
lvals = self._values
if is_period_dtype(other) or is_datetime64tz_dtype(other):
rvals = other._ndarray_values
else:
rvals = other._values
if sort is None and self.is_monotonic and other.is_monotonic:
try:
result = self._outer_indexer(lvals, rvals)[0]
except TypeError:
result = list(lvals)
value_set = set(lvals)
result.extend([x for x in rvals if x not in value_set])
else:
indexer = self.get_indexer(other)
indexer, = (indexer == -1).nonzero()
if len(indexer) > 0:
other_diff = algos.take_nd(rvals, indexer,
allow_fill=False)
result = _concat._concat_compat((lvals, other_diff))
else:
result = lvals
if sort is None:
try:
result = sorting.safe_sort(result)
except TypeError as e:
warnings.warn("{}, sort order is undefined for "
"incomparable objects".format(e),
RuntimeWarning, stacklevel=3)
return self._wrap_setop_result(other, result) |
{'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', '45', '56', '64', '73', '92', '112', '123', '143']},{'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': 'if_statement', 'children': ['25', '31']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_shallow_copy'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '42', 'type': 'slice', 'children': ['43', '44']},{'id': '43', 'type': 'colon', 'children': []},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'result_name'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_convert_can_do_setop'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_get_unique_index'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_indexer'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '91']},{'id': '82', 'type': 'call', 'children': ['83', '90']},{'id': '83', 'type': 'attribute', 'children': ['84', '89']},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '!='},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'nonzero'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'label_diff'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'setdiff1d'},{'id': '99', 'type': 'argument_list', 'children': ['100', '108', '109']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'assume_unique'},{'id': '111', 'type': 'True', 'children': []},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'label_diff'},{'id': '123', 'type': 'if_statement', 'children': ['124', '127']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'try_statement', 'children': ['129', '139']},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'safe_sort'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '139', 'type': 'except_clause', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'pass_statement', 'children': []},{'id': '143', 'type': 'return_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_shallow_copy'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '153']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'result_name'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '155', 'type': 'None', 'children': []} | def difference(self, other, sort=None):
self._validate_sort_keyword(sort)
self._assert_can_do_setop(other)
if self.equals(other):
return self._shallow_copy(self._data[:0])
other, result_name = self._convert_can_do_setop(other)
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)
the_diff = this.values.take(label_diff)
if sort is None:
try:
the_diff = sorting.safe_sort(the_diff)
except TypeError:
pass
return this._shallow_copy(the_diff, name=result_name, freq=None) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'symmetric_difference'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'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': 'result_name'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '20', '27', '38', '47', '55', '63', '72', '91', '111', '122', '136', '147', '158', '178', '186', '192', '203']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_validate_sort_keyword'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_assert_can_do_setop'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '32']},{'id': '29', 'type': 'pattern_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'result_name_update'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_convert_can_do_setop'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'result_name'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'result_name'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'result_name_update'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_get_unique_index'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_get_unique_index'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_indexer'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'common_indexer'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '90']},{'id': '81', 'type': 'call', 'children': ['82', '89']},{'id': '82', 'type': 'attribute', 'children': ['83', '88']},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '!='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '-'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'nonzero'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'left_indexer'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'setdiff1d'},{'id': '98', 'type': 'argument_list', 'children': ['99', '107', '108']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'common_indexer'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'assume_unique'},{'id': '110', 'type': 'True', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'left_diff'},{'id': '114', 'type': 'call', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'left_indexer'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'right_indexer'},{'id': '125', 'type': 'subscript', 'children': ['126', '135']},{'id': '126', 'type': 'call', 'children': ['127', '134']},{'id': '127', 'type': 'attribute', 'children': ['128', '133']},{'id': '128', 'type': '()', 'children': ['129']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '=='},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '131', 'type': 'unary_operator', 'children': ['132'], 'value': '-'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'nonzero'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'integer', 'children': [], 'value': '0'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'right_diff'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'right_indexer'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_concat'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_concat_compat'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'list', 'children': ['156', '157'], 'value': '[left_diff, right_diff]'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'left_diff'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'right_diff'},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'is'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '161', 'type': 'None', 'children': []},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'try_statement', 'children': ['164', '174']},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'safe_sort'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '174', 'type': 'except_clause', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'pass_statement', 'children': []},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_get_attributes_dict'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '190', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'result_name'},{'id': '192', 'type': 'if_statement', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'in'},{'id': '194', 'type': 'string', 'children': [], 'value': "'freq'"},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '202']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '201', 'type': 'string', 'children': [], 'value': "'freq'"},{'id': '202', 'type': 'None', 'children': []},{'id': '203', 'type': 'return_statement', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_shallow_copy_with_infer'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'the_diff'},{'id': '210', 'type': 'dictionary_splat', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'attribs'} | def symmetric_difference(self, other, result_name=None, sort=None):
self._validate_sort_keyword(sort)
self._assert_can_do_setop(other)
other, result_name_update = self._convert_can_do_setop(other)
if result_name is None:
result_name = result_name_update
this = self._get_unique_index()
other = other._get_unique_index()
indexer = this.get_indexer(other)
common_indexer = indexer.take((indexer != -1).nonzero()[0])
left_indexer = np.setdiff1d(np.arange(this.size), common_indexer,
assume_unique=True)
left_diff = this.values.take(left_indexer)
right_indexer = (indexer == -1).nonzero()[0]
right_diff = other.values.take(right_indexer)
the_diff = _concat._concat_compat([left_diff, right_diff])
if sort is None:
try:
the_diff = sorting.safe_sort(the_diff)
except TypeError:
pass
attribs = self._get_attributes_dict()
attribs['name'] = result_name
if 'freq' in attribs:
attribs['freq'] = None
return self._shallow_copy_with_infer(the_diff, **attribs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'asof'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'try_statement', 'children': ['8', '21', '28']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_loc'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '20', 'type': 'string', 'children': [], 'value': "'pad'"},{'id': '21', 'type': 'except_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_na_value'},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30', '52']},{'id': '30', 'type': 'if_statement', 'children': ['31', '36']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '40', 'type': 'subscript', 'children': ['41', '50']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'loc'} | def asof(self, label):
try:
loc = self.get_loc(label, method='pad')
except KeyError:
return self._na_value
else:
if isinstance(loc, slice):
loc = loc.indices(len(self))[-1]
return self[loc] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'return_indexer'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '20', '34', '43']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_as'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'if_statement', 'children': ['21', '23']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'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': '_as'},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_as'},{'id': '29', 'type': 'slice', 'children': ['30', '31', '32']},{'id': '30', 'type': 'colon', 'children': []},{'id': '31', 'type': 'colon', 'children': []},{'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'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': 'take'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_as'},{'id': '43', 'type': 'if_statement', 'children': ['44', '45', '50']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'return_indexer'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'expression_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_as'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted_index'} | def sort_values(self, return_indexer=False, ascending=True):
_as = self.argsort()
if not ascending:
_as = _as[::-1]
sorted_index = self.take(_as)
if return_indexer:
return sorted_index, _as
else:
return sorted_index |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '16', '30']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'asi8'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'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': 'result'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '35', 'type': 'argument_list', 'children': ['36', '38']},{'id': '36', 'type': 'list_splat', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '38', 'type': 'dictionary_splat', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def argsort(self, *args, **kwargs):
result = self.asi8
if result is None:
result = np.array(self)
return result.argsort(*args, **kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'slice_indexer'},{'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', '36', '48', '60']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'start_slice'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'end_slice'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'slice_locs'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30', '33']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '36', 'type': 'if_statement', 'children': ['37', '42']},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'is_scalar'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'start_slice'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'raise_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'AssertionError'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': '"Start slice bound is non-scalar"'},{'id': '48', 'type': 'if_statement', 'children': ['49', '54']},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'is_scalar'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'end_slice'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'AssertionError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"End slice bound is non-scalar"'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'start_slice'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'end_slice'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'step'} | def slice_indexer(self, start=None, end=None, step=None, kind=None):
start_slice, end_slice = self.slice_locs(start, end, step=step,
kind=kind)
if not is_scalar(start_slice):
raise AssertionError("Start slice bound is non-scalar")
if not is_scalar(end_slice):
raise AssertionError("End slice bound is non-scalar")
return slice(start_slice, end_slice, step) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_grouper'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'},{'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', '28', '43', '201', '255', '261', '267']},{'id': '10', 'type': 'if_statement', 'children': ['11', '22']},{'id': '11', 'type': 'boolean_operator', 'children': ['12', '17'], 'value': 'and'},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '16'], 'value': 'is'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': 'is'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '"The Grouper cannot specify both a key and a level!"'},{'id': '28', 'type': 'if_statement', 'children': ['29', '34']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': 'is'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_grouper'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_grouper'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'grouper'},{'id': '43', 'type': 'if_statement', 'children': ['44', '49', '119']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': 'is'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'block', 'children': ['50', '56']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'if_statement', 'children': ['57', '74', '88']},{'id': '57', 'type': '()', 'children': ['58']},{'id': '58', 'type': 'boolean_operator', 'children': ['59', '69'], 'value': 'and'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '68'], 'value': '=='},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '62', 'type': 'argument_list', 'children': ['63', '66', '67']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'grouper'},{'id': '66', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ABCSeries'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ax'},{'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': '_grouper'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'id': '89', 'type': 'block', 'children': ['90', '107']},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'not'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_info_axis'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'raise_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': '"The grouper name {0} is not found"'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '112', 'type': 'argument_list', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121', '132']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_get_axis'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '132', 'type': 'if_statement', 'children': ['133', '138']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': 'is'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'block', 'children': ['139', '145']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '145', 'type': 'if_statement', 'children': ['146', '151', '180']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '151', 'type': 'block', 'children': ['152', '161']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_get_level_number'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '166', 'type': 'argument_list', 'children': ['167', '173']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_get_level_values'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '175', 'type': 'subscript', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'if_statement', 'children': ['183', '190']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'not'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '185', 'type': 'tuple', 'children': ['186', '187']},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'raise_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': '"The level {0} is not valid"'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '201', 'type': 'if_statement', 'children': ['202', '213']},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '209'], 'value': 'and'},{'id': '203', 'type': '()', 'children': ['204']},{'id': '204', 'type': 'boolean_operator', 'children': ['205', '208'], 'value': 'or'},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '209', 'type': 'not_operator', 'children': ['210']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'is_monotonic'},{'id': '213', 'type': 'block', 'children': ['214', '229', '238']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '217', 'type': 'assignment', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '228', 'type': 'string', 'children': [], 'value': "'mergesort'"},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_take'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247', '252']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'is_copy'},{'id': '254', 'type': 'False', 'children': []},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'grouper'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'grouper'} | def _set_grouper(self, obj, sort=False):
if self.key is not None and self.level is not None:
raise ValueError(
"The Grouper cannot specify both a key and a level!")
if self._grouper is None:
self._grouper = self.grouper
if self.key is not None:
key = self.key
if (getattr(self.grouper, 'name', None) == key and
isinstance(obj, ABCSeries)):
ax = self._grouper.take(obj.index)
else:
if key not in obj._info_axis:
raise KeyError(
"The grouper name {0} is not found".format(key))
ax = Index(obj[key], name=key)
else:
ax = obj._get_axis(self.axis)
if self.level is not None:
level = self.level
if isinstance(ax, MultiIndex):
level = ax._get_level_number(level)
ax = Index(ax._get_level_values(level),
name=ax.names[level])
else:
if level not in (0, ax.name):
raise ValueError(
"The level {0} is not valid".format(level))
if (self.sort or sort) and not ax.is_monotonic:
indexer = self.indexer = ax.argsort(kind='mergesort')
ax = ax.take(indexer)
obj = obj._take(indexer, axis=self.axis, is_copy=False)
self.obj = obj
self.grouper = ax
return self.grouper |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_from_derivatives'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'yi'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'der'},{'id': '12', 'type': 'integer', 'children': [], 'value': '0'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'extrapolate'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '22', '30', '51']},{'id': '17', 'type': 'import_from_statement', 'children': ['18', '20']},{'id': '18', 'type': 'dotted_name', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '20', 'type': 'dotted_name', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'interpolate'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'interpolate'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'BPoly'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'from_derivatives'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '45', '48']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'yi'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '41', 'type': 'argument_list', 'children': ['42', '44']},{'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'extrapolate'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'extrapolate'},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'} | def _from_derivatives(xi, yi, x, order=None, der=0, extrapolate=False):
from scipy import interpolate
method = interpolate.BPoly.from_derivatives
m = method(xi, yi.reshape(-1, 1),
orders=order, extrapolate=extrapolate)
return m(x) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'recode_for_groupby'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'observed'},{'id': '7', 'type': 'block', 'children': ['8', '92', '99', '107', '130']},{'id': '8', 'type': 'if_statement', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'observed'},{'id': '10', 'type': 'block', 'children': ['11', '20', '29', '43', '54', '67', '79']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'unique_codes'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'unique1d'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'take_codes'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'unique_codes'},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '!='},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'unique_codes'},{'id': '27', 'type': 'unary_operator', 'children': ['28'], 'value': '-'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'if_statement', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'take_codes'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'take_codes'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'take_codes'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_recode_for_categories'},{'id': '59', 'type': 'argument_list', 'children': ['60', '63', '66']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'CategoricalDtype'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'expression_list', 'children': ['81', '91']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'Categorical'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '88']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'fastpath'},{'id': '90', 'type': 'True', 'children': []},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '92', 'type': 'if_statement', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'expression_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'add_categories'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '119', 'type': 'unary_operator', 'children': ['120'], 'value': '~'},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'expression_list', 'children': ['132', '140']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'reorder_categories'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '140', 'type': 'None', 'children': []} | def recode_for_groupby(c, sort, observed):
if observed:
unique_codes = unique1d(c.codes)
take_codes = unique_codes[unique_codes != -1]
if c.ordered:
take_codes = np.sort(take_codes)
categories = c.categories.take(take_codes)
codes = _recode_for_categories(c.codes,
c.categories,
categories)
dtype = CategoricalDtype(categories, ordered=c.ordered)
return Categorical(codes, dtype=dtype, fastpath=True), c
if sort:
return c, None
cat = c.unique()
cat = cat.add_categories(
c.categories[~c.categories.isin(cat.categories)])
return c.reorder_categories(cat.categories), None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_bins_generic'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'binner'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '7', 'type': 'block', 'children': ['8', '15', '22', '36', '50', '68', '84', '88', '92', '147']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'lenidx'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'lenbin'},{'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': 'binner'},{'id': '22', 'type': 'if_statement', 'children': ['23', '30']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '27'], 'value': 'or'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '<='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'lenidx'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '<='},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'lenbin'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'raise_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': '"Invalid length for values or for binner"'},{'id': '36', 'type': 'if_statement', 'children': ['37', '44']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '<'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'binner'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '"Values falls before first bin"'},{'id': '50', 'type': 'if_statement', 'children': ['51', '62']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '57'], 'value': '>'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '-'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'lenidx'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'binner'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '-'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'lenbin'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'raise_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': '"Values falls after last bin"'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79']},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '-'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'lenbin'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '101']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '-'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'lenbin'},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'id': '101', 'type': 'block', 'children': ['102', '110', '137', '143']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'r_bin'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'binner'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '+'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'while_statement', 'children': ['111', '132']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '115'], 'value': 'and'},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '<'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'lenidx'},{'id': '115', 'type': '()', 'children': ['116']},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '122'], 'value': 'or'},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': '<'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'r_bin'},{'id': '122', 'type': '()', 'children': ['123']},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '127'], 'value': 'and'},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '=='},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '126', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '=='},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'r_bin'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'augmented_assignment', 'children': ['135', '136'], 'value': '+='},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'augmented_assignment', 'children': ['145', '146'], 'value': '+='},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '146', 'type': 'integer', 'children': [], 'value': '1'},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'bins'} | def generate_bins_generic(values, binner, closed):
lenidx = len(values)
lenbin = len(binner)
if lenidx <= 0 or lenbin <= 0:
raise ValueError("Invalid length for values or for binner")
if values[0] < binner[0]:
raise ValueError("Values falls before first bin")
if values[lenidx - 1] > binner[lenbin - 1]:
raise ValueError("Values falls after last bin")
bins = np.empty(lenbin - 1, dtype=np.int64)
j = 0
bc = 0
for i in range(0, lenbin - 1):
r_bin = binner[i + 1]
while j < lenidx and (values[j] < r_bin or
(closed == 'right' and values[j] == r_bin)):
j += 1
bins[bc] = j
bc += 1
return bins |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'wide_to_long'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '10', 'type': 'string', 'children': [], 'value': '""'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '13', 'type': 'string', 'children': [], 'value': "r'\\d+'"},{'id': '14', 'type': 'block', 'children': ['15', '17', '76', '168', '189', '207', '228', '246', '260', '271', '292', '314', '332', '358', '384']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '17', 'type': 'function_definition', 'children': ['18', '19', '24']},{'id': '18', 'type': 'function_name', 'children': [], 'value': 'get_var_names'},{'id': '19', 'type': 'parameters', 'children': ['20', '21', '22', '23']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '24', 'type': 'block', 'children': ['25', '52', '61']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "r'^{stub}{sep}{suffix}$'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '32', 'type': 'argument_list', 'children': ['33', '41', '49']},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'list_comprehension', 'children': ['63', '64', '69']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '69', 'type': 'if_clause', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '76', 'type': 'function_definition', 'children': ['77', '78', '85']},{'id': '77', 'type': 'function_name', 'children': [], 'value': 'melt_stub'},{'id': '78', 'type': 'parameters', 'children': ['79', '80', '81', '82', '83', '84']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'value_vars'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '85', 'type': 'block', 'children': ['86', '110', '121', '144', '158']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'melt'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '96', '99', '107']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'id_vars'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'value_vars'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'value_vars'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'value_name'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '115']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'Categorical'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '126', 'type': 'call', 'children': ['127', '134']},{'id': '127', 'type': 'attribute', 'children': ['128', '133']},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '134', 'type': 'argument_list', 'children': ['135', '143']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '+'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '143', 'type': 'string', 'children': [], 'value': '""'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'to_numeric'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '157', 'type': 'string', 'children': [], 'value': "'ignore'"},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'newdf'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '+'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '166', 'type': 'list', 'children': ['167'], 'value': '[j]'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '168', 'type': 'if_statement', 'children': ['169', '174', '180']},{'id': '169', 'type': 'not_operator', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '178', 'type': 'list', 'children': ['179'], 'value': '[stubnames]'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '189', 'type': 'if_statement', 'children': ['190', '201']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '192', 'type': 'generator_expression', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'in'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '196', 'type': 'for_in_clause', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'raise_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'string', 'children': [], 'value': '"stubname can\'t be identical to a column name"'},{'id': '207', 'type': 'if_statement', 'children': ['208', '213', '219']},{'id': '208', 'type': 'not_operator', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'list', 'children': ['218'], 'value': '[i]'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '219', 'type': 'else_clause', 'children': ['220']},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '228', 'type': 'if_statement', 'children': ['229', '240']},{'id': '229', 'type': 'call', 'children': ['230', '239']},{'id': '230', 'type': 'attribute', 'children': ['231', '238']},{'id': '231', 'type': 'call', 'children': ['232', '237']},{'id': '232', 'type': 'attribute', 'children': ['233', '236']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'duplicated'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'raise_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'string', 'children': [], 'value': '"the id variables need to uniquely identify each row"'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'value_vars'},{'id': '249', 'type': 'list_comprehension', 'children': ['250', '257']},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'get_var_names'},{'id': '252', 'type': 'argument_list', 'children': ['253', '254', '255', '256']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '257', 'type': 'for_in_clause', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'value_vars_flattened'},{'id': '263', 'type': 'list_comprehension', 'children': ['264', '265', '268']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '265', 'type': 'for_in_clause', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'sublist'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'value_vars'},{'id': '268', 'type': 'for_in_clause', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'sublist'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'id_vars'},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '290']},{'id': '278', 'type': 'attribute', 'children': ['279', '289']},{'id': '279', 'type': 'call', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '288']},{'id': '283', 'type': 'attribute', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '288', 'type': 'argument_list', 'children': []},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'value_vars_flattened'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'melted'},{'id': '295', 'type': 'list_comprehension', 'children': ['296', '305']},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'melt_stub'},{'id': '298', 'type': 'argument_list', 'children': ['299', '300', '301', '302', '303', '304']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '305', 'type': 'for_in_clause', 'children': ['306', '309']},{'id': '306', 'type': 'pattern_list', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '311', 'type': 'argument_list', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'stubnames'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'value_vars'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'melted'},{'id': '317', 'type': 'call', 'children': ['318', '323']},{'id': '318', 'type': 'attribute', 'children': ['319', '322']},{'id': '319', 'type': 'subscript', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'melted'},{'id': '321', 'type': 'integer', 'children': [], 'value': '0'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '323', 'type': 'argument_list', 'children': ['324', '329']},{'id': '324', 'type': 'subscript', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'melted'},{'id': '326', 'type': 'slice', 'children': ['327', '328']},{'id': '327', 'type': 'integer', 'children': [], 'value': '1'},{'id': '328', 'type': 'colon', 'children': []},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '331', 'type': 'string', 'children': [], 'value': "'outer'"},{'id': '332', 'type': 'if_statement', 'children': ['333', '339']},{'id': '333', 'type': 'comparison_operator', 'children': ['334', '338'], 'value': '=='},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '338', 'type': 'integer', 'children': [], 'value': '1'},{'id': '339', 'type': 'block', 'children': ['340', '356']},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '343', 'type': 'call', 'children': ['344', '354']},{'id': '344', 'type': 'attribute', 'children': ['345', '353']},{'id': '345', 'type': 'call', 'children': ['346', '351']},{'id': '346', 'type': 'attribute', 'children': ['347', '350']},{'id': '347', 'type': 'subscript', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'id_vars'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'melted'},{'id': '356', 'type': 'return_statement', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '361', 'type': 'call', 'children': ['362', '379']},{'id': '362', 'type': 'attribute', 'children': ['363', '378']},{'id': '363', 'type': 'call', 'children': ['364', '369']},{'id': '364', 'type': 'attribute', 'children': ['365', '368']},{'id': '365', 'type': 'subscript', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'id_vars'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '369', 'type': 'argument_list', 'children': ['370', '375']},{'id': '370', 'type': 'call', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'melted'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '374', 'type': 'argument_list', 'children': []},{'id': '375', 'type': 'keyword_argument', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '379', 'type': 'argument_list', 'children': ['380']},{'id': '380', 'type': 'binary_operator', 'children': ['381', '382'], 'value': '+'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '382', 'type': 'list', 'children': ['383'], 'value': '[j]'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '384', 'type': 'return_statement', 'children': ['385']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'new'} | def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'):
r
def get_var_names(df, stub, sep, suffix):
regex = r'^{stub}{sep}{suffix}$'.format(
stub=re.escape(stub), sep=re.escape(sep), suffix=suffix)
pattern = re.compile(regex)
return [col for col in df.columns if pattern.match(col)]
def melt_stub(df, stub, i, j, value_vars, sep):
newdf = melt(df, id_vars=i, value_vars=value_vars,
value_name=stub.rstrip(sep), var_name=j)
newdf[j] = Categorical(newdf[j])
newdf[j] = newdf[j].str.replace(re.escape(stub + sep), "")
newdf[j] = to_numeric(newdf[j], errors='ignore')
return newdf.set_index(i + [j])
if not is_list_like(stubnames):
stubnames = [stubnames]
else:
stubnames = list(stubnames)
if any(col in stubnames for col in df.columns):
raise ValueError("stubname can't be identical to a column name")
if not is_list_like(i):
i = [i]
else:
i = list(i)
if df[i].duplicated().any():
raise ValueError("the id variables need to uniquely identify each row")
value_vars = [get_var_names(df, stub, sep, suffix) for stub in stubnames]
value_vars_flattened = [e for sublist in value_vars for e in sublist]
id_vars = list(set(df.columns.tolist()).difference(value_vars_flattened))
melted = [melt_stub(df, s, i, j, v, sep)
for s, v in zip(stubnames, value_vars)]
melted = melted[0].join(melted[1:], how='outer')
if len(i) == 1:
new = df[id_vars].set_index(i).join(melted)
return new
new = df[id_vars].merge(melted.reset_index(), on=i).set_index(i + [j])
return new |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '18']},{'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': 'nv'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'validate_argsort'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '18', 'type': 'if_statement', 'children': ['19', '24', '35']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '>'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '30', 'type': 'argument_list', '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': 'self'},{'id': '35', 'type': 'else_clause', 'children': ['36']},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '42', 'type': 'argument_list', 'children': ['43', '49', '51']},{'id': '43', 'type': 'binary_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': 'self'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'unary_operator', 'children': ['50'], 'value': '-'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'} | def argsort(self, *args, **kwargs):
nv.validate_argsort(args, kwargs)
if self._step > 0:
return np.arange(len(self))
else:
return np.arange(len(self) - 1, -1, -1) |
{'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', '51', '395']},{'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': '_assert_can_do_setop'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '17', 'type': 'if_statement', 'children': ['18', '38']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '32'], 'value': 'or'},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '26'], 'value': 'or'},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '37'], 'value': '=='},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '51', 'type': 'if_statement', 'children': ['52', '61']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '58'], 'value': 'and'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'RangeIndex'},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'block', 'children': ['62', '74', '92', '104', '122', '140', '158', '212', '220', '228']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '67', 'type': 'expression_list', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_start'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '81'], 'value': '+'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_start'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '85'], 'value': '*'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'binary_operator', 'children': ['87', '91'], 'value': '-'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '97', 'type': 'expression_list', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_start'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '111'], 'value': '+'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_start'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '115'], 'value': '*'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '115', 'type': '()', 'children': ['116']},{'id': '116', 'type': 'binary_operator', 'children': ['117', '121'], 'value': '-'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'if_statement', 'children': ['123', '128']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': '<'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '135']},{'id': '131', 'type': 'pattern_list', 'children': ['132', '133', '134']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '135', 'type': 'expression_list', 'children': ['136', '137', '139']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '137', 'type': 'unary_operator', 'children': ['138'], 'value': '-'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '140', 'type': 'if_statement', 'children': ['141', '146']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': '<'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_step'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '153']},{'id': '149', 'type': 'pattern_list', 'children': ['150', '151', '152']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '153', 'type': 'expression_list', 'children': ['154', '155', '157']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '155', 'type': 'unary_operator', 'children': ['156'], 'value': '-'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '158', 'type': 'if_statement', 'children': ['159', '172', '188', '200']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '166'], 'value': 'and'},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '165'], 'value': '=='},{'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': 'self'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '171'], 'value': '=='},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '171', 'type': 'integer', 'children': [], 'value': '1'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '185'], 'value': '-'},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_start'},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '187', 'type': 'identifier', 'children': [], 'value': '_start'},{'id': '188', 'type': 'elif_clause', 'children': ['189', '195']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '194'], 'value': '=='},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'step_s'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '200', 'type': 'elif_clause', 'children': ['201', '207']},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '206'], 'value': '=='},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '206', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'step_o'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'start_r'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '217', 'type': 'argument_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'end_r'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '228', 'type': 'if_statement', 'children': ['229', '232', '313', '354']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': '=='},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '232', 'type': 'block', 'children': ['233', '267']},{'id': '233', 'type': 'if_statement', 'children': ['234', '257']},{'id': '234', 'type': '()', 'children': ['235']},{'id': '235', 'type': 'boolean_operator', 'children': ['236', '251'], 'value': 'and'},{'id': '236', 'type': 'boolean_operator', 'children': ['237', '245'], 'value': 'and'},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '244'], 'value': '=='},{'id': '238', 'type': 'binary_operator', 'children': ['239', '243'], 'value': '%'},{'id': '239', 'type': '()', 'children': ['240']},{'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '-'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '244', 'type': 'integer', 'children': [], 'value': '0'},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '<='},{'id': '246', 'type': '()', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '-'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '251', 'type': 'comparison_operator', 'children': ['252', '256'], 'value': '<='},{'id': '252', 'type': '()', 'children': ['253']},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '-'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'return_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'RangeIndex'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263', '266']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'start_r'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '+'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'end_r'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '267', 'type': 'if_statement', 'children': ['268', '299']},{'id': '268', 'type': '()', 'children': ['269']},{'id': '269', 'type': 'boolean_operator', 'children': ['270', '288'], 'value': 'and'},{'id': '270', 'type': 'boolean_operator', 'children': ['271', '277'], 'value': 'and'},{'id': '271', 'type': '()', 'children': ['272']},{'id': '272', 'type': 'comparison_operator', 'children': ['273', '276'], 'value': '=='},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '275', 'type': 'integer', 'children': [], 'value': '2'},{'id': '276', 'type': 'integer', 'children': [], 'value': '0'},{'id': '277', 'type': '()', 'children': ['278']},{'id': '278', 'type': 'comparison_operator', 'children': ['279', '285'], 'value': '<='},{'id': '279', 'type': 'call', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'binary_operator', 'children': ['283', '284'], 'value': '-'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '/'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '287', 'type': 'integer', 'children': [], 'value': '2'},{'id': '288', 'type': '()', 'children': ['289']},{'id': '289', 'type': 'comparison_operator', 'children': ['290', '296'], 'value': '<='},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'binary_operator', 'children': ['294', '295'], 'value': '-'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '/'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '298', 'type': 'integer', 'children': [], 'value': '2'},{'id': '299', 'type': 'block', 'children': ['300']},{'id': '300', 'type': 'return_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'RangeIndex'},{'id': '303', 'type': 'argument_list', 'children': ['304', '305', '310']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'start_r'},{'id': '305', 'type': 'binary_operator', 'children': ['306', '307'], 'value': '+'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'end_r'},{'id': '307', 'type': 'binary_operator', 'children': ['308', '309'], 'value': '/'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '309', 'type': 'integer', 'children': [], 'value': '2'},{'id': '310', 'type': 'binary_operator', 'children': ['311', '312'], 'value': '/'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '312', 'type': 'integer', 'children': [], 'value': '2'},{'id': '313', 'type': 'elif_clause', 'children': ['314', '319']},{'id': '314', 'type': 'comparison_operator', 'children': ['315', '318'], 'value': '=='},{'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '%'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '318', 'type': 'integer', 'children': [], 'value': '0'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'if_statement', 'children': ['321', '344']},{'id': '321', 'type': '()', 'children': ['322']},{'id': '322', 'type': 'boolean_operator', 'children': ['323', '338'], 'value': 'and'},{'id': '323', 'type': 'boolean_operator', 'children': ['324', '332'], 'value': 'and'},{'id': '324', 'type': 'comparison_operator', 'children': ['325', '331'], 'value': '=='},{'id': '325', 'type': 'binary_operator', 'children': ['326', '330'], 'value': '%'},{'id': '326', 'type': '()', 'children': ['327']},{'id': '327', 'type': 'binary_operator', 'children': ['328', '329'], 'value': '-'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '331', 'type': 'integer', 'children': [], 'value': '0'},{'id': '332', 'type': '()', 'children': ['333']},{'id': '333', 'type': 'comparison_operator', 'children': ['334', '337'], 'value': '>='},{'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '+'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '338', 'type': '()', 'children': ['339']},{'id': '339', 'type': 'comparison_operator', 'children': ['340', '343'], 'value': '<='},{'id': '340', 'type': 'binary_operator', 'children': ['341', '342'], 'value': '-'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '344', 'type': 'block', 'children': ['345']},{'id': '345', 'type': 'return_statement', 'children': ['346']},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'RangeIndex'},{'id': '348', 'type': 'argument_list', 'children': ['349', '350', '353']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'start_r'},{'id': '350', 'type': 'binary_operator', 'children': ['351', '352'], 'value': '+'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'end_r'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '354', 'type': 'elif_clause', 'children': ['355', '360']},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '359'], 'value': '=='},{'id': '356', 'type': 'binary_operator', 'children': ['357', '358'], 'value': '%'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'step_s'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '359', 'type': 'integer', 'children': [], 'value': '0'},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'if_statement', 'children': ['362', '385']},{'id': '362', 'type': '()', 'children': ['363']},{'id': '363', 'type': 'boolean_operator', 'children': ['364', '379'], 'value': 'and'},{'id': '364', 'type': 'boolean_operator', 'children': ['365', '373'], 'value': 'and'},{'id': '365', 'type': 'comparison_operator', 'children': ['366', '372'], 'value': '=='},{'id': '366', 'type': 'binary_operator', 'children': ['367', '371'], 'value': '%'},{'id': '367', 'type': '()', 'children': ['368']},{'id': '368', 'type': 'binary_operator', 'children': ['369', '370'], 'value': '-'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '372', 'type': 'integer', 'children': [], 'value': '0'},{'id': '373', 'type': '()', 'children': ['374']},{'id': '374', 'type': 'comparison_operator', 'children': ['375', '378'], 'value': '>='},{'id': '375', 'type': 'binary_operator', 'children': ['376', '377'], 'value': '+'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'start_s'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'start_o'},{'id': '379', 'type': '()', 'children': ['380']},{'id': '380', 'type': 'comparison_operator', 'children': ['381', '384'], 'value': '<='},{'id': '381', 'type': 'binary_operator', 'children': ['382', '383'], 'value': '-'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'end_s'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'end_o'},{'id': '385', 'type': 'block', 'children': ['386']},{'id': '386', 'type': 'return_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'RangeIndex'},{'id': '389', 'type': 'argument_list', 'children': ['390', '391', '394']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'start_r'},{'id': '391', 'type': 'binary_operator', 'children': ['392', '393'], 'value': '+'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'end_r'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'step_o'},{'id': '395', 'type': 'return_statement', 'children': ['396']},{'id': '396', 'type': 'call', 'children': ['397', '402']},{'id': '397', 'type': 'attribute', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '400', 'type': 'identifier', 'children': [], 'value': '_int64index'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '402', 'type': 'argument_list', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '404', 'type': 'keyword_argument', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'sort'} | def union(self, other, sort=None):
self._assert_can_do_setop(other)
if len(other) == 0 or self.equals(other) or len(self) == 0:
return super().union(other, sort=sort)
if isinstance(other, RangeIndex) and sort is None:
start_s, step_s = self._start, self._step
end_s = self._start + self._step * (len(self) - 1)
start_o, step_o = other._start, other._step
end_o = other._start + other._step * (len(other) - 1)
if self._step < 0:
start_s, step_s, end_s = end_s, -step_s, start_s
if other._step < 0:
start_o, step_o, end_o = end_o, -step_o, start_o
if len(self) == 1 and len(other) == 1:
step_s = step_o = abs(self._start - other._start)
elif len(self) == 1:
step_s = step_o
elif len(other) == 1:
step_o = step_s
start_r = min(start_s, start_o)
end_r = max(end_s, end_o)
if step_o == step_s:
if ((start_s - start_o) % step_s == 0 and
(start_s - end_o) <= step_s and
(start_o - end_s) <= step_s):
return RangeIndex(start_r, end_r + step_s, step_s)
if ((step_s % 2 == 0) and
(abs(start_s - start_o) <= step_s / 2) and
(abs(end_s - end_o) <= step_s / 2)):
return RangeIndex(start_r, end_r + step_s / 2, step_s / 2)
elif step_o % step_s == 0:
if ((start_o - start_s) % step_s == 0 and
(start_o + step_s >= start_s) and
(end_o - step_s <= end_s)):
return RangeIndex(start_r, end_r + step_s, step_s)
elif step_s % step_o == 0:
if ((start_s - start_o) % step_o == 0 and
(start_s + step_o >= start_o) and
(end_s - step_o <= end_o)):
return RangeIndex(start_r, end_r + step_o, step_o)
return self._int64index.union(other, sort=sort) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nlargest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '9', 'type': 'string', 'children': [], 'value': "'first'"},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '30']},{'id': '13', 'type': 'attribute', 'children': ['14', '29']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'SelectNFrame'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20', '23', '26']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'nlargest'},{'id': '30', 'type': 'argument_list', 'children': []} | def nlargest(self, n, columns, keep='first'):
return algorithms.SelectNFrame(self,
n=n,
keep=keep,
columns=columns).nlargest() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nsmallest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '9', 'type': 'string', 'children': [], 'value': "'first'"},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '30']},{'id': '13', 'type': 'attribute', 'children': ['14', '29']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'SelectNFrame'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20', '23', '26']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'nsmallest'},{'id': '30', 'type': 'argument_list', 'children': []} | def nsmallest(self, n, columns, keep='first'):
return algorithms.SelectNFrame(self,
n=n,
keep=keep,
columns=columns).nsmallest() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'append'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '259', '267', '291']},{'id': '16', 'type': 'if_statement', 'children': ['17', '24', '204']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '21', 'type': 'tuple', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '24', 'type': 'block', 'children': ['25', '39', '56', '86', '99', '131', '143', '168', '182']},{'id': '25', 'type': 'if_statement', 'children': ['26', '31']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '39', 'type': 'if_statement', 'children': ['40', '48']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '46'], 'value': 'and'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': 'is'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'concatenated_string', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "'Can only append a Series if ignore_index=True'"},{'id': '55', 'type': 'string', 'children': [], 'value': "' or if the Series has a name'"},{'id': '56', 'type': 'if_statement', 'children': ['57', '62', '67']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': 'is'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '61', 'type': 'None', 'children': []},{'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': 'index'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '74', 'type': 'argument_list', 'children': ['75', '79']},{'id': '75', 'type': 'list', 'children': ['76'], 'value': '[other.name]'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'idx_diff'},{'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': 'other'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '99', 'type': 'try_statement', 'children': ['100', '112']},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'combined_columns'},{'id': '104', 'type': 'call', 'children': ['105', '110']},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'idx_diff'},{'id': '112', 'type': 'except_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'combined_columns'},{'id': '118', 'type': 'call', 'children': ['119', '129']},{'id': '119', 'type': 'attribute', 'children': ['120', '128']},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'idx_diff'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'combined_columns'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '142', 'type': 'False', 'children': []},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '148', 'type': 'argument_list', 'children': ['149', '162', '165']},{'id': '149', 'type': 'call', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'tuple', 'children': ['157', '158']},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'other'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'combined_columns'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '_convert'},{'id': '175', 'type': 'argument_list', 'children': ['176', '179']},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '178', 'type': 'True', 'children': []},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '181', 'type': 'True', 'children': []},{'id': '182', 'type': 'if_statement', 'children': ['183', '192']},{'id': '183', 'type': 'not_operator', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '190']},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'combined_columns'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'combined_columns'},{'id': '204', 'type': 'elif_clause', 'children': ['205', '219']},{'id': '205', 'type': 'boolean_operator', 'children': ['206', '211'], 'value': 'and'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '211', 'type': 'not_operator', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '214', 'type': 'argument_list', 'children': ['215', '218']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '217', 'type': 'integer', 'children': [], 'value': '0'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '219', 'type': 'block', 'children': ['220', '227']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '227', 'type': 'if_statement', 'children': ['228', '245']},{'id': '228', 'type': 'call', 'children': ['229', '244']},{'id': '229', 'type': 'attribute', 'children': ['230', '243']},{'id': '230', 'type': '()', 'children': ['231']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '242'], 'value': '>='},{'id': '232', 'type': 'call', 'children': ['233', '238']},{'id': '233', 'type': 'attribute', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'get_indexer'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '242', 'type': 'integer', 'children': [], 'value': '0'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '244', 'type': 'argument_list', 'children': []},{'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': 'other'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'reindex'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '259', 'type': 'import_from_statement', 'children': ['260', '265']},{'id': '260', 'type': 'dotted_name', 'children': ['261', '262', '263', '264']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '265', 'type': 'dotted_name', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '267', 'type': 'if_statement', 'children': ['268', '275', '283']},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '272', 'type': 'tuple', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '275', 'type': 'block', 'children': ['276']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'to_concat'},{'id': '279', 'type': 'binary_operator', 'children': ['280', '282'], 'value': '+'},{'id': '280', 'type': 'list', 'children': ['281'], 'value': '[self]'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '283', 'type': 'else_clause', 'children': ['284']},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'to_concat'},{'id': '288', 'type': 'list', 'children': ['289', '290'], 'value': '[self, other]'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '291', 'type': 'return_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '294', 'type': 'argument_list', 'children': ['295', '296', '299', '302']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'to_concat'},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'sort'} | def append(self, other, ignore_index=False,
verify_integrity=False, sort=None):
if isinstance(other, (Series, dict)):
if isinstance(other, dict):
other = Series(other)
if other.name is None and not ignore_index:
raise TypeError('Can only append a Series if ignore_index=True'
' or if the Series has a name')
if other.name is None:
index = None
else:
index = Index([other.name], name=self.index.name)
idx_diff = other.index.difference(self.columns)
try:
combined_columns = self.columns.append(idx_diff)
except TypeError:
combined_columns = self.columns.astype(object).append(idx_diff)
other = other.reindex(combined_columns, copy=False)
other = DataFrame(other.values.reshape((1, len(other))),
index=index,
columns=combined_columns)
other = other._convert(datetime=True, timedelta=True)
if not self.columns.equals(combined_columns):
self = self.reindex(columns=combined_columns)
elif isinstance(other, list) and not isinstance(other[0], DataFrame):
other = DataFrame(other)
if (self.columns.get_indexer(other.columns) >= 0).all():
other = other.reindex(columns=self.columns)
from pandas.core.reshape.concat import concat
if isinstance(other, (list, tuple)):
to_concat = [self] + other
else:
to_concat = [self, other]
return concat(to_concat, ignore_index=ignore_index,
verify_integrity=verify_integrity,
sort=sort) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'join'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'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': 'on'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '11', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'lsuffix'},{'id': '14', 'type': 'string', 'children': [], 'value': "''"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'rsuffix'},{'id': '17', 'type': 'string', 'children': [], 'value': "''"},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_join_compat'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '32', '35', '38', '41']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'lsuffix'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'lsuffix'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'rsuffix'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'rsuffix'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'} | def join(self, other, on=None, how='left', lsuffix='', rsuffix='',
sort=False):
return self._join_compat(other, on=on, how=how, lsuffix=lsuffix,
rsuffix=rsuffix, sort=sort) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_values_for_argsort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'attribute', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '9', 'type': 'block', 'children': ['10', '20', '34']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '27']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_mask'},{'id': '27', 'type': 'binary_operator', 'children': ['28', '33'], 'value': '-'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'} | def _values_for_argsort(self) -> np.ndarray:
data = self._data.copy()
data[self._mask] = data.min() - 1
return data |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_combined_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'intersect'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '19', '93', '110']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_get_distinct_objs'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '19', 'type': 'if_statement', 'children': ['20', '26', '34', '48', '74']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'index'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'list', 'children': [], 'value': '[]'},{'id': '34', 'type': 'elif_clause', 'children': ['35', '41']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], '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': 'indexes'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'elif_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'intersect'},{'id': '50', 'type': 'block', 'children': ['51', '57']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '64']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '61', 'type': 'slice', 'children': ['62', '63']},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'colon', 'children': []},{'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': 'index'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76', '86']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_union_indexes'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ensure_index'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '93', 'type': 'if_statement', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'try_statement', 'children': ['97', '106']},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'except_clause', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'pass_statement', 'children': []},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'index'} | def _get_combined_index(indexes, intersect=False, sort=False):
indexes = _get_distinct_objs(indexes)
if len(indexes) == 0:
index = Index([])
elif len(indexes) == 1:
index = indexes[0]
elif intersect:
index = indexes[0]
for other in indexes[1:]:
index = index.intersection(other)
else:
index = _union_indexes(indexes, sort=sort)
index = ensure_index(index)
if sort:
try:
index = index.sort_values()
except TypeError:
pass
return index |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_union_indexes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '22', '55', '64', '111']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '15'], 'value': '=='},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'AssertionError'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'Must have at least 1 Index to union'"},{'id': '22', 'type': 'if_statement', 'children': ['23', '29']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '28'], 'value': '=='},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'block', 'children': ['30', '36', '53']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'if_statement', 'children': ['37', '42']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '60']},{'id': '57', 'type': 'pattern_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_sanitize_and_check'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '64', 'type': 'function_definition', 'children': ['65', '66', '68']},{'id': '65', 'type': 'function_name', 'children': [], 'value': '_unique_indices'},{'id': '66', 'type': 'parameters', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '68', 'type': 'block', 'children': ['69', '91']},{'id': '69', 'type': 'function_definition', 'children': ['70', '71', '73']},{'id': '70', 'type': 'function_name', 'children': [], 'value': 'conv'},{'id': '71', 'type': 'parameters', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'block', 'children': ['74', '89']},{'id': '74', 'type': 'if_statement', 'children': ['75', '80']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'fast_unique_multiple_list'},{'id': '99', 'type': 'argument_list', 'children': ['100', '108']},{'id': '100', 'type': 'list_comprehension', 'children': ['101', '105']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '111', 'type': 'if_statement', 'children': ['112', '115', '161', '243']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '114', 'type': 'string', 'children': [], 'value': "'special'"},{'id': '115', 'type': 'block', 'children': ['116', '122']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'if_statement', 'children': ['123', '128', '140']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '127', 'type': 'string', 'children': [], 'value': "'union_many'"},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'union_many'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '137', 'type': 'slice', 'children': ['138', '139']},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'colon', 'children': []},{'id': '140', 'type': 'else_clause', 'children': ['141']},{'id': '141', 'type': 'block', 'children': ['142', '159']},{'id': '142', 'type': 'for_statement', 'children': ['143', '144', '149']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '146', 'type': 'slice', 'children': ['147', '148']},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'colon', 'children': []},{'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': 'result'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '159', 'type': 'return_statement', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '161', 'type': 'elif_clause', 'children': ['162', '165']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '=='},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '164', 'type': 'string', 'children': [], 'value': "'array'"},{'id': '165', 'type': 'block', 'children': ['166', '172', '214', '223', '241']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'for_statement', 'children': ['173', '174', '179']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '176', 'type': 'slice', 'children': ['177', '178']},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'colon', 'children': []},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'if_statement', 'children': ['181', '188']},{'id': '181', 'type': 'not_operator', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '188', 'type': 'block', 'children': ['189', '209']},{'id': '189', 'type': 'if_statement', 'children': ['190', '193']},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'is'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '192', 'type': 'None', 'children': []},{'id': '193', 'type': 'block', 'children': ['194', '205']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201', '202']},{'id': '200', 'type': 'identifier', 'children': [], 'value': '_sort_msg'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'FutureWarning'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'stacklevel'},{'id': '204', 'type': 'integer', 'children': [], 'value': '8'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '208', 'type': 'True', 'children': []},{'id': '209', 'type': 'return_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_unique_indices'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '217', 'type': 'subscript', 'children': ['218', '222']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': '_get_consensus_names'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '222', 'type': 'integer', 'children': [], 'value': '0'},{'id': '223', 'type': 'if_statement', 'children': ['224', '229']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': '!='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '236', 'type': 'identifier', 'children': [], 'value': '_shallow_copy'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '243', 'type': 'else_clause', 'children': ['244']},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'return_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': '_unique_indices'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'indexes'} | def _union_indexes(indexes, sort=True):
if len(indexes) == 0:
raise AssertionError('Must have at least 1 Index to union')
if len(indexes) == 1:
result = indexes[0]
if isinstance(result, list):
result = Index(sorted(result))
return result
indexes, kind = _sanitize_and_check(indexes)
def _unique_indices(inds):
def conv(i):
if isinstance(i, Index):
i = i.tolist()
return i
return Index(
lib.fast_unique_multiple_list([conv(i) for i in inds], sort=sort))
if kind == 'special':
result = indexes[0]
if hasattr(result, 'union_many'):
return result.union_many(indexes[1:])
else:
for other in indexes[1:]:
result = result.union(other)
return result
elif kind == 'array':
index = indexes[0]
for other in indexes[1:]:
if not index.equals(other):
if sort is None:
warnings.warn(_sort_msg, FutureWarning, stacklevel=8)
sort = True
return _unique_indices(indexes)
name = _get_consensus_names(indexes)[0]
if name != index.name:
index = index._shallow_copy(name=name)
return index
else:
return _unique_indices(indexes) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sanitize_and_check'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '5', 'type': 'block', 'children': ['6', '20', '70']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kinds'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'set_comprehension', 'children': ['13', '17']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'in'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kinds'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '32', '64']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '31'], 'value': '>'},{'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': 'kinds'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'block', 'children': ['33', '57']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '54']},{'id': '37', 'type': 'conditional_expression', 'children': ['38', '47', '53'], 'value': 'if'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'com'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'try_sort'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'kinds'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '64', 'type': 'else_clause', 'children': ['65']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'expression_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '69', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '81', '86']},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '78'], 'value': 'or'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '77'], 'value': '>'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'kinds'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'not'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'kinds'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'expression_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '85', 'type': 'string', 'children': [], 'value': "'special'"},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'expression_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '91', 'type': 'string', 'children': [], 'value': "'array'"} | def _sanitize_and_check(indexes):
kinds = list({type(index) for index in indexes})
if list in kinds:
if len(kinds) > 1:
indexes = [Index(com.try_sort(x))
if not isinstance(x, Index) else
x for x in indexes]
kinds.remove(list)
else:
return indexes, 'list'
if len(kinds) > 1 or Index not in kinds:
return indexes, 'special'
else:
return indexes, 'array' |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_from_inferred_categories'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'inferred_categories'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'inferred_codes'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'true_values'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '23', '30', '45', '133', '208']},{'id': '12', 'type': 'import_from_statement', 'children': ['13', '15', '17', '19', '21']},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '15', 'type': 'dotted_name', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '17', 'type': 'dotted_name', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'to_numeric'},{'id': '19', 'type': 'dotted_name', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'to_datetime'},{'id': '21', 'type': 'dotted_name', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'to_timedelta'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'inferred_categories'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'known_categories'},{'id': '33', 'type': '()', 'children': ['34']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '40'], 'value': 'and'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'CategoricalDtype'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': 'is'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'known_categories'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'if_statement', 'children': ['49', '56', '67', '85', '103']},{'id': '49', 'type': 'call', 'children': ['50', '55']},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'is_numeric'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'to_numeric'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'inferred_categories'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '66', 'type': 'string', 'children': [], 'value': '"coerce"'},{'id': '67', 'type': 'elif_clause', 'children': ['68', '74']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'is_datetime64_dtype'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'to_datetime'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'inferred_categories'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '84', 'type': 'string', 'children': [], 'value': '"coerce"'},{'id': '85', 'type': 'elif_clause', 'children': ['86', '92']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'is_timedelta64_dtype'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'to_timedelta'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'inferred_categories'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '102', 'type': 'string', 'children': [], 'value': '"coerce"'},{'id': '103', 'type': 'elif_clause', 'children': ['104', '111']},{'id': '104', 'type': 'call', 'children': ['105', '110']},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'is_boolean'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'block', 'children': ['112', '124']},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'true_values'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'true_values'},{'id': '120', 'type': 'list', 'children': ['121', '122', '123'], 'value': '["True", "TRUE", "true"]'},{'id': '121', 'type': 'string', 'children': [], 'value': '"True"'},{'id': '122', 'type': 'string', 'children': [], 'value': '"TRUE"'},{'id': '123', 'type': 'string', 'children': [], 'value': '"true"'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'true_values'},{'id': '133', 'type': 'if_statement', 'children': ['134', '135', '151', '192']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'known_categories'},{'id': '135', 'type': 'block', 'children': ['136', '142']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_recode_for_categories'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149', '150']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'inferred_codes'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '151', 'type': 'elif_clause', 'children': ['152', '156']},{'id': '152', 'type': 'not_operator', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'is_monotonic_increasing'},{'id': '156', 'type': 'block', 'children': ['157', '165', '173', '182']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'unsorted'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_recode_for_categories'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '181']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'inferred_codes'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'unsorted'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'CategoricalDtype'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '191', 'type': 'False', 'children': []},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194', '204']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'CategoricalDtype'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '203', 'type': 'False', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'inferred_codes'},{'id': '208', 'type': 'return_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213', '216']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'fastpath'},{'id': '218', 'type': 'True', 'children': []} | def _from_inferred_categories(cls, inferred_categories, inferred_codes,
dtype, true_values=None):
from pandas import Index, to_numeric, to_datetime, to_timedelta
cats = Index(inferred_categories)
known_categories = (isinstance(dtype, CategoricalDtype) and
dtype.categories is not None)
if known_categories:
if dtype.categories.is_numeric():
cats = to_numeric(inferred_categories, errors="coerce")
elif is_datetime64_dtype(dtype.categories):
cats = to_datetime(inferred_categories, errors="coerce")
elif is_timedelta64_dtype(dtype.categories):
cats = to_timedelta(inferred_categories, errors="coerce")
elif dtype.categories.is_boolean():
if true_values is None:
true_values = ["True", "TRUE", "true"]
cats = cats.isin(true_values)
if known_categories:
categories = dtype.categories
codes = _recode_for_categories(inferred_codes, cats, categories)
elif not cats.is_monotonic_increasing:
unsorted = cats.copy()
categories = cats.sort_values()
codes = _recode_for_categories(inferred_codes, unsorted,
categories)
dtype = CategoricalDtype(categories, ordered=False)
else:
dtype = CategoricalDtype(cats, ordered=False)
codes = inferred_codes
return cls(codes, dtype=dtype, fastpath=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'},{'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': 'inplace'},{'id': '7', 'type': 'False', 'children': []},{'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': 'na_position'},{'id': '13', 'type': 'string', 'children': [], 'value': "'last'"},{'id': '14', 'type': 'block', 'children': ['15', '23', '46', '59']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'validate_bool_kwarg'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '22', 'type': 'string', 'children': [], 'value': "'inplace'"},{'id': '23', 'type': 'if_statement', 'children': ['24', '29']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'not'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '26', 'type': 'list', 'children': ['27', '28'], 'value': "['last', 'first']"},{'id': '27', 'type': 'string', 'children': [], 'value': "'last'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'first'"},{'id': '29', 'type': 'block', 'children': ['30', '34']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '33', 'type': 'string', 'children': [], 'value': "'invalid na_position: {na_position!r}'"},{'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': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted_idx'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'nargsort'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53', '56']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '59', 'type': 'if_statement', 'children': ['60', '61', '72']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_codes'},{'id': '67', 'type': 'subscript', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_codes'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted_idx'},{'id': '72', 'type': 'else_clause', 'children': ['73']},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_constructor'},{'id': '79', 'type': 'argument_list', 'children': ['80', '87', '92']},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_codes'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted_idx'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'fastpath'},{'id': '94', 'type': 'True', 'children': []} | def sort_values(self, inplace=False, ascending=True, na_position='last'):
inplace = validate_bool_kwarg(inplace, 'inplace')
if na_position not in ['last', 'first']:
msg = 'invalid na_position: {na_position!r}'
raise ValueError(msg.format(na_position=na_position))
sorted_idx = nargsort(self,
ascending=ascending,
na_position=na_position)
if inplace:
self._codes = self._codes[sorted_idx]
else:
return self._constructor(values=self._codes[sorted_idx],
dtype=self.dtype,
fastpath=True) |
{'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': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '15', '23', '29', '38', '52']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'unique_codes'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'unique1d'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cat'},{'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': 'copy'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_codes'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'unique_codes'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'take_codes'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'unique_codes'},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '!='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'unique_codes'},{'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'take_codes'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'take_codes'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'set_categories'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'take_codes'} | def unique(self):
unique_codes = unique1d(self.codes)
cat = self.copy()
cat._codes = unique_codes
take_codes = unique_codes[unique_codes != -1]
if self.ordered:
take_codes = np.sort(take_codes)
return cat.set_categories(cat.categories.take(take_codes)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '35']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'concat'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '10', 'type': 'string', 'children': [], 'value': "'outer'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'join_axes'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'block', 'children': ['36', '73']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_Concatenator'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '46', '49', '52', '55', '58', '61', '64', '67', '70']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'join_axes'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'join_axes'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_result'},{'id': '78', 'type': 'argument_list', 'children': []} | def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
keys=None, levels=None, names=None, verify_integrity=False,
sort=None, copy=True):
op = _Concatenator(objs, axis=axis, join_axes=join_axes,
ignore_index=ignore_index, join=join,
keys=keys, levels=levels, names=names,
verify_integrity=verify_integrity,
copy=copy, sort=sort)
return op.get_result() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cut'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'retbins'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '17', 'type': 'integer', 'children': [], 'value': '3'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'include_lowest'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'id': '23', 'type': 'string', 'children': [], 'value': "'raise'"},{'id': '24', 'type': 'block', 'children': ['25', '36', '45', '330', '358']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '32']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29', '30', '31']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x_is_series'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'series_index'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_preprocess_for_cut'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '41']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_coerce_to_type'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'if_statement', 'children': ['46', '53', '249', '266']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '53', 'type': 'block', 'children': ['54', '69', '95', '105', '121', '133']},{'id': '54', 'type': 'if_statement', 'children': ['55', '63']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '60'], 'value': 'and'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'is_scalar'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '<'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'raise_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': '"`bins` should be a positive integer."'},{'id': '69', 'type': 'try_statement', 'children': ['70', '77']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sz'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '77', 'type': 'except_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '79', 'type': 'block', 'children': ['80', '89']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sz'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '=='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sz'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'Cannot cut empty array'"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'rng'},{'id': '108', 'type': 'tuple', 'children': ['109', '115']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'nanops'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'nanmin'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'nanops'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'nanmax'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '126', 'type': 'list_comprehension', 'children': ['127', '130']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'mi'},{'id': '129', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'mi'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'rng'},{'id': '133', 'type': 'if_statement', 'children': ['134', '147', '155', '204']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '141'], 'value': 'or'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'isinf'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'isinf'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'raise_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'concatenated_string', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': "'cannot specify integer `bins` when input data '"},{'id': '154', 'type': 'string', 'children': [], 'value': "'contains infinity'"},{'id': '155', 'type': 'elif_clause', 'children': ['156', '159']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': '=='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '159', 'type': 'block', 'children': ['160', '174', '188']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'augmented_assignment', 'children': ['162', '163'], 'value': '-='},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '163', 'type': 'conditional_expression', 'children': ['164', '170', '173'], 'value': 'if'},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '*'},{'id': '165', 'type': 'float', 'children': [], 'value': '.001'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '!='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '172', 'type': 'integer', 'children': [], 'value': '0'},{'id': '173', 'type': 'float', 'children': [], 'value': '.001'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '+='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '177', 'type': 'conditional_expression', 'children': ['178', '184', '187'], 'value': 'if'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '*'},{'id': '179', 'type': 'float', 'children': [], 'value': '.001'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '!='},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'float', 'children': [], 'value': '.001'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'linspace'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197', '198', '201']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '+'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '203', 'type': 'True', 'children': []},{'id': '204', 'type': 'else_clause', 'children': ['205']},{'id': '205', 'type': 'block', 'children': ['206', '222', '231']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'linspace'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215', '216', '219']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '+'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '218', 'type': 'integer', 'children': [], 'value': '1'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '221', 'type': 'True', 'children': []},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'adj'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '230'], 'value': '*'},{'id': '226', 'type': '()', 'children': ['227']},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '-'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '230', 'type': 'float', 'children': [], 'value': '0.001'},{'id': '231', 'type': 'if_statement', 'children': ['232', '233', '240']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'augmented_assignment', 'children': ['236', '239'], 'value': '-='},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '238', 'type': 'integer', 'children': [], 'value': '0'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'adj'},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'augmented_assignment', 'children': ['244', '248'], 'value': '+='},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '246', 'type': 'unary_operator', 'children': ['247'], 'value': '-'},{'id': '247', 'type': 'integer', 'children': [], 'value': '1'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'adj'},{'id': '249', 'type': 'elif_clause', 'children': ['250', '255']},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '252', 'type': 'argument_list', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'IntervalIndex'},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'if_statement', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'is_overlapping'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'raise_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'string', 'children': [], 'value': "'Overlapping IntervalIndex is not accepted.'"},{'id': '266', 'type': 'else_clause', 'children': ['267']},{'id': '267', 'type': 'block', 'children': ['268', '297', '305']},{'id': '268', 'type': 'if_statement', 'children': ['269', '273', '286']},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'is_datetime64tz_dtype'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '281', 'type': 'argument_list', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '285', 'type': 'identifier', 'children': [], 'value': '_NS_DTYPE'},{'id': '286', 'type': 'else_clause', 'children': ['287']},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'assignment', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': '_convert_bin_to_numeric_type'},{'id': '302', 'type': 'argument_list', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '305', 'type': 'if_statement', 'children': ['306', '324']},{'id': '306', 'type': 'call', 'children': ['307', '323']},{'id': '307', 'type': 'attribute', 'children': ['308', '322']},{'id': '308', 'type': '()', 'children': ['309']},{'id': '309', 'type': 'comparison_operator', 'children': ['310', '321'], 'value': '<'},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'string', 'children': [], 'value': "'float64'"},{'id': '321', 'type': 'integer', 'children': [], 'value': '0'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '323', 'type': 'argument_list', 'children': []},{'id': '324', 'type': 'block', 'children': ['325']},{'id': '325', 'type': 'raise_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'string', 'children': [], 'value': "'bins must increase monotonically.'"},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '335']},{'id': '332', 'type': 'pattern_list', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'fac'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '335', 'type': 'call', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': '_bins_to_cuts'},{'id': '337', 'type': 'argument_list', 'children': ['338', '339', '340', '343', '346', '349', '352', '355']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '349', 'type': 'keyword_argument', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'include_lowest'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'include_lowest'},{'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '355', 'type': 'keyword_argument', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'id': '358', 'type': 'return_statement', 'children': ['359']},{'id': '359', 'type': 'call', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': '_postprocess_for_cut'},{'id': '361', 'type': 'argument_list', 'children': ['362', '363', '364', '365', '366', '367', '368']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'fac'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'retbins'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'x_is_series'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'series_index'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'dtype'} | def cut(x, bins, right=True, labels=None, retbins=False, precision=3,
include_lowest=False, duplicates='raise'):
x_is_series, series_index, name, x = _preprocess_for_cut(x)
x, dtype = _coerce_to_type(x)
if not np.iterable(bins):
if is_scalar(bins) and bins < 1:
raise ValueError("`bins` should be a positive integer.")
try:
sz = x.size
except AttributeError:
x = np.asarray(x)
sz = x.size
if sz == 0:
raise ValueError('Cannot cut empty array')
rng = (nanops.nanmin(x), nanops.nanmax(x))
mn, mx = [mi + 0.0 for mi in rng]
if np.isinf(mn) or np.isinf(mx):
raise ValueError('cannot specify integer `bins` when input data '
'contains infinity')
elif mn == mx:
mn -= .001 * abs(mn) if mn != 0 else .001
mx += .001 * abs(mx) if mx != 0 else .001
bins = np.linspace(mn, mx, bins + 1, endpoint=True)
else:
bins = np.linspace(mn, mx, bins + 1, endpoint=True)
adj = (mx - mn) * 0.001
if right:
bins[0] -= adj
else:
bins[-1] += adj
elif isinstance(bins, IntervalIndex):
if bins.is_overlapping:
raise ValueError('Overlapping IntervalIndex is not accepted.')
else:
if is_datetime64tz_dtype(bins):
bins = np.asarray(bins, dtype=_NS_DTYPE)
else:
bins = np.asarray(bins)
bins = _convert_bin_to_numeric_type(bins, dtype)
if (np.diff(bins.astype('float64')) < 0).any():
raise ValueError('bins must increase monotonically.')
fac, bins = _bins_to_cuts(x, bins, right=right, labels=labels,
precision=precision,
include_lowest=include_lowest,
dtype=dtype,
duplicates=duplicates)
return _postprocess_for_cut(fac, bins, retbins, x_is_series,
series_index, name, dtype) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'union_categoricals'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_categories'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ignore_order'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '23', '31', '44', '78', '89', '95', '126', '130', '412', '419']},{'id': '12', 'type': 'import_from_statement', 'children': ['13', '15', '17', '19', '21']},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '15', 'type': 'dotted_name', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '17', 'type': 'dotted_name', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Categorical'},{'id': '19', 'type': 'dotted_name', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'CategoricalIndex'},{'id': '21', 'type': 'dotted_name', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '23', 'type': 'import_from_statement', 'children': ['24', '29']},{'id': '24', 'type': 'dotted_name', 'children': ['25', '26', '27', '28']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'categorical'},{'id': '29', 'type': 'dotted_name', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_recode_for_categories'},{'id': '31', 'type': 'if_statement', 'children': ['32', '38']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '37'], 'value': '=='},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'raise_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'No Categoricals to union'"},{'id': '44', 'type': 'function_definition', 'children': ['45', '46', '48']},{'id': '45', 'type': 'function_name', 'children': [], 'value': '_maybe_unwrap'},{'id': '46', 'type': 'parameters', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '57', '62', '71']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'tuple', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'CategoricalIndex'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '62', 'type': 'elif_clause', 'children': ['63', '68']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'Categorical'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': '"all components to combine must be Categorical"'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '81', 'type': 'list_comprehension', 'children': ['82', '86']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_maybe_unwrap'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '86', 'type': 'for_in_clause', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'if_statement', 'children': ['96', '120']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '99', 'type': 'generator_expression', 'children': ['100', '113']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'is_dtype_equal'},{'id': '102', 'type': 'argument_list', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '117', 'type': 'slice', 'children': ['118', '119']},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'raise_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': '"dtype of categories must be the same"'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '129', 'type': 'False', 'children': []},{'id': '130', 'type': 'if_statement', 'children': ['131', '147', '297', '380']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '133', 'type': 'generator_expression', 'children': ['134', '140']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'is_dtype_equal'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '144', 'type': 'slice', 'children': ['145', '146']},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'colon', 'children': []},{'id': '147', 'type': 'block', 'children': ['148', '154', '160', '236', '251']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '160', 'type': 'if_statement', 'children': ['161', '181', '197']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '163', 'type': 'generator_expression', 'children': ['164', '174']},{'id': '164', 'type': 'call', 'children': ['165', '170']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '174', 'type': 'for_in_clause', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '178', 'type': 'slice', 'children': ['179', '180']},{'id': '179', 'type': 'integer', 'children': [], 'value': '1'},{'id': '180', 'type': 'colon', 'children': []},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'list_comprehension', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '194', 'type': 'for_in_clause', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '197', 'type': 'else_clause', 'children': ['198']},{'id': '198', 'type': 'block', 'children': ['199', '227']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '202', 'type': 'binary_operator', 'children': ['203', '207'], 'value': '+'},{'id': '203', 'type': 'list', 'children': ['204'], 'value': '[first.codes]'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '207', 'type': 'list_comprehension', 'children': ['208', '220']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_recode_for_categories'},{'id': '210', 'type': 'argument_list', 'children': ['211', '214', '217']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '220', 'type': 'for_in_clause', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '224', 'type': 'slice', 'children': ['225', '226']},{'id': '225', 'type': 'integer', 'children': [], 'value': '1'},{'id': '226', 'type': 'colon', 'children': []},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '236', 'type': 'if_statement', 'children': ['237', '243']},{'id': '237', 'type': 'boolean_operator', 'children': ['238', '242'], 'value': 'and'},{'id': '238', 'type': 'boolean_operator', 'children': ['239', '240'], 'value': 'and'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'sort_categories'},{'id': '240', 'type': 'not_operator', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'ignore_order'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'raise_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'concatenated_string', 'children': ['249', '250']},{'id': '249', 'type': 'string', 'children': [], 'value': '"Cannot use sort_categories=True with "'},{'id': '250', 'type': 'string', 'children': [], 'value': '"ordered Categoricals"'},{'id': '251', 'type': 'if_statement', 'children': ['252', '258']},{'id': '252', 'type': 'boolean_operator', 'children': ['253', '254'], 'value': 'and'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'sort_categories'},{'id': '254', 'type': 'not_operator', 'children': ['255']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'is_monotonic_increasing'},{'id': '258', 'type': 'block', 'children': ['259', '267', '278', '285']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '266', 'type': 'argument_list', 'children': []},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'get_indexer'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '278', 'type': 'import_from_statement', 'children': ['279', '283']},{'id': '279', 'type': 'dotted_name', 'children': ['280', '281', '282']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '283', 'type': 'dotted_name', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'take_1d'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'take_1d'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292', '293']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '295', 'type': 'unary_operator', 'children': ['296'], 'value': '-'},{'id': '296', 'type': 'integer', 'children': [], 'value': '1'},{'id': '297', 'type': 'elif_clause', 'children': ['298', '310']},{'id': '298', 'type': 'boolean_operator', 'children': ['299', '300'], 'value': 'or'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'ignore_order'},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '302', 'type': 'generator_expression', 'children': ['303', '307']},{'id': '303', 'type': 'not_operator', 'children': ['304']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '307', 'type': 'for_in_clause', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '310', 'type': 'block', 'children': ['311', '332', '343', '354', '371']},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '314', 'type': 'call', 'children': ['315', '320']},{'id': '315', 'type': 'attribute', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'list_comprehension', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '325', 'type': 'for_in_clause', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '327', 'type': 'subscript', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '329', 'type': 'slice', 'children': ['330', '331']},{'id': '330', 'type': 'integer', 'children': [], 'value': '1'},{'id': '331', 'type': 'colon', 'children': []},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '335', 'type': 'call', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'cats'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '342', 'type': 'argument_list', 'children': []},{'id': '343', 'type': 'if_statement', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'sort_categories'},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '349', 'type': 'call', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '353', 'type': 'argument_list', 'children': []},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'assignment', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '357', 'type': 'list_comprehension', 'children': ['358', '368']},{'id': '358', 'type': 'call', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': '_recode_for_categories'},{'id': '360', 'type': 'argument_list', 'children': ['361', '364', '367']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '368', 'type': 'for_in_clause', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'assignment', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '378', 'type': 'argument_list', 'children': ['379']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '380', 'type': 'else_clause', 'children': ['381']},{'id': '381', 'type': 'block', 'children': ['382']},{'id': '382', 'type': 'if_statement', 'children': ['383', '392', '405']},{'id': '383', 'type': 'call', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '385', 'type': 'generator_expression', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '389', 'type': 'for_in_clause', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'to_union'},{'id': '392', 'type': 'block', 'children': ['393', '400']},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'assignment', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '396', 'type': '()', 'children': ['397']},{'id': '397', 'type': 'concatenated_string', 'children': ['398', '399']},{'id': '398', 'type': 'string', 'children': [], 'value': '"to union ordered Categoricals, "'},{'id': '399', 'type': 'string', 'children': [], 'value': '"all categories must be the same"'},{'id': '400', 'type': 'raise_statement', 'children': ['401']},{'id': '401', 'type': 'call', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '403', 'type': 'argument_list', 'children': ['404']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '405', 'type': 'else_clause', 'children': ['406']},{'id': '406', 'type': 'block', 'children': ['407']},{'id': '407', 'type': 'raise_statement', 'children': ['408']},{'id': '408', 'type': 'call', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'string', 'children': [], 'value': "'Categorical.ordered must be the same'"},{'id': '412', 'type': 'if_statement', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'ignore_order'},{'id': '414', 'type': 'block', 'children': ['415']},{'id': '415', 'type': 'expression_statement', 'children': ['416']},{'id': '416', 'type': 'assignment', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '418', 'type': 'False', 'children': []},{'id': '419', 'type': 'return_statement', 'children': ['420']},{'id': '420', 'type': 'call', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'Categorical'},{'id': '422', 'type': 'argument_list', 'children': ['423', '424', '427', '430']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '424', 'type': 'keyword_argument', 'children': ['425', '426']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '427', 'type': 'keyword_argument', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '430', 'type': 'keyword_argument', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'fastpath'},{'id': '432', 'type': 'True', 'children': []} | def union_categoricals(to_union, sort_categories=False, ignore_order=False):
from pandas import Index, Categorical, CategoricalIndex, Series
from pandas.core.arrays.categorical import _recode_for_categories
if len(to_union) == 0:
raise ValueError('No Categoricals to union')
def _maybe_unwrap(x):
if isinstance(x, (CategoricalIndex, Series)):
return x.values
elif isinstance(x, Categorical):
return x
else:
raise TypeError("all components to combine must be Categorical")
to_union = [_maybe_unwrap(x) for x in to_union]
first = to_union[0]
if not all(is_dtype_equal(other.categories.dtype, first.categories.dtype)
for other in to_union[1:]):
raise TypeError("dtype of categories must be the same")
ordered = False
if all(first.is_dtype_equal(other) for other in to_union[1:]):
categories = first.categories
ordered = first.ordered
if all(first.categories.equals(other.categories)
for other in to_union[1:]):
new_codes = np.concatenate([c.codes for c in to_union])
else:
codes = [first.codes] + [_recode_for_categories(other.codes,
other.categories,
first.categories)
for other in to_union[1:]]
new_codes = np.concatenate(codes)
if sort_categories and not ignore_order and ordered:
raise TypeError("Cannot use sort_categories=True with "
"ordered Categoricals")
if sort_categories and not categories.is_monotonic_increasing:
categories = categories.sort_values()
indexer = categories.get_indexer(first.categories)
from pandas.core.algorithms import take_1d
new_codes = take_1d(indexer, new_codes, fill_value=-1)
elif ignore_order or all(not c.ordered for c in to_union):
cats = first.categories.append([c.categories for c in to_union[1:]])
categories = Index(cats.unique())
if sort_categories:
categories = categories.sort_values()
new_codes = [_recode_for_categories(c.codes, c.categories, categories)
for c in to_union]
new_codes = np.concatenate(new_codes)
else:
if all(c.ordered for c in to_union):
msg = ("to union ordered Categoricals, "
"all categories must be the same")
raise TypeError(msg)
else:
raise TypeError('Categorical.ordered must be the same')
if ignore_order:
ordered = False
return Categorical(new_codes, categories=categories, ordered=ordered,
fastpath=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '13']},{'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': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '10', 'type': 'string', 'children': [], 'value': "'quicksort'"},{'id': '11', 'type': 'list_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16', '27', '35', '49', '63']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'nv'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'validate_argsort_with_ascending'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_values_for_argsort'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44', '47']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '47', 'type': 'dictionary_splat', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '49', 'type': 'if_statement', 'children': ['50', '52']},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '58', 'type': 'slice', 'children': ['59', '60', '61']},{'id': '59', 'type': 'colon', 'children': []},{'id': '60', 'type': 'colon', 'children': []},{'id': '61', 'type': 'unary_operator', 'children': ['62'], 'value': '-'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'result'} | def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
values = self._values_for_argsort()
result = np.argsort(values, kind=kind, **kwargs)
if not ascending:
result = result[::-1]
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'factorize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '9']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'na_sentinel'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '9', 'type': 'unary_operator', 'children': ['10'], 'value': '-'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'generic_type', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '14', 'type': 'type_parameter', 'children': ['15', '19']},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ABCExtensionArray'},{'id': '21', 'type': 'block', 'children': ['22', '29', '39', '54', '64']},{'id': '22', 'type': 'import_from_statement', 'children': ['23', '27']},{'id': '23', 'type': 'dotted_name', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '27', 'type': 'dotted_name', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_factorize_array'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'na_value'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_values_for_factorize'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '44']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'uniques'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_factorize_array'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48', '51']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'na_sentinel'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'na_sentinel'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'na_value'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'na_value'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'uniques'},{'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': '_from_factorized'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'uniques'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'expression_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'uniques'} | def factorize(
self,
na_sentinel: int = -1,
) -> Tuple[np.ndarray, ABCExtensionArray]:
from pandas.core.algorithms import _factorize_array
arr, na_value = self._values_for_factorize()
labels, uniques = _factorize_array(arr, na_sentinel=na_sentinel,
na_value=na_value)
uniques = self._from_factorized(uniques, self)
return labels, uniques |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'return_indexer'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'if_statement', 'children': ['13', '14', '50']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'return_indexer'},{'id': '14', 'type': 'block', 'children': ['15', '23', '37', '46']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_as'},{'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': 'argsort'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'if_statement', 'children': ['24', '26']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'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': '_as'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_as'},{'id': '32', 'type': 'slice', 'children': ['33', '34', '35']},{'id': '33', 'type': 'colon', 'children': []},{'id': '34', 'type': 'colon', 'children': []},{'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_as'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'expression_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_as'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52', '63', '71', '77', '121', '127', '141']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted_values'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_ndarray_values'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_get_attributes_dict'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '76', 'type': 'string', 'children': [], 'value': "'freq'"},{'id': '77', 'type': 'if_statement', 'children': ['78', '87']},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '82'], 'value': 'and'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '81', 'type': 'None', 'children': []},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'is_period_dtype'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'if_statement', 'children': ['89', '97', '105']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '95'], 'value': 'and'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '>'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'not_operator', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '*'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '103', 'type': 'unary_operator', 'children': ['104'], 'value': '-'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'elif_clause', 'children': ['106', '113']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '112'], 'value': 'and'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '<'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '*'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '119', 'type': 'unary_operator', 'children': ['120'], 'value': '-'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '125', 'type': 'string', 'children': [], 'value': "'freq'"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '127', 'type': 'if_statement', 'children': ['128', '130']},{'id': '128', 'type': 'not_operator', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'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': 'sorted_values'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sorted_values'},{'id': '136', 'type': 'slice', 'children': ['137', '138', '139']},{'id': '137', 'type': 'colon', 'children': []},{'id': '138', 'type': 'colon', 'children': []},{'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_simple_new'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sorted_values'},{'id': '148', 'type': 'dictionary_splat', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'attribs'} | def sort_values(self, return_indexer=False, ascending=True):
if return_indexer:
_as = self.argsort()
if not ascending:
_as = _as[::-1]
sorted_index = self.take(_as)
return sorted_index, _as
else:
sorted_values = np.sort(self._ndarray_values)
attribs = self._get_attributes_dict()
freq = attribs['freq']
if freq is not None and not is_period_dtype(self):
if freq.n > 0 and not ascending:
freq = freq * -1
elif freq.n < 0 and ascending:
freq = freq * -1
attribs['freq'] = freq
if not ascending:
sorted_values = sorted_values[::-1]
return self._simple_new(sorted_values, **attribs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '19', 'type': 'string', 'children': [], 'value': "'quicksort'"},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '22', 'type': 'string', 'children': [], 'value': "'last'"},{'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': 'NotImplementedError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'concatenated_string', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': '"sort_values has not been implemented "'},{'id': '30', 'type': 'string', 'children': [], 'value': '"on Panel or Panel4D objects."'} | def sort_values(self, by=None, axis=0, ascending=True, inplace=False,
kind='quicksort', na_position='last'):
raise NotImplementedError("sort_values has not been implemented "
"on Panel or Panel4D objects.") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'groupby'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'as_index'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'observed'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'dictionary_splat_pattern', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'block', 'children': ['32', '40', '54', '63']},{'id': '32', 'type': 'import_from_statement', 'children': ['33', '38']},{'id': '33', 'type': 'dotted_name', 'children': ['34', '35', '36', '37']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '38', 'type': 'dotted_name', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '40', 'type': 'if_statement', 'children': ['41', '48']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '45'], 'value': 'and'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': '"You have to supply one of \'by\' and \'level\'"'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'axis'},{'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': '_get_axis_number'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68', '71', '74', '77', '80', '83', '86', '89', '92']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'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': 'axis'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'as_index'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'as_index'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'observed'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'observed'},{'id': '92', 'type': 'dictionary_splat', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
group_keys=True, squeeze=False, observed=False, **kwargs):
from pandas.core.groupby.groupby import groupby
if level is None and by is None:
raise TypeError("You have to supply one of 'by' and 'level'")
axis = self._get_axis_number(axis)
return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
sort=sort, group_keys=group_keys, squeeze=squeeze,
observed=observed, **kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'inplace'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '16', 'type': 'string', 'children': [], 'value': "'quicksort'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '19', 'type': 'string', 'children': [], 'value': "'last'"},{'id': '20', 'type': 'block', 'children': ['21', '29', '36', '50', '78', '84', '101', '108', '113', '125', '134', '167', '179', '193', '275', '293']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'validate_bool_kwarg'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '28', 'type': 'string', 'children': [], 'value': "'inplace'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_get_axis_number'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '36', 'type': 'if_statement', 'children': ['37', '42']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '39'], 'value': 'and'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_is_cached'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'raise_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'concatenated_string', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': '"This Series is a view of some other array, to "'},{'id': '49', 'type': 'string', 'children': [], 'value': '"sort in-place you must create a copy"'},{'id': '50', 'type': 'function_definition', 'children': ['51', '52', '54']},{'id': '51', 'type': 'function_name', 'children': [], 'value': '_try_kind_sort'},{'id': '52', 'type': 'parameters', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'try_statement', 'children': ['56', '66']},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '66', 'type': 'except_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '77', 'type': 'string', 'children': [], 'value': "'quicksort'"},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_values'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sortedIdx'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '91', 'type': 'argument_list', 'children': ['92', '96']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'bad'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'isna'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '111', 'type': 'unary_operator', 'children': ['112'], 'value': '~'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'bad'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ibase'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'default_index'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'argsorted'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_try_kind_sort'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '134', 'type': 'if_statement', 'children': ['135', '139']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '139', 'type': 'block', 'children': ['140', '161']},{'id': '140', 'type': 'if_statement', 'children': ['141', '147']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '146'], 'value': '!='},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '146', 'type': 'integer', 'children': [], 'value': '1'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'raise_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'binary_operator', 'children': ['153', '156'], 'value': '%'},{'id': '153', 'type': 'concatenated_string', 'children': ['154', '155']},{'id': '154', 'type': 'string', 'children': [], 'value': "'Length of ascending (%d) must be 1 '"},{'id': '155', 'type': 'string', 'children': [], 'value': "'for Series'"},{'id': '156', 'type': '()', 'children': ['157']},{'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': 'ascending'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'if_statement', 'children': ['168', '173']},{'id': '168', 'type': 'not_operator', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'is_bool'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'raise_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'string', 'children': [], 'value': "'ascending must be boolean'"},{'id': '179', 'type': 'if_statement', 'children': ['180', '182']},{'id': '180', 'type': 'not_operator', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'argsorted'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'argsorted'},{'id': '188', 'type': 'slice', 'children': ['189', '190', '191']},{'id': '189', 'type': 'colon', 'children': []},{'id': '190', 'type': 'colon', 'children': []},{'id': '191', 'type': 'unary_operator', 'children': ['192'], 'value': '-'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'if_statement', 'children': ['194', '197', '228', '263']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '=='},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '196', 'type': 'string', 'children': [], 'value': "'last'"},{'id': '197', 'type': 'block', 'children': ['198', '206', '218']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '213']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'sortedIdx'},{'id': '210', 'type': 'slice', 'children': ['211', '212']},{'id': '211', 'type': 'colon', 'children': []},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '213', 'type': 'subscript', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'argsorted'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '225']},{'id': '220', 'type': 'subscript', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'sortedIdx'},{'id': '222', 'type': 'slice', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '224', 'type': 'colon', 'children': []},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'bad'},{'id': '228', 'type': 'elif_clause', 'children': ['229', '232']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': '=='},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '231', 'type': 'string', 'children': [], 'value': "'first'"},{'id': '232', 'type': 'block', 'children': ['233', '241', '253']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'bad'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '248']},{'id': '243', 'type': 'subscript', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'sortedIdx'},{'id': '245', 'type': 'slice', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '247', 'type': 'colon', 'children': []},{'id': '248', 'type': 'subscript', 'children': ['249', '252']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'argsorted'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '260']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'sortedIdx'},{'id': '257', 'type': 'slice', 'children': ['258', '259']},{'id': '258', 'type': 'colon', 'children': []},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'bad'},{'id': '263', 'type': 'else_clause', 'children': ['264']},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'raise_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'string', 'children': [], 'value': "'invalid na_position: {!r}'"},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': '_constructor'},{'id': '282', 'type': 'argument_list', 'children': ['283', '286']},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'sortedIdx'},{'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '288', 'type': 'subscript', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'sortedIdx'},{'id': '293', 'type': 'if_statement', 'children': ['294', '295', '303']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '295', 'type': 'block', 'children': ['296']},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '300', 'type': 'identifier', 'children': [], 'value': '_update_inplace'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '303', 'type': 'else_clause', 'children': ['304']},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'return_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '309', 'type': 'identifier', 'children': [], 'value': '__finalize__'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'self'} | def sort_values(self, axis=0, ascending=True, inplace=False,
kind='quicksort', na_position='last'):
inplace = validate_bool_kwarg(inplace, 'inplace')
self._get_axis_number(axis)
if inplace and self._is_cached:
raise ValueError("This Series is a view of some other array, to "
"sort in-place you must create a copy")
def _try_kind_sort(arr):
try:
return arr.argsort(kind=kind)
except TypeError:
return arr.argsort(kind='quicksort')
arr = self._values
sortedIdx = np.empty(len(self), dtype=np.int32)
bad = isna(arr)
good = ~bad
idx = ibase.default_index(len(self))
argsorted = _try_kind_sort(arr[good])
if is_list_like(ascending):
if len(ascending) != 1:
raise ValueError('Length of ascending (%d) must be 1 '
'for Series' % (len(ascending)))
ascending = ascending[0]
if not is_bool(ascending):
raise ValueError('ascending must be boolean')
if not ascending:
argsorted = argsorted[::-1]
if na_position == 'last':
n = good.sum()
sortedIdx[:n] = idx[good][argsorted]
sortedIdx[n:] = idx[bad]
elif na_position == 'first':
n = bad.sum()
sortedIdx[n:] = idx[good][argsorted]
sortedIdx[:n] = idx[bad]
else:
raise ValueError('invalid na_position: {!r}'.format(na_position))
result = self._constructor(arr[sortedIdx], index=self.index[sortedIdx])
if inplace:
self._update_inplace(result)
else:
return result.__finalize__(self) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '19', 'type': 'string', 'children': [], 'value': "'quicksort'"},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '22', 'type': 'string', 'children': [], 'value': "'last'"},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_remaining'},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '35', '42', '48', '163', '170', '179', '187', '198', '210']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'validate_bool_kwarg'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '34', 'type': 'string', 'children': [], 'value': "'inplace'"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'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': '_get_axis_number'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '48', 'type': 'if_statement', 'children': ['49', '52', '70', '109']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sortlevel'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '67']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort_remaining'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort_remaining'},{'id': '70', 'type': 'elif_clause', 'children': ['71', '76']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '76', 'type': 'block', 'children': ['77', '84', '92']},{'id': '77', 'type': 'import_from_statement', 'children': ['78', '82']},{'id': '78', 'type': 'dotted_name', 'children': ['79', '80', '81']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '82', 'type': 'dotted_name', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lexsort_indexer'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_sort_levels_monotonic'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'lexsort_indexer'},{'id': '97', 'type': 'argument_list', 'children': ['98', '103', '106']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_get_codes_for_sorting'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111', '118', '147']},{'id': '111', 'type': 'import_from_statement', 'children': ['112', '116']},{'id': '112', 'type': 'dotted_name', 'children': ['113', '114', '115']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '116', 'type': 'dotted_name', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'nargsort'},{'id': '118', 'type': 'if_statement', 'children': ['119', '134']},{'id': '119', 'type': '()', 'children': ['120']},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '127'], 'value': 'or'},{'id': '121', 'type': '()', 'children': ['122']},{'id': '122', 'type': 'boolean_operator', 'children': ['123', '124'], 'value': 'and'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'is_monotonic_increasing'},{'id': '127', 'type': '()', 'children': ['128']},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '131'], 'value': 'and'},{'id': '129', 'type': 'not_operator', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'is_monotonic_decreasing'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'if_statement', 'children': ['136', '137', '139']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'return_statement', 'children': []},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'nargsort'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154', '157', '160']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'na_position'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ensure_platform_int'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_sort_levels_monotonic'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'new_values'},{'id': '190', 'type': 'call', 'children': ['191', '196']},{'id': '191', 'type': 'attribute', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_values'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': '_constructor'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'new_values'},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '210', 'type': 'if_statement', 'children': ['211', '212', '220']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': '_update_inplace'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '220', 'type': 'else_clause', 'children': ['221']},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'return_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '226', 'type': 'identifier', 'children': [], 'value': '__finalize__'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'} | def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
kind='quicksort', na_position='last', sort_remaining=True):
inplace = validate_bool_kwarg(inplace, 'inplace')
self._get_axis_number(axis)
index = self.index
if level is not None:
new_index, indexer = index.sortlevel(level, ascending=ascending,
sort_remaining=sort_remaining)
elif isinstance(index, MultiIndex):
from pandas.core.sorting import lexsort_indexer
labels = index._sort_levels_monotonic()
indexer = lexsort_indexer(labels._get_codes_for_sorting(),
orders=ascending,
na_position=na_position)
else:
from pandas.core.sorting import nargsort
if ((ascending and index.is_monotonic_increasing) or
(not ascending and index.is_monotonic_decreasing)):
if inplace:
return
else:
return self.copy()
indexer = nargsort(index, kind=kind, ascending=ascending,
na_position=na_position)
indexer = ensure_platform_int(indexer)
new_index = index.take(indexer)
new_index = new_index._sort_levels_monotonic()
new_values = self._values.take(indexer)
result = self._constructor(new_values, index=new_index)
if inplace:
self._update_inplace(result)
else:
return result.__finalize__(self) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nlargest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '7', 'type': 'integer', 'children': [], 'value': '5'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '10', 'type': 'string', 'children': [], 'value': "'first'"},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '28']},{'id': '14', 'type': 'attribute', 'children': ['15', '27']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'SelectNSeries'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nlargest'},{'id': '28', 'type': 'argument_list', 'children': []} | def nlargest(self, n=5, keep='first'):
return algorithms.SelectNSeries(self, n=n, keep=keep).nlargest() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nsmallest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '7', 'type': 'integer', 'children': [], 'value': '5'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '10', 'type': 'string', 'children': [], 'value': "'first'"},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '28']},{'id': '14', 'type': 'attribute', 'children': ['15', '27']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'SelectNSeries'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nsmallest'},{'id': '28', 'type': 'argument_list', 'children': []} | def nsmallest(self, n=5, keep='first'):
return algorithms.SelectNSeries(self, n=n, keep=keep).nsmallest() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'searchsorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '8', 'type': 'string', 'children': [], 'value': '"left"'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '30']},{'id': '13', 'type': 'try_statement', 'children': ['14', '26']},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '26', 'type': 'except_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'pass_statement', 'children': []},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '42']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sorter'} | def searchsorted(self, value, side="left", sorter=None):
try:
value = self.dtype.type(value)
except ValueError:
pass
return super().searchsorted(value, side=side, sorter=sorter) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_arrays'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '17', '42', '58', '91', '99', '108', '126']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '16', 'type': 'string', 'children': [], 'value': '"Input must be a list / sequence of array-likes."'},{'id': '17', 'type': 'if_statement', 'children': ['18', '23', '29']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'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': 'TypeError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '29', 'type': 'elif_clause', 'children': ['30', '34']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'is_iterator'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'if_statement', 'children': ['47', '52']},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'raise_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '68']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '85']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '77'], 'value': '!='},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '-'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'raise_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': "'all arrays must be same length'"},{'id': '91', 'type': 'import_from_statement', 'children': ['92', '97']},{'id': '92', 'type': 'dotted_name', 'children': ['93', '94', '95', '96']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'categorical'},{'id': '97', 'type': 'dotted_name', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_factorize_from_iterables'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '104']},{'id': '101', 'type': 'pattern_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_factorize_from_iterables'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '108', 'type': 'if_statement', 'children': ['109', '112']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '111', 'type': 'None', 'children': []},{'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': 'names'},{'id': '116', 'type': 'list_comprehension', 'children': ['117', '123']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '121', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '122', 'type': 'None', 'children': []},{'id': '123', 'type': 'for_in_clause', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '129', 'type': 'argument_list', 'children': ['130', '133', '136', '139', '142']},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '144', 'type': 'False', 'children': []} | def from_arrays(cls, arrays, sortorder=None, names=None):
error_msg = "Input must be a list / sequence of array-likes."
if not is_list_like(arrays):
raise TypeError(error_msg)
elif is_iterator(arrays):
arrays = list(arrays)
for array in arrays:
if not is_list_like(array):
raise TypeError(error_msg)
for i in range(1, len(arrays)):
if len(arrays[i]) != len(arrays[i - 1]):
raise ValueError('all arrays must be same length')
from pandas.core.arrays.categorical import _factorize_from_iterables
codes, levels = _factorize_from_iterables(arrays)
if names is None:
names = [getattr(arr, "name", None) for arr in arrays]
return MultiIndex(levels=levels, codes=codes, sortorder=sortorder,
names=names, verify_integrity=False) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_tuples'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '38', '139']},{'id': '13', 'type': 'if_statement', 'children': ['14', '19', '25']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'Input must be a list / sequence of tuple-likes.'"},{'id': '25', 'type': 'elif_clause', 'children': ['26', '30']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'is_iterator'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'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': 'tuples'},{'id': '38', 'type': 'if_statement', 'children': ['39', '45', '70', '108', '129']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '=='},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'block', 'children': ['46', '60']},{'id': '46', 'type': 'if_statement', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'block', 'children': ['51', '55']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '54', 'type': 'string', 'children': [], 'value': "'Cannot infer number of levels from empty list'"},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '66'], 'value': '*'},{'id': '64', 'type': 'list', 'children': ['65'], 'value': '[[]]'},{'id': '65', 'type': 'list', 'children': [], 'value': '[]'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '70', 'type': 'elif_clause', 'children': ['71', '80']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '75', 'type': 'tuple', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '80', 'type': 'block', 'children': ['81', '94']},{'id': '81', 'type': 'if_statement', 'children': ['82', '87']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_values'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'attribute', 'children': ['101', '107']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'tuples_to_object_array'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '108', 'type': 'elif_clause', 'children': ['109', '114']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'attribute', 'children': ['122', '128']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'to_object_array_tuples'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'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': 'arrays'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'lzip'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'list_splat', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'from_arrays'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146', '149']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'names'} | def from_tuples(cls, tuples, sortorder=None, names=None):
if not is_list_like(tuples):
raise TypeError('Input must be a list / sequence of tuple-likes.')
elif is_iterator(tuples):
tuples = list(tuples)
if len(tuples) == 0:
if names is None:
msg = 'Cannot infer number of levels from empty list'
raise TypeError(msg)
arrays = [[]] * len(names)
elif isinstance(tuples, (np.ndarray, Index)):
if isinstance(tuples, Index):
tuples = tuples._values
arrays = list(lib.tuples_to_object_array(tuples).T)
elif isinstance(tuples, list):
arrays = list(lib.to_object_array_tuples(tuples).T)
else:
arrays = lzip(*tuples)
return MultiIndex.from_arrays(arrays, sortorder=sortorder, names=names) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_product'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '21', '29', '54', '63', '70']},{'id': '13', 'type': 'import_from_statement', 'children': ['14', '19']},{'id': '14', 'type': 'dotted_name', 'children': ['15', '16', '17', '18']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'categorical'},{'id': '19', 'type': 'dotted_name', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_factorize_from_iterables'},{'id': '21', 'type': 'import_from_statement', 'children': ['22', '27']},{'id': '22', 'type': 'dotted_name', 'children': ['23', '24', '25', '26']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '27', 'type': 'dotted_name', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cartesian_product'},{'id': '29', 'type': 'if_statement', 'children': ['30', '35', '41']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'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': 'TypeError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': '"Input must be a list / sequence of iterables."'},{'id': '41', 'type': 'elif_clause', 'children': ['42', '46']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'is_iterator'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_factorize_from_iterables'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'iterables'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'cartesian_product'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '76', '79']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'names'} | def from_product(cls, iterables, sortorder=None, names=None):
from pandas.core.arrays.categorical import _factorize_from_iterables
from pandas.core.reshape.util import cartesian_product
if not is_list_like(iterables):
raise TypeError("Input must be a list / sequence of iterables.")
elif is_iterator(iterables):
iterables = list(iterables)
codes, levels = _factorize_from_iterables(iterables)
codes = cartesian_product(codes)
return MultiIndex(levels, codes, sortorder=sortorder, names=names) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_frame'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '26', '40', '49']},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ABCDataFrame'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"Input must be a DataFrame"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '31']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lzip'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'list_splat', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '43', 'type': 'conditional_expression', 'children': ['44', '45', '48'], 'value': 'if'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'from_arrays'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '59']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'names'} | def from_frame(cls, df, sortorder=None, names=None):
if not isinstance(df, ABCDataFrame):
raise TypeError("Input must be a DataFrame")
column_names, columns = lzip(*df.iteritems())
names = column_names if names is None else names
return cls.from_arrays(columns, sortorder=sortorder, names=names) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortlevel'},{'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': 'level'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'sort_remaining'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '22', '36', '49', '53', '224', '231', '246', '271']},{'id': '15', 'type': 'import_from_statement', 'children': ['16', '20']},{'id': '16', 'type': 'dotted_name', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '20', 'type': 'dotted_name', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'indexer_from_factorized'},{'id': '22', 'type': 'if_statement', 'children': ['23', '30']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '27', 'type': 'tuple', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '34', 'type': 'list', 'children': ['35'], 'value': '[level]'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '46']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_get_level_number'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'if_statement', 'children': ['54', '59', '102']},{'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': 'ascending'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '59', 'type': 'block', 'children': ['60', '77', '84']},{'id': '60', 'type': 'if_statement', 'children': ['61', '71']},{'id': '61', 'type': 'not_operator', 'children': ['62']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '67'], 'value': '=='},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'raise_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': '"level must have same length as ascending"'},{'id': '77', 'type': 'import_from_statement', 'children': ['78', '82']},{'id': '78', 'type': 'dotted_name', 'children': ['79', '80', '81']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '82', 'type': 'dotted_name', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lexsort_indexer'},{'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', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'lexsort_indexer'},{'id': '89', 'type': 'argument_list', 'children': ['90', '99']},{'id': '90', 'type': 'list_comprehension', 'children': ['91', '96']},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '96', 'type': 'for_in_clause', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '102', 'type': 'else_clause', 'children': ['103']},{'id': '103', 'type': 'block', 'children': ['104', '113', '122', '134', '146', '170', '199', '210']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'levshape'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'primary'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '127', 'type': 'generator_expression', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'primshp'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '139', 'type': 'generator_expression', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '143', 'type': 'for_in_clause', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '146', 'type': 'for_statement', 'children': ['147', '148', '155']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '154', 'type': 'True', 'children': []},{'id': '155', 'type': 'block', 'children': ['156', '163']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'lev'},{'id': '170', 'type': 'if_statement', 'children': ['171', '172', '191']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'sort_remaining'},{'id': '172', 'type': 'block', 'children': ['173', '182']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'augmented_assignment', 'children': ['175', '176'], 'value': '+='},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'primary'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'primary'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'augmented_assignment', 'children': ['184', '185'], 'value': '+='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'primshp'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '+'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'primshp'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '198', 'type': 'integer', 'children': [], 'value': '0'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'indexer_from_factorized'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'primary'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'primshp'},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '209', 'type': 'False', 'children': []},{'id': '210', 'type': 'if_statement', 'children': ['211', '213']},{'id': '211', 'type': 'not_operator', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '219', 'type': 'slice', 'children': ['220', '221', '222']},{'id': '220', 'type': 'colon', 'children': []},{'id': '221', 'type': 'colon', 'children': []},{'id': '222', 'type': 'unary_operator', 'children': ['223'], 'value': '-'},{'id': '223', 'type': 'integer', 'children': [], 'value': '1'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ensure_platform_int'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '234', 'type': 'list_comprehension', 'children': ['235', '241']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'level_codes'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'indexer'},{'id': '241', 'type': 'for_in_clause', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'level_codes'},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '251', 'type': 'argument_list', 'children': ['252', '255', '260', '265', '268']},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'new_codes'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'},{'id': '270', 'type': 'False', 'children': []},{'id': '271', 'type': 'return_statement', 'children': ['272']},{'id': '272', 'type': 'expression_list', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'new_index'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'indexer'} | def sortlevel(self, level=0, ascending=True, sort_remaining=True):
from pandas.core.sorting import indexer_from_factorized
if isinstance(level, (str, int)):
level = [level]
level = [self._get_level_number(lev) for lev in level]
sortorder = None
if isinstance(ascending, list):
if not len(level) == len(ascending):
raise ValueError("level must have same length as ascending")
from pandas.core.sorting import lexsort_indexer
indexer = lexsort_indexer([self.codes[lev] for lev in level],
orders=ascending)
else:
codes = list(self.codes)
shape = list(self.levshape)
primary = tuple(codes[lev] for lev in level)
primshp = tuple(shape[lev] for lev in level)
for lev in sorted(level, reverse=True):
codes.pop(lev)
shape.pop(lev)
if sort_remaining:
primary += primary + tuple(codes)
primshp += primshp + tuple(shape)
else:
sortorder = level[0]
indexer = indexer_from_factorized(primary, primshp,
compress=False)
if not ascending:
indexer = indexer[::-1]
indexer = ensure_platform_int(indexer)
new_codes = [level_codes.take(indexer) for level_codes in self.codes]
new_index = MultiIndex(codes=new_codes, levels=self.levels,
names=self.names, sortorder=sortorder,
verify_integrity=False)
return new_index, indexer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.