Search is not available for this dataset
id
int64
0
10.8M
vector
listlengths
1.54k
1.54k
ast_depth
int64
3
164
ast_data
stringlengths
297
510k
full_path
stringlengths
0
319
code
stringlengths
60
56.5k
12,501
[ 0.038929589092731476, -0.013665961101651192, 0.06456119567155838, -0.047837208956480026, 0.012891937978565693, -0.02243400178849697, 0.026139164343476295, 0.010055964812636375, 0.01924908347427845, 0.01680012419819832, 0.0035941351670771837, -0.034057047218084335, -0.020441841334104538, 0....
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "inst", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mgtest"}}], "func": {"_type": "Name", "_fields": {"id": "Application", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "a.key1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "a.key2"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "value2"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_config", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertTrue", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "b"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_config", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertFalse", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "c"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_config", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertFalse", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "d"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_config", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertFalse", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test03", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test03(self): app = Application(self.inst, "mgtest") self.assertEqual(app.config.get("a.key1"), None) self.assertEqual(app.config.get("a.key2"), "value2") self.assertTrue("a" in app.config._config) self.assertFalse("b" in app.config._config) self.assertFalse("c" in app.config._config) self.assertFalse("d" in app.config._config)
12,502
[ 0.04578680545091629, -0.002353658201172948, 0.0626896470785141, -0.0646284967660904, 0.006257778964936733, -0.012378843501210213, 0.03743481636047363, 0.025503400713205338, 0.0189411211758852, 0.011651773005723953, 0.026895398274064064, -0.0431768074631691, -0.02539154328405857, 0.00533185...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "inst", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mgtest"}}], "func": {"_type": "Name", "_fields": {"id": "Application", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "a.key1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "value1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "a.key2"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "value2"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "a.key1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "store", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "a.key1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "a.key2"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "config", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "value2"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test02", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test02(self): app = Application(self.inst, "mgtest") self.assertEqual(app.config.get("a.key1"), "value1") app.config.set("a.key2", "value2") app.config.delete("a.key1") app.config.store() self.assertEqual(app.config.get("a.key1"), None) self.assertEqual(app.config.get("a.key2"), "value2")
12,503
[ 0.01869290880858898, -0.018558524549007416, 0.06810615956783295, 0.014500107616186142, -0.01474200002849102, -0.04561016336083412, 0.01920357160270214, 0.022724449634552002, 0.0019636962097138166, 0.021703125908970833, 0.0026742552872747183, -0.0065680514089763165, -0.017631269991397858, -...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "subjects"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_index", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "/media/james/ext4data1/current/projects/pfizer/outer_test_results.csv"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "read_csv", "value": {"_type": "Name", "_fields": {"id": "pd", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "otr", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "scores"}}, "value": {"_type": "Name", "_fields": {"id": "otr", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 100}}}}, "targets": [{"_type": "Name", "_fields": {"id": "acc", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "index", "value": {"_type": "Name", "_fields": {"id": "otr", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 10000}}, "targets": [{"_type": "Name", "_fields": {"id": "runs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "acc", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "choice", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "replace", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "sample", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sample", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "sum", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sample", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sample_mean", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sample_mean", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "runs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "sum", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "dist_mean", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "GeneratorExp", "_fields": {"elt": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 52.77}}]}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "sum", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "runs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "p_value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "{} runs, {} samples per run"}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dist_mean", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "distribution mean: {}%"}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "p_value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "p-value: {}"}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "samples per run"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "runs"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "distribution mean"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "p-value"}}], "values": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 10000}}, {"_type": "Name", "_fields": {"id": "dist_mean", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "p_value", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "bootstrap_results", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bootstrap_results", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "from_dict", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "DataFrame", "value": {"_type": "Name", "_fields": {"id": "pd", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "orient", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "index"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "bdf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 101}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "digitize", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "binner", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 52.77}}, {"_type": "Constant", "_fields": {"kind": null, "value": 52.77}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "binner", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mode", "value": {"_type": "Name", "_fields": {"id": "statistics", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "binner", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}]}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-r"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "plot", "value": {"_type": "Name", "_fields": {"id": "plt", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "lw", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "distribution", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hist", "value": {"_type": "Name", "_fields": {"id": "plt", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "bins", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 101}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "show", "value": {"_type": "Name", "_fields": {"id": "plt", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "to_csv", "value": {"_type": "Name", "_fields": {"id": "bdf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "path_or_buf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/media/james/ext4data1/current/projects/pfizer/bootstrap_results.csv"}}}}]}}}}, {"_type": "Return", "_fields": {"value": null}}], "name": "Bill", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def Bill(): otr=pd.read_csv('/media/james/ext4data1/current/projects/pfizer/outer_test_results.csv').set_index('subjects') #Per subject accuracy acc= otr['scores']*100 n= len(otr.index) runs= 10000 distribution= [] for i in range(runs): sample= np.random.choice(acc, n,replace=True) sample_mean= sum(sample)/len(sample) distribution.append(sample_mean) dist_mean= sum(distribution)/len(distribution) p_value= sum(i<=52.77 for i in distribution)/runs print('{} runs, {} samples per run'.format(len(distribution), n)) print('distribution mean: {}%'.format(dist_mean)) print('p-value: {}'.format(p_value)) bootstrap_results= {'samples per run': n, 'runs': 10000, 'distribution mean': dist_mean, 'p-value': p_value } bdf= pd.DataFrame.from_dict(bootstrap_results, orient='index') binner=np.digitize(distribution, np.array(range(0,101))) plt.plot([52.77,52.77],[0,list(binner).count(statistics.mode(binner))],'-r',lw=2) plt.hist(distribution, bins=list(range(0,101))) plt.show() bdf.to_csv(path_or_buf='/media/james/ext4data1/current/projects/pfizer/bootstrap_results.csv') return
12,504
[ -0.01969968155026436, 0.006501591298729181, 0.08392203599214554, -0.05011933296918869, 0.0029392901342362165, -0.016024263575673103, -0.0013617492513731122, 0.041571203619241714, -0.009564438834786415, 0.013636634685099125, 0.007796340622007847, -0.06131264939904213, -0.006212709005922079, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "inst", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mgtest"}}], "func": {"_type": "Name", "_fields": {"id": "Application", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "mg.test.testcore.TestJoin"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "load", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "modules", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.empty"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.single"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "single"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.prio1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "prio2"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.prio2"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "prio1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.prio3"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "prio1"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.filter1"}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.filter2"}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 4}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.filter3"}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 14}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "join.immed"}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hooks", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "immed"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test09", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test09(self): app = Application(self.inst, "mgtest") app.modules.load(["mg.test.testcore.TestJoin"]) self.assertEqual(app.hooks.call("join.empty"), None) self.assertEqual(app.hooks.call("join.single"), "single") self.assertEqual(app.hooks.call("join.prio1"), "prio2") self.assertEqual(app.hooks.call("join.prio2"), "prio1") self.assertEqual(app.hooks.call("join.prio3"), "prio1") self.assertEqual(app.hooks.call("join.filter1", 2), 2) self.assertEqual(app.hooks.call("join.filter2", 2), 4) self.assertEqual(app.hooks.call("join.filter3", 2), 14) self.assertEqual(app.hooks.call("join.immed", 2), "immed")
12,505
[ 0.024872053414583206, -0.03463296219706535, 0.044602662324905396, -0.021935949102044106, -0.024467522278428078, 0.04264526069164276, -0.049926795065402985, -0.012455600313842297, 0.02810829132795334, 0.04092274606227875, -0.016311682760715485, -0.021126890555024147, -0.01710769161581993, -...
14
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 4}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 35}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 4}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 30}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 8}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 5}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 63}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 70}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 15}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 8}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 6}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 231}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 6}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 315}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 4}}}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 105}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 16}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 10}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 11}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 10}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 11}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 10}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 11}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 4}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "roots", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Dict", "_fields": {"keys": [{"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 7}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 35}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 30}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 7}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 35}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 30}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 7}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 35}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 30}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 7}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 35}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 30}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Half", "value": {"_type": "Name", "_fields": {"id": "S", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}]}}}}], "name": "test_legendre", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_legendre(): assert legendre(0, x) == 1 assert legendre(1, x) == x assert legendre(2, x) == ((3*x**2-1)/2).expand() assert legendre(3, x) == ((5*x**3-3*x)/2).expand() assert legendre(4, x) == ((35*x**4-30*x**2+3)/8).expand() assert legendre(5, x) == ((63*x**5-70*x**3+15*x)/8).expand() assert legendre(6, x) == ((231*x**6-315*x**4+105*x**2-5)/16).expand() assert legendre(10, -1) == 1 assert legendre(11, -1) == -1 assert legendre(10, 1) == 1 assert legendre(11, 1) == 1 assert legendre(10, 0) != 0 assert legendre(11, 0) == 0 assert roots(legendre(4,x), x) == { (Rational(3, 7) - Rational(2, 35)*30**S.Half)**S.Half: 1, -(Rational(3, 7) - Rational(2, 35)*30**S.Half)**S.Half: 1, (Rational(3, 7) + Rational(2, 35)*30**S.Half)**S.Half: 1, -(Rational(3, 7) + Rational(2, 35)*30**S.Half)**S.Half: 1, }
12,506
[ 0.015421483665704727, 0.04209400713443756, 0.10036567598581314, -0.019442984834313393, -0.032149095088243484, -0.02213544398546219, 0.026374632492661476, -0.007808128837496042, -0.03246989846229553, 0.05907367914915085, 0.01093596313148737, 0.018881579861044884, -0.014779876917600632, 0.00...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "PWD"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "environ", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pwd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "nacl-chrome"}}, "comparators": [{"_type": "Name", "_fields": {"id": "pwd", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "is_integration_bot", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "platform", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "win32"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "cygwin"}}]}}]}}, {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "64"}}, "comparators": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "PROCESSOR_ARCHITECTURE"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "environ", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "64"}}, "comparators": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "PROCESSOR_ARCHITEW6432"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "environ", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "is_win64", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tests_to_disable", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "run_ppapi_ppb_image_data_browser_test"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "tests_to_disable", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "run_ppapi_crash_browser_test"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "tests_to_disable", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "platform", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "darwin"}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "run_inbrowser_test_runner"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "tests_to_disable", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "platform", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "win32"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "cygwin"}}]}}]}}, "orelse": []}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "is_integration_bot", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "__file__", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "abspath", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dirname", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "script_dir", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "script_dir", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "buildbot_chrome_nacl_stage.py"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "nacl_integration_script", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "executable", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "nacl_integration_script", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--disable_glibc"}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "--disable_tests=%s"}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tests_to_disable", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": ","}}}}, "keywords": []}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "cmd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "cmd", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Running %s\n"}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cmd", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}}}, "keywords": []}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stdout", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "flush", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stdout", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cmd", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "subprocess", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "Main", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def Main(args): pwd = os.environ.get('PWD', '') is_integration_bot = 'nacl-chrome' in pwd # This environment variable check mimics what # buildbot_chrome_nacl_stage.py does. is_win64 = (sys.platform in ('win32', 'cygwin') and ('64' in os.environ.get('PROCESSOR_ARCHITECTURE', '') or '64' in os.environ.get('PROCESSOR_ARCHITEW6432', ''))) # On the main Chrome waterfall, we may need to control where the tests are # run. # If there is serious skew in the PPAPI interface that causes all of # the NaCl integration tests to fail, you can uncomment the # following block. (Make sure you comment it out when the issues # are resolved.) *However*, it is much preferred to add tests to # the 'tests_to_disable' list below. #if not is_integration_bot: # return tests_to_disable = [] # In general, you should disable tests inside this conditional. This turns # them off on the main Chrome waterfall, but not on NaCl's integration bots. # This makes it easier to see when things have been fixed NaCl side. if not is_integration_bot: # http://code.google.com/p/nativeclient/issues/detail?id=2511 tests_to_disable.append('run_ppapi_ppb_image_data_browser_test') if sys.platform == 'darwin': # TODO(mseaborn) fix # http://code.google.com/p/nativeclient/issues/detail?id=1835 tests_to_disable.append('run_ppapi_crash_browser_test') if sys.platform in ('win32', 'cygwin'): # This one is only failing for nacl_glibc on x64 Windows # but it is not clear how to disable only that limited case. # See http://crbug.com/132395 tests_to_disable.append('run_inbrowser_test_runner') script_dir = os.path.dirname(os.path.abspath(__file__)) nacl_integration_script = os.path.join(script_dir, 'buildbot_chrome_nacl_stage.py') cmd = [sys.executable, nacl_integration_script, # TODO(ncbray) re-enable. # https://code.google.com/p/chromium/issues/detail?id=133568 '--disable_glibc', '--disable_tests=%s' % ','.join(tests_to_disable)] cmd += args sys.stdout.write('Running %s\n' % ' '.join(cmd)) sys.stdout.flush() return subprocess.call(cmd)
12,507
[ 0.04221566393971443, 0.0008752808789722621, 0.0308125838637352, -0.019422980025410652, -0.010291079059243202, 0.028116818517446518, -0.003101813606917858, -0.028602056205272675, 0.018304238095879555, 0.013135110028088093, 0.0009982751216739416, -0.02405969426035881, 0.020150836557149887, 0...
16
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "assoc_legendre", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "Rational", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "Q", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "Q", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Name", "_fields": {"id": "Q", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "Q", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "Q", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 15}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "Q", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 15}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "Q", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 24}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 6}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 720}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 120}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Plm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 12}}}}]}}}}], "name": "test_assoc_legendre", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_assoc_legendre(): Plm=assoc_legendre Q=(1-x**2)**Rational(1,2) assert Plm(0, 0, x) == 1 assert Plm(1, 0, x) == x assert Plm(1, 1, x) == -Q assert Plm(2, 0, x) == (3*x**2-1)/2 assert Plm(2, 1, x) == -3*x*Q assert Plm(2, 2, x) == 3*Q**2 assert Plm(3, 0, x) == (5*x**3-3*x)/2 assert Plm(3, 1, x).expand() == (( 3*(1-5*x**2)/2 ).expand() * Q).expand() assert Plm(3, 2, x) == 15*x * Q**2 assert Plm(3, 3, x) == -15 * Q**3 # negative m assert Plm(1,-1, x) == -Plm(1, 1, x)/2 assert Plm(2,-2, x) == Plm(2, 2, x)/24 assert Plm(2,-1, x) == -Plm(2, 1, x)/6 assert Plm(3,-3, x) == -Plm(3, 3, x)/720 assert Plm(3,-2, x) == Plm(3, 2, x)/120 assert Plm(3,-1, x) == -Plm(3, 1, x)/12
12,508
[ 0.01928139291703701, -0.05860237032175064, 0.022535784170031548, 0.024215469136834145, 0.015887027606368065, 0.032380610704422, 0.008672544732689857, 0.003260223427787423, -0.004272117279469967, 0.03338375315070152, 0.03326711058616638, -0.019059767946600914, -0.03977589309215546, -0.01136...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 4}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, {"_type": "For", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "k", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevt_root", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "z", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "z", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "k", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 4}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "k", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevu_root", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "z", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "z", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "chebyshevu", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "k", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 4}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_chebyshev", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_chebyshev(): assert chebyshevt(0, x) == 1 assert chebyshevt(1, x) == x assert chebyshevt(2, x) == 2*x**2-1 assert chebyshevt(3, x) == 4*x**3-3*x for n in range(1, 4): for k in range(n): z = chebyshevt_root(n, k) assert chebyshevt(n, z) == 0 for n in range(1, 4): for k in range(n): z = chebyshevu_root(n, k) assert chebyshevu(n, z) == 0
12,509
[ -0.033907871693372726, 0.01728336699306965, -0.01623624563217163, -0.03494322672486305, -0.03588445857167244, -0.043343719094991684, -0.014765571802854538, -0.0022780748549848795, -0.004353196360170841, 0.027978111058473587, 0.02713100239634514, -0.008400492370128632, 0.035860925912857056, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "log_file", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "regex", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "readlines", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "log_file", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "file", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "log_list", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "regex", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "search", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "group", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": null}}], "finalbody": []}}], "iter": {"_type": "Name", "_fields": {"id": "log_list", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "get_amount_list", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_amount_list(log_file, regex): log_list = file(log_file).readlines() amount_list = [] for line in log_list: m = re.search(regex, line) try: amount_list.append(m.group()) except: # Example: # 78.174.192.97 - - [03/Apr/2010:19:55:49 +0300] "GET /media/podcasts/oi_podcast_E0/.ogg HTTP/1.1" 404 196 # 78.174.241.181 - - [10/Apr/2010:19:13:30 +0300] "GET /media/podcasts/oi_podcast_E0*.ogg HTTP/1.1" 404 198 pass return amount_list
12,510
[ 0.009908324107527733, -0.02611573226749897, -0.005510146263986826, -0.01535634882748127, 0.001433445606380701, 0.014461804181337357, -0.040950264781713486, -0.04785813391208649, 0.06063024327158928, 0.03108542412519455, 0.030986031517386436, -0.028724821284413338, -0.01658634841442108, -0....
14
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "alpha"}}], "func": {"_type": "Name", "_fields": {"id": "Symbol", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 6}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "alpha", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 6}}}}}}}}, "keywords": []}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 6}}}}}}]}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expand", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_l", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "laguerre_poly", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 10}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_laguerre", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_laguerre(): alpha = Symbol("alpha") # generalized Laguerre polynomials: assert laguerre_l(0, alpha, x) == 1 assert laguerre_l(1, alpha, x) == -x + alpha + 1 assert laguerre_l(2, alpha, x).expand() == (x**2/2 - (alpha+2)*x + (alpha+2)*(alpha+1)/2).expand() assert laguerre_l(3, alpha, x).expand() == (-x**3/6 + (alpha+3)*x**2/2 - (alpha+2)*(alpha+3)*x/2 + (alpha+1)*(alpha+2)*(alpha+3)/6).expand() # Laguerre polynomials: assert laguerre_l(0, 0, x) == 1 assert laguerre_l(1, 0, x) == 1 - x assert laguerre_l(2, 0, x).expand() == 1 - 2*x + x**2/2 assert laguerre_l(3, 0, x).expand() == 1 - 3*x + 3*x**2/2 - x**3/6 # Test the lowest 10 polynomials with laguerre_poly, to make sure that it # works: for i in range(10): assert laguerre_l(i, 0, x).expand() == laguerre_poly(i, x)
12,511
[ 0.01393149048089981, 0.00946103036403656, -0.01991274394094944, -0.05681571736931801, -0.02506430074572563, -0.0027150928508490324, -0.004823391791433096, 0.016271980479359627, -0.015491818077862263, -0.01483548991382122, 0.04425879940390587, -0.011052316054701805, -0.006389910355210304, -...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "(?<=oi_podcast_E)\\w+.(mp3|ogg)"}}, "targets": [{"_type": "Name", "_fields": {"id": "regex_podcast", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "(?<=oi_say)\\w+_(buyuk|kucuk).pdf"}}, "targets": [{"_type": "Name", "_fields": {"id": "regex_edergi", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "LOGPODCAST", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "regex_podcast", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_amount_list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "0%s"}}, "right": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 10}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s.ogg"}}, "right": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "amount_ogg", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s.mp3"}}, "right": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "amount_mp3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "podcast %s (toplam: %s)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "amount_ogg", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "amount_mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " ogg: %s"}}, "right": {"_type": "Name", "_fields": {"id": "amount_ogg", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " mp3: %s\n"}}, "right": {"_type": "Name", "_fields": {"id": "amount_mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "COUNT_OF_PODCAST", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "LOGEDERGI", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "regex_edergi", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_amount_list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "0%s"}}, "right": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 10}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s_buyuk.pdf"}}, "right": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "amount_buyuk", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s_kucuk.pdf"}}, "right": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "amount_list", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "amount_kucuk", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "edergi %s (toplam: %s)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "amount_buyuk", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "amount_kucuk", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " buyuk: %s"}}, "right": {"_type": "Name", "_fields": {"id": "amount_buyuk", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " küçük: %s\n"}}, "right": {"_type": "Name", "_fields": {"id": "amount_kucuk", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "COUNT_OF_JOURNAL", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "episode", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "print_output", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def print_output(): regex_podcast = '(?<=oi_podcast_E)\w+.(mp3|ogg)' regex_edergi = '(?<=oi_say)\w+_(buyuk|kucuk).pdf' # podcasts amount_list = get_amount_list(LOGPODCAST, regex_podcast) for episode in range(1, COUNT_OF_PODCAST + 1): if episode < 10: # dirty hacking episode = "0%s" % episode amount_ogg = amount_list.count('%s.ogg' % episode) amount_mp3 = amount_list.count('%s.mp3' % episode) print("podcast %s (toplam: %s)" % (episode, (amount_ogg + amount_mp3))) print(" ogg: %s" % amount_ogg) print(" mp3: %s\n" % amount_mp3) # edergis amount_list = get_amount_list(LOGEDERGI, regex_edergi) for episode in range(1, COUNT_OF_JOURNAL + 1): if episode < 10: # still dirty hacking episode = "0%s" % episode amount_buyuk = amount_list.count('%s_buyuk.pdf' % episode) amount_kucuk = amount_list.count('%s_kucuk.pdf' % episode) print("edergi %s (toplam: %s)" % (episode, (amount_buyuk + amount_kucuk))) print(" buyuk: %s" % amount_buyuk) print(" küçük: %s\n" % amount_kucuk)
12,512
[ 0.046275872737169266, 0.008589859120547771, 0.03237716108560562, -0.04875941202044487, -0.0036341713275760412, -0.0037851203233003616, 0.022602494806051254, 0.002304110210388899, 0.00007405051292153075, -0.020039208233356476, 0.00710315303876996, 0.00526328245177865, 0.008743656799197197, ...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "input_lines", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "source", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "line_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "input_lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "source", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "internal padding after "}}, "right": {"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "offset", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "input_lines", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "line_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "input_lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "source", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "internal padding before "}}, "right": {"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "offset", "value": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "line_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "input_lines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "StringList", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "input_lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "insert_input", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def insert_input(self, input_lines, source): self.input_lines.insert(self.line_offset + 1, '', source='internal padding after '+source, offset=len(input_lines)) self.input_lines.insert(self.line_offset + 1, '', source='internal padding before '+source, offset=-1) self.input_lines.insert(self.line_offset + 2, StringList(input_lines, source))
12,513
[ 0.06979983299970627, -0.016689926385879517, -0.043013788759708405, -0.0499567985534668, 0.03284577280282974, -0.03149003908038139, -0.03132570534944534, 0.01038370095193386, 0.0074668158777058125, 0.03906983137130737, 0.03588590770959854, -0.026744963601231575, 0.03444800525903702, -0.0384...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "i", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "cannot handle slice with stride"}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "step", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}]}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "upper": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__class__", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "items", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "upper": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "parent_offset", "value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}]}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "slice", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}]}}], "name": "__getitem__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __getitem__(self, i): if isinstance(i, slice): assert i.step in (None, 1), 'cannot handle slice with stride' return self.__class__(self.data[i.start:i.stop], items=self.items[i.start:i.stop], parent=self, parent_offset=i.start or 0) else: return self.data[i]
12,514
[ 0.05017910897731781, -0.01186092384159565, -0.0625108852982521, -0.029282357543706894, -0.01326226256787777, -0.03829576447606087, 0.009999947622418404, -0.030089527368545532, -0.010986489243805408, 0.03995494544506073, 0.07035837322473526, -0.00043966976227238774, 0.012993205338716507, -0...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "i", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "item", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "cannot handle slice with stride"}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "step", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}]}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "assigning non-ViewList to ViewList slice"}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ViewList", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "upper": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "upper": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "data mismatch"}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "upper": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "slice", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}]}}], "name": "__setitem__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __setitem__(self, i, item): if isinstance(i, slice): assert i.step in (None, 1), 'cannot handle slice with stride' if not isinstance(item, ViewList): raise TypeError('assigning non-ViewList to ViewList slice') self.data[i.start:i.stop] = item.data self.items[i.start:i.stop] = item.items assert len(self.data) == len(self.items), 'data mismatch' if self.parent: self.parent[(i.start or 0) + self.parent_offset : (i.stop or len(self)) + self.parent_offset] = item else: self.data[i] = item if self.parent: self.parent[i + self.parent_offset] = item
12,515
[ 0.053691960871219635, 0.01048671081662178, 0.0235762782394886, -0.0074590095318853855, -0.04332356154918671, -0.017951099202036858, -0.012820676900446415, -0.024845438078045845, -0.02027430757880211, 0.01354130171239376, 0.015122375451028347, -0.0072976755909621716, 0.021532714366912842, -...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "item", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "source", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "offset", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extend", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "offset", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "offset", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}]}}], "name": "append", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def append(self, item, source=None, offset=0): if source is None: self.extend(item) else: if self.parent: self.parent.insert(len(self.data) + self.parent_offset, item, source, offset) self.data.append(item) self.items.append((source, offset))
12,516
[ 0.09238100051879883, 0.022457392886281013, -0.011944781057536602, -0.04397604987025261, -0.001452479395084083, 0.008791599422693253, -0.0009725820273160934, 0.012131324969232082, -0.01694534160196781, 0.03827144205570221, 0.057046107947826385, -0.02038736455142498, 0.01143930945545435, -0....
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "i", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Delete", "_fields": {"targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Del", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, {"_type": "Delete", "_fields": {"targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Del", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "Delete", "_fields": {"targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Del", "_fields": {}}, "slice": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "cannot handle slice with stride"}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "step", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}}}, {"_type": "Delete", "_fields": {"targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Del", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "upper": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, {"_type": "Delete", "_fields": {"targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Del", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "upper": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "Delete", "_fields": {"targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Del", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "upper": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop", "value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "__delitem__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __delitem__(self, i): try: del self.data[i] del self.items[i] if self.parent: del self.parent[i + self.parent_offset] except TypeError: assert i.step is None, 'cannot handle slice with stride' del self.data[i.start:i.stop] del self.items[i.start:i.stop] if self.parent: del self.parent[(i.start or 0) + self.parent_offset : (i.stop or len(self)) + self.parent_offset]
12,517
[ 0.007611389271914959, 0.010182804428040981, 0.003015322843566537, -0.0052159130573272705, -0.003562086960300803, -0.02431746944785118, 0.012039637193083763, -0.036378759890794754, -0.0010603704722598195, 0.04590653255581856, 0.04837508872151375, 0.015060373581945896, 0.005841172765940428, ...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "top", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "left", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "bottom", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "right", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "strip_indent", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": true}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Name", "_fields": {"id": "top", "ctx": {"_type": "Load", "_fields": {}}}}, "upper": {"_type": "Name", "_fields": {"id": "bottom", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "right", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Name", "_fields": {"id": "indent", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "column_indices", "value": {"_type": "Name", "_fields": {"id": "utils", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ci", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "left", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "ci", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "left", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ci", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "target": {"_type": "Name", "_fields": {"id": "left", "ctx": {"_type": "Store", "_fields": {}}}}}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "IndexError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "right", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "ci", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "right", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ci", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "target": {"_type": "Name", "_fields": {"id": "right", "ctx": {"_type": "Store", "_fields": {}}}}}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "IndexError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rstrip", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Name", "_fields": {"id": "left", "ctx": {"_type": "Load", "_fields": {}}}}, "upper": {"_type": "Name", "_fields": {"id": "right", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "indent", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lstrip", "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "min", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "indent", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Name", "_fields": {"id": "indent", "ctx": {"_type": "Load", "_fields": {}}}}, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}, "target": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "strip_indent", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}, {"_type": "Lt", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "comparators": [{"_type": "Name", "_fields": {"id": "indent", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "right", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "block", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "get_2D_block", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_2D_block(self, top, left, bottom, right, strip_indent=True): block = self[top:bottom] indent = right for i in range(len(block.data)): # get slice from line, care for combining characters ci = utils.column_indices(block.data[i]) try: left = ci[left] except IndexError: left += len(block.data[i]) - len(ci) try: right = ci[right] except IndexError: right += len(block.data[i]) - len(ci) block.data[i] = line = block.data[i][left:right].rstrip() if line: indent = min(indent, len(line) - len(line.lstrip())) if strip_indent and 0 < indent < right: block.data = [line[indent:] for line in block.data] return block
12,518
[ 0.027539458125829697, 0.025056734681129456, -0.0035910827573388815, -0.04727606847882271, -0.006806627381592989, -0.03809624910354614, 0.00563828693702817, -0.002198462374508381, -0.06325729936361313, -0.0034763349685817957, 0.036281149834394455, 0.008710396476089954, 0.024117888882756233, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "i", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "item", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "source", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "offset", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "inserting non-ViewList with no source given"}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ViewList", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "upper": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "upper": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "offset", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent_offset", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "source", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "offset", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insert", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parent", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}]}}], "name": "insert", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def insert(self, i, item, source=None, offset=0): if source is None: if not isinstance(item, ViewList): raise TypeError('inserting non-ViewList with no source given') self.data[i:i] = item.data self.items[i:i] = item.items if self.parent: index = (len(self.data) + i) % len(self.data) self.parent.insert(index + self.parent_offset, item) else: self.data.insert(i, item) self.items.insert(i, (source, offset)) if self.parent: index = (len(self.data) + i) % len(self.data) self.parent.insert(index + self.parent_offset, item, source, offset)
12,519
[ 0.011310231871902943, -0.013098654337227345, 0.02075803652405739, 0.009484807029366493, -0.007073519751429558, -0.014603395946323872, -0.004588229116052389, 0.0030156506691128016, 0.02033868245780468, 0.0491877906024456, -0.012549793347716331, -0.04546293616294861, -0.06280446797609329, -0...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "response", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update_headers", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "updated_headers", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "updated_headers", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "headers", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "warning_header_value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "Warning"}}], "values": [{"_type": "Name", "_fields": {"id": "warning_header_value", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "headers", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "warning_header_value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}], "test": {"_type": "Name", "_fields": {"id": "updated_headers", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "apply", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def apply(self, response): updated_headers = self.update_headers(response) if updated_headers: response.headers.update(updated_headers) warning_header_value = self.warning(response) if warning_header_value is not None: response.headers.update({'Warning': warning_header_value}) return response
12,520
[ 0.0450783334672451, -0.014041537418961525, 0.011973932385444641, 0.007088931743055582, -0.0014427793212234974, 0.012530595995485783, 0.015927376225590706, -0.0344676598906517, 0.013712083920836449, 0.06348229199647903, -0.0008633955148980021, -0.05907443165779114, 0.0031894512940198183, -0...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "X", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "A", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "leaves_cnt", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "target": {"_type": "Name", "_fields": {"id": "leaves_cnt", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "leaves_cnt", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "A", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}], "name": "solution", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def solution(X, A): path = [None] * (X + 1) leaves_cnt = 0 for i, a in enumerate(A): if path[a] is None: path[a] = i leaves_cnt += 1 if leaves_cnt == X: return i return -1
12,521
[ -0.0011692752595990896, -0.03224281594157219, 0.018140526488423347, -0.0345984548330307, 0.004337952006608248, 0.00820793118327856, -0.0004761888412758708, 0.004911087453365326, 0.021558307111263275, -0.018855631351470947, 0.006635752040892839, -0.05068831145763397, -0.056535348296165466, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "response", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "date"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "headers", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "parsedate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "date", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "days", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "expire_after", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "date", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 6}}}}, "value": {"_type": "Name", "_fields": {"id": "date", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "datetime", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expires", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "expires", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "datetime_to_header", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "expires"}}, "value": {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "public"}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "cache-control"}}, "value": {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "expires"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "headers", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "update_headers", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def update_headers(self, response): headers = {} if 'expires' not in response.headers: date = parsedate(response.headers['date']) expires = expire_after(timedelta(days=1), date=datetime(*date[:6])) headers['expires'] = datetime_to_header(expires) headers['cache-control'] = 'public' return headers
12,522
[ 0.015991266816854477, 0.00606753071770072, 0.025773389264941216, -0.021198231726884842, -0.013921552337706089, 0.03361651673913002, -0.00992373563349247, -0.02596946805715561, 0.028235260397195816, 0.0066503188572824, 0.01057188306003809, -0.04993458092212677, -0.04666661098599434, -0.0126...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "resp", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "headers", "value": {"_type": "Name", "_fields": {"id": "resp", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "expires"}}, "comparators": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cache-control"}}, "comparators": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "cache-control"}}, "value": {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "public"}}]}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status", "value": {"_type": "Name", "_fields": {"id": "resp", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cacheable_by_default_statuses", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "date"}}, "comparators": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "last-modified"}}, "comparators": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "date"}}, "value": {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "parsedate_tz", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "timegm", "value": {"_type": "Name", "_fields": {"id": "calendar", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "date", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "last-modified"}}, "value": {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "parsedate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "last_modified", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "date", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "last_modified", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "time", "value": {"_type": "Name", "_fields": {"id": "time", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "date", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "max", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "current_age", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "date", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "last_modified", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "timegm", "value": {"_type": "Name", "_fields": {"id": "calendar", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "delta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "delta", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 10}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 24}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 3600}}}}], "func": {"_type": "Name", "_fields": {"id": "min", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "max", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "freshness_lifetime", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "freshness_lifetime", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "current_age", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "date", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "freshness_lifetime", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "expires", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "expires"}}], "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TIME_FMT", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "expires", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "gmtime", "value": {"_type": "Name", "_fields": {"id": "time", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strftime", "value": {"_type": "Name", "_fields": {"id": "time", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}}}], "name": "update_headers", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def update_headers(self, resp): headers = resp.headers if 'expires' in headers: return {} if 'cache-control' in headers and headers['cache-control'] != 'public': return {} if resp.status not in self.cacheable_by_default_statuses: return {} if 'date' not in headers or 'last-modified' not in headers: return {} date = calendar.timegm(parsedate_tz(headers['date'])) last_modified = parsedate(headers['last-modified']) if date is None or last_modified is None: return {} now = time.time() current_age = max(0, now - date) delta = date - calendar.timegm(last_modified) freshness_lifetime = max(0, min(delta / 10, 24 * 3600)) if freshness_lifetime <= current_age: return {} expires = date + freshness_lifetime return {'expires': time.strftime(TIME_FMT, time.gmtime(expires))}
12,523
[ 0.007557687349617481, -0.011087194085121155, -0.014217761345207691, -0.015403497964143753, 0.01459453720599413, -0.011170306243002415, -0.009762936271727085, 0.04583371803164482, 0.03933987021446228, 0.041955139487981796, 0.042597874999046326, 0.0011109357001259923, 0.006516012363135815, 0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "method", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "method", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "authed"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "session", "value": {"_type": "Name", "_fields": {"id": "flask", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "redirect", "value": {"_type": "Name", "_fields": {"id": "flask", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "name": "wrapper", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "method", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "wraps", "value": {"_type": "Name", "_fields": {"id": "functools", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "wrapper", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "auth", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def auth(method): @functools.wraps(method) def wrapper(*args, **kwargs): if 'authed' in flask.session: return method(*args, **kwargs) else: return flask.redirect('/') return wrapper
12,524
[ 0.0018977074651047587, 0.000431395776104182, 0.038162436336278915, 0.004264056216925383, -0.04906268045306206, 0.01567922905087471, 0.01946307346224785, -0.006919689476490021, -0.009540609084069729, 0.04612354934215546, -0.02846561186015606, -0.0468178316950798, -0.021777350455522537, 0.05...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "min", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "max", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "aeiou"}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "vowels", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "word", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "min", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "random", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "max", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "min", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "syllables", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "type", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "ListComp", "_fields": {"elt": {"_type": "Name", "_fields": {"id": "ch", "ctx": {"_type": "Load", "_fields": {}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "ch", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "vowels", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lowercase", "value": {"_type": "Name", "_fields": {"id": "string", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "ch", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sample", "value": {"_type": "Name", "_fields": {"id": "random", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "type", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "c"}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "vowels", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sample", "value": {"_type": "Name", "_fields": {"id": "random", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "type", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "v"}}]}}, "orelse": []}}], "name": "word_part", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "random", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ran", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "v"}}], "func": {"_type": "Name", "_fields": {"id": "word_part", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "c"}}], "func": {"_type": "Name", "_fields": {"id": "word_part", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "target": {"_type": "Name", "_fields": {"id": "word", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "ran", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.333}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "c"}}], "func": {"_type": "Name", "_fields": {"id": "word_part", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "v"}}], "func": {"_type": "Name", "_fields": {"id": "word_part", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "target": {"_type": "Name", "_fields": {"id": "word", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "ran", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.666}}]}}, "orelse": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "c"}}], "func": {"_type": "Name", "_fields": {"id": "word_part", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "v"}}], "func": {"_type": "Name", "_fields": {"id": "word_part", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "c"}}], "func": {"_type": "Name", "_fields": {"id": "word_part", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "target": {"_type": "Name", "_fields": {"id": "word", "ctx": {"_type": "Store", "_fields": {}}}}}}]}}]}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Name", "_fields": {"id": "syllables", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "word", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "gen_word", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def gen_word(min, max): # gen_word(2, 3) vowels = list('aeiou') word = '' syllables = min + int(random.random() * (max - min)) def word_part(type): if type is 'c': return random.sample([ch for ch in list(string.lowercase) if ch not in vowels], 1)[0] if type is 'v': return random.sample(vowels, 1)[0] for i in range(0, syllables): ran = random.random() if ran < 0.333: word += word_part('v') + word_part('c') elif ran < 0.666: word += word_part('c') + word_part('v') else: word += word_part('c') + word_part('v') + word_part('c') return word
12,525
[ 0.0708971694111824, -0.018307622522115707, -0.04336842522025108, 0.009019196964800358, -0.01607525907456875, 0.035560764372348785, 0.008329295553267002, 0.0038645686581730843, -0.003227952402085066, 0.07596766203641891, 0.05743568018078804, 0.00678122416138649, 0.009720315225422382, 0.0557...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "id", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "utf-8"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "encode", "value": {"_type": "Name", "_fields": {"id": "id", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "id_encoded", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "^[A-Za-z0-9]+"}}, {"_type": "Name", "_fields": {"id": "id", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "match", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "id_encoded", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getsizeof", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "id_encoded", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getsizeof", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 50}}]}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}], "name": null, "type": null}}], "finalbody": []}}], "name": "validate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def validate(id): try: id_encoded = id.encode('utf-8') if not re.match(r'^[A-Za-z0-9]+', id): return False if sys.getsizeof(id_encoded) < 1 or sys.getsizeof(id_encoded) > 50: return False return True except: return False
12,526
[ 0.007271943148225546, -0.03230820223689079, 0.08331569284200668, -0.017829246819019318, 0.008440648205578327, -0.028905972838401794, 0.0000033256610549869947, 0.002877936465665698, -0.0019527114927768707, 0.014725684188306332, -0.04482633247971535, -0.03350288048386574, 0.06446058303117752, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "os"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "compiler"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "build_type"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "arch"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Hello/0.1@%s/%s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "username", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "channel", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "requires", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "cmake"}}, "targets": [{"_type": "Name", "_fields": {"id": "generators", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "CMake", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cmake", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "configure", "value": {"_type": "Name", "_fields": {"id": "cmake", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build", "value": {"_type": "Name", "_fields": {"id": "cmake", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "build", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "."}}, {"_type": "Constant", "_fields": {"kind": null, "value": "bin"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "greet"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sep", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "run", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "settings", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cross_building", "value": {"_type": "Name", "_fields": {"id": "tools", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "orelse": []}}], "name": "test", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "HelloReuseConan", "bases": [{"_type": "Name", "_fields": {"id": "ConanFile", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class HelloReuseConan(ConanFile): settings = "os", "compiler", "build_type", "arch" requires = "Hello/0.1@%s/%s" % (username, channel) generators = "cmake" def build(self): cmake = CMake(self) cmake.configure() cmake.build() def test(self): # equal to ./bin/greet, but portable win: .\bin\greet if not tools.cross_building(self.settings): self.run(os.sep.join([".","bin", "greet"]))
12,527
[ 0.021906977519392967, 0.009783699177205563, 0.059015631675720215, -0.05077672749757767, 0.018089767545461655, 0.01744050718843937, 0.010376989841461182, -0.026821216568350792, 0.004975805524736643, 0.026171954348683357, -0.011451628990471363, -0.017977826297283173, 0.01941067911684513, -0....
10
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "DataLoader", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "setUp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "AnsibleFileNotFound", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "on the Ansible Controller"}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaisesRegex", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_none", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": ""}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "./"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_empty_strings", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, {"_type": "Constant", "_fields": {"kind": null, "value": "~/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "~"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expanduser", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_empty_lists", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_all_slash", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "paths", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "foo/bar/tasks/"}}]}}}}, {"_type": "keyword", "_fields": {"arg": "dirname", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}}}, {"_type": "keyword", "_fields": {"arg": "source", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}}}]}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_path_endswith_role", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "paths", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "foo/bar/tasks/"}}]}}}}, {"_type": "keyword", "_fields": {"arg": "dirname", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}}}, {"_type": "keyword", "_fields": {"arg": "source", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "~/"}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "~"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expanduser", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_path_endswith_role_source_tilde", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "AnsibleFileNotFound", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "foo/bar/tasks/"}}]}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "main.yml"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_path_endswith_role_source_main_yml", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "AnsibleFileNotFound", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative_stack", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "foo/bar/tasks/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tasks"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tasks/main.yml"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_path_endswith_role_source_main_yml_source_in_dirname", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "TestPathDwimRelativeStackDataLoader", "bases": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TestCase", "value": {"_type": "Name", "_fields": {"id": "unittest", "ctx": {"_type": "Load", "_fields": {}}}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class TestPathDwimRelativeStackDataLoader(unittest.TestCase): def setUp(self): self._loader = DataLoader() def test_none(self): self.assertRaisesRegex(AnsibleFileNotFound, 'on the Ansible Controller', self._loader.path_dwim_relative_stack, None, None, None) def test_empty_strings(self): self.assertEqual(self._loader.path_dwim_relative_stack('', '', ''), './') def test_empty_lists(self): self.assertEqual(self._loader.path_dwim_relative_stack([], '', '~/'), os.path.expanduser('~')) def test_all_slash(self): self.assertEqual(self._loader.path_dwim_relative_stack('/', '/', '/'), '/') def test_path_endswith_role(self): self.assertEqual(self._loader.path_dwim_relative_stack(paths=['foo/bar/tasks/'], dirname='/', source='/'), '/') def test_path_endswith_role_source_tilde(self): self.assertEqual(self._loader.path_dwim_relative_stack(paths=['foo/bar/tasks/'], dirname='/', source='~/'), os.path.expanduser('~')) def test_path_endswith_role_source_main_yml(self): self.assertRaises(AnsibleFileNotFound, self._loader.path_dwim_relative_stack, ['foo/bar/tasks/'], '/', 'main.yml') def test_path_endswith_role_source_main_yml_source_in_dirname(self): self.assertRaises(AnsibleFileNotFound, self._loader.path_dwim_relative_stack, 'foo/bar/tasks/', 'tasks', 'tasks/main.yml')
12,528
[ 0.030965112149715424, 0.036266446113586426, 0.06911696493625641, -0.03582281991839409, 0.02182641066610813, 0.024244174361228943, 0.026573210954666138, -0.018998293206095695, 0.018754299730062485, 0.019275560975074768, -0.009166426956653595, -0.014706210233271122, 0.01473948173224926, 0.01...
10
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "DataLoader", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "setUp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_all_slash", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "path", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "foo/bar/tasks/"}}}}, {"_type": "keyword", "_fields": {"arg": "dirname", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}}}, {"_type": "keyword", "_fields": {"arg": "source", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}}}]}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_path_endswith_role", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "main.yml"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "path", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "foo/bar/tasks/"}}}}, {"_type": "keyword", "_fields": {"arg": "dirname", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}}}, {"_type": "keyword", "_fields": {"arg": "source", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "main.yml"}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertIn", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_path_endswith_role_main_yml", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path_dwim_relative", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "path", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "foo/bar/tasks/"}}}}, {"_type": "keyword", "_fields": {"arg": "dirname", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "/"}}}}, {"_type": "keyword", "_fields": {"arg": "source", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "~/"}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "~"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expanduser", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_path_endswith_role_source_tilde", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "TestPathDwimRelativeDataLoader", "bases": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TestCase", "value": {"_type": "Name", "_fields": {"id": "unittest", "ctx": {"_type": "Load", "_fields": {}}}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class TestPathDwimRelativeDataLoader(unittest.TestCase): def setUp(self): self._loader = DataLoader() def test_all_slash(self): self.assertEqual(self._loader.path_dwim_relative('/', '/', '/'), '/') def test_path_endswith_role(self): self.assertEqual(self._loader.path_dwim_relative(path='foo/bar/tasks/', dirname='/', source='/'), '/') def test_path_endswith_role_main_yml(self): self.assertIn('main.yml', self._loader.path_dwim_relative(path='foo/bar/tasks/', dirname='/', source='main.yml')) def test_path_endswith_role_source_tilde(self): self.assertEqual(self._loader.path_dwim_relative(path='foo/bar/tasks/', dirname='/', source='~/'), os.path.expanduser('~'))
12,529
[ 0.013260803185403347, 0.00310112489387393, 0.01164334174245596, -0.050046149641275406, 0.058751896023750305, 0.012594789266586304, -0.02356022410094738, 0.009585835970938206, 0.007837550714612007, -0.01831536926329136, 0.0048969825729727745, -0.01054322998970747, 0.01548481173813343, 0.001...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "$ANSIBLE_VAULT;1.1;AES256\n33343734386261666161626433386662623039356366656637303939306563376130623138626165\n6436333766346533353463636566313332623130383662340a393835656134633665333861393331\n37666233346464636263636530626332623035633135363732623332313534306438393366323966\n3135306561356164310a343937653834643433343734653137383339323330626437313562306630\n3035\n"}}, "targets": [{"_type": "Name", "_fields": {"id": "vaulted_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "builtins"}}, "targets": [{"_type": "Name", "_fields": {"id": "builtins_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "PY3", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "__builtin__"}}, "targets": [{"_type": "Name", "_fields": {"id": "builtins_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "dummy_vault.txt"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "load_from_file", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "output", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "output", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "foo", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "bar"}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "builtins_name", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": ".open"}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "mock_open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "read_data", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "utf-8"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "encode", "value": {"_type": "Name", "_fields": {"id": "vaulted_data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "patch", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "test_parse_from_vault_1_1_file", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_parse_from_vault_1_1_file(self): vaulted_data = """$ANSIBLE_VAULT;1.1;AES256 33343734386261666161626433386662623039356366656637303939306563376130623138626165 6436333766346533353463636566313332623130383662340a393835656134633665333861393331 37666233346464636263636530626332623035633135363732623332313534306438393366323966 3135306561356164310a343937653834643433343734653137383339323330626437313562306630 3035 """ if PY3: builtins_name = 'builtins' else: builtins_name = '__builtin__' with patch(builtins_name + '.open', mock_open(read_data=vaulted_data.encode('utf-8'))): output = self._loader.load_from_file('dummy_vault.txt') self.assertEqual(output, dict(foo='bar'))
12,530
[ 0.03399201110005379, 0.01628643088042736, 0.03849724680185318, -0.06618192791938782, 0.01929367519915104, 0.020656509324908257, -0.008886579424142838, -0.0125583466142416, 0.017852000892162323, 0.00920194573700428, 0.018617890775203705, 0.01071119960397482, 0.0065269614569842815, 0.0035084...
12
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "DataLoader", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "ansible"}}], "func": {"_type": "Name", "_fields": {"id": "TextVaultSecret", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vault_secrets", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "vault_secrets", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_vault_secrets", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "__file__", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dirname", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "fixtures"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "vault.yml"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "test_vault_data_path", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "setUp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Pass", "_fields": {}}], "name": "tearDown", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "test_vault_data_path", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_real_file", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "real_file_path", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "real_file_path", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exists", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertTrue", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_get_real_file_vault", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_vault_secrets", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "AnsibleParserError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_real_file", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "test_vault_data_path", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_get_real_file_vault_no_vault", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "wrong_password"}}], "func": {"_type": "Name", "_fields": {"id": "TextVaultSecret", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "wrong_vault", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "wrong_vault", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_vault_secrets", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "AnsibleVaultError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_real_file", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "test_vault_data_path", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_get_real_file_vault_wrong_password", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "AnsibleParserError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Invalid filename"}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_real_file", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaisesRegex", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_get_real_file_not_a_path", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "$ANSIBLE_VAULT;1.1;AES256\n33343734386261666161626433386662623039356366656637303939306563376130623138626165\n6436333766346533353463636566313332623130383662340a393835656134633665333861393331\n37666233346464636263636530626332623035633135363732623332313534306438393366323966\n3135306561356164310a343937653834643433343734653137383339323330626437313562306630\n3035\n"}}, "targets": [{"_type": "Name", "_fields": {"id": "vaulted_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "builtins"}}, "targets": [{"_type": "Name", "_fields": {"id": "builtins_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "PY3", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "__builtin__"}}, "targets": [{"_type": "Name", "_fields": {"id": "builtins_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "dummy_vault.txt"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "load_from_file", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_loader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "output", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "output", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "foo", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "bar"}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "builtins_name", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": ".open"}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "mock_open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "read_data", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "utf-8"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "encode", "value": {"_type": "Name", "_fields": {"id": "vaulted_data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "patch", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "test_parse_from_vault_1_1_file", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "DataLoader", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "multiple", "value": {"_type": "Name", "_fields": {"id": "patch", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "path_exists", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "s", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "x", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_file", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "s", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "x", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}}}]}}]}}], "name": "TestDataLoaderWithVault", "bases": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TestCase", "value": {"_type": "Name", "_fields": {"id": "unittest", "ctx": {"_type": "Load", "_fields": {}}}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class TestDataLoaderWithVault(unittest.TestCase): def setUp(self): self._loader = DataLoader() vault_secrets = [('default', TextVaultSecret('ansible'))] self._loader.set_vault_secrets(vault_secrets) self.test_vault_data_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'vault.yml') def tearDown(self): pass def test_get_real_file_vault(self): real_file_path = self._loader.get_real_file(self.test_vault_data_path) self.assertTrue(os.path.exists(real_file_path)) def test_get_real_file_vault_no_vault(self): self._loader.set_vault_secrets(None) self.assertRaises(AnsibleParserError, self._loader.get_real_file, self.test_vault_data_path) def test_get_real_file_vault_wrong_password(self): wrong_vault = [('default', TextVaultSecret('wrong_password'))] self._loader.set_vault_secrets(wrong_vault) self.assertRaises(AnsibleVaultError, self._loader.get_real_file, self.test_vault_data_path) def test_get_real_file_not_a_path(self): self.assertRaisesRegex(AnsibleParserError, 'Invalid filename', self._loader.get_real_file, None) @patch.multiple(DataLoader, path_exists=lambda s, x: True, is_file=lambda s, x: True) def test_parse_from_vault_1_1_file(self): vaulted_data = """$ANSIBLE_VAULT;1.1;AES256 33343734386261666161626433386662623039356366656637303939306563376130623138626165 6436333766346533353463636566313332623130383662340a393835656134633665333861393331 37666233346464636263636530626332623035633135363732623332313534306438393366323966 3135306561356164310a343937653834643433343734653137383339323330626437313562306630 3035 """ if PY3: builtins_name = 'builtins' else: builtins_name = '__builtin__' with patch(builtins_name + '.open', mock_open(read_data=vaulted_data.encode('utf-8'))): output = self._loader.load_from_file('dummy_vault.txt') self.assertEqual(output, dict(foo='bar'))
12,531
[ -0.0328352265059948, -0.011941983364522457, 0.033818189054727554, -0.024929674342274666, -0.03063923865556717, -0.014357567764818668, -0.00020734424469992518, -0.010577334091067314, -0.02748120203614235, 0.02419767901301384, -0.022963743656873703, -0.03316985070705414, 0.01174329873174429, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "docutilsconf", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "srcdir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "cleanenv"}}], "values": [{"_type": "Name", "_fields": {"id": "root", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": true}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "default_kw", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "default_kw", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "func", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs2", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args2", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "TestApp", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "default_kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "docutilsconf", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write_text", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "srcdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "docutils.conf"}}}}}}, "keywords": []}}}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getcwd", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cwd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "srcdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "chdir", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args2", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs2", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "orelse": [], "handlers": [], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cwd", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "chdir", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cleanup", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "deco", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wraps", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "deco", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "generator", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "generator", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "with_conf_app", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def with_conf_app(docutilsconf='', *args, **kwargs): default_kw = { 'srcdir': root, 'cleanenv': True, } default_kw.update(kwargs) def generator(func): @wraps(func) def deco(*args2, **kwargs2): app = TestApp(*args, **default_kw) (app.srcdir / 'docutils.conf').write_text(docutilsconf) try: cwd = os.getcwd() os.chdir(app.srcdir) func(app, *args2, **kwargs2) finally: os.chdir(cwd) # don't execute cleanup if test failed app.cleanup() return deco return generator
12,532
[ 0.001761582912877202, 0.024155523627996445, 0.014779825694859028, -0.039179932326078415, -0.02168639563024044, -0.022874372079968452, 0.012799864634871483, -0.005465274211019278, 0.008979705162346363, 0.014034428633749485, 0.013708317652344704, -0.023899292573332787, -0.0026059779338538647, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "func", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs2", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args2", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "TestApp", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "default_kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "docutilsconf", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write_text", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "srcdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "docutils.conf"}}}}}}, "keywords": []}}}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getcwd", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cwd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "srcdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "chdir", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args2", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs2", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "orelse": [], "handlers": [], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cwd", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "chdir", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cleanup", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "deco", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wraps", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "deco", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "generator", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def generator(func): @wraps(func) def deco(*args2, **kwargs2): app = TestApp(*args, **default_kw) (app.srcdir / 'docutils.conf').write_text(docutilsconf) try: cwd = os.getcwd() os.chdir(app.srcdir) func(app, *args2, **kwargs2) finally: os.chdir(cwd) # don't execute cleanup if test failed app.cleanup() return deco
12,533
[ -0.010548176243901253, 0.018771035596728325, 0.08065591752529144, -0.015782948583364487, 0.008486844599246979, -0.033273376524448395, 0.009716903790831566, -0.04333851486444473, -0.0016246326267719269, -0.008144225925207138, 0.01549087930470705, -0.04439445585012436, -0.00744775403290987, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "app", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "contents"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "builder", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "text", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "outdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "contents.html"}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "encoding", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "utf-8"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<th class=\"field-name\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<th class=\"field-name\" colspan=\"2\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<td class=\"option-group\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<td class=\"option-group\" colspan=\"2\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}}}], "name": "test_html_with_default_docutilsconf", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_html_with_default_docutilsconf(app): app.builder.build(['contents']) result = (app.outdir / 'contents.html').text(encoding='utf-8') assert regex_count(r'<th class="field-name">', result) == 1 assert regex_count(r'<th class="field-name" colspan="2">', result) == 1 assert regex_count(r'<td class="option-group">', result) == 1 assert regex_count(r'<td class="option-group" colspan="2">', result) == 1
12,534
[ 0.005335111636668444, 0.01176156010478735, 0.031439557671546936, -0.07011699676513672, -0.02257314883172512, -0.016160836443305016, 0.028182508423924446, -0.012191309593617916, -0.018411366268992424, 0.031914543360471725, 0.011908579617738724, -0.025287354364991188, 0.01371805090457201, 0....
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs2", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args2", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "TestApp", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "default_kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "docutilsconf", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write_text", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "srcdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "docutils.conf"}}}}}}, "keywords": []}}}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getcwd", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cwd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "srcdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "chdir", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args2", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs2", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "orelse": [], "handlers": [], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cwd", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "chdir", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cleanup", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "deco", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def deco(*args2, **kwargs2): app = TestApp(*args, **default_kw) (app.srcdir / 'docutils.conf').write_text(docutilsconf) try: cwd = os.getcwd() os.chdir(app.srcdir) func(app, *args2, **kwargs2) finally: os.chdir(cwd) # don't execute cleanup if test failed app.cleanup()
12,535
[ 0.0051215519197285175, 0.006772524677217007, 0.03196414187550545, -0.019398251548409462, -0.037316884845495224, -0.013109867461025715, -0.01951792649924755, 0.0034678590018302202, 0.010596689768135548, 0.015568647533655167, -0.01691771298646927, -0.06431994587182999, 0.002696770476177335, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "cursor", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "parameter_name", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "facts", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\n select c.parameter_name, c.current_value, c.default_value\n from configuration_parameters c\n where c.node_name = 'ALL'\n and (? = '' or c.parameter_name ilike ?)\n "}}, {"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "execute", "value": {"_type": "Name", "_fields": {"id": "cursor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "While", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 100}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fetchmany", "value": {"_type": "Name", "_fields": {"id": "cursor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "rows", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Break", "_fields": {}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "rows", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "parameter_name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "current_value"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "default_value"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parameter_name", "value": {"_type": "Name", "_fields": {"id": "row", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "current_value", "value": {"_type": "Name", "_fields": {"id": "row", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "default_value", "value": {"_type": "Name", "_fields": {"id": "row", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parameter_name", "value": {"_type": "Name", "_fields": {"id": "row", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "value": {"_type": "Name", "_fields": {"id": "facts", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Name", "_fields": {"id": "rows", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "row", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "test": {"_type": "Constant", "_fields": {"kind": null, "value": true}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "facts", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "get_configuration_facts", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_configuration_facts(cursor, parameter_name=''): facts = {} cursor.execute(""" select c.parameter_name, c.current_value, c.default_value from configuration_parameters c where c.node_name = 'ALL' and (? = '' or c.parameter_name ilike ?) """, parameter_name, parameter_name) while True: rows = cursor.fetchmany(100) if not rows: break for row in rows: facts[row.parameter_name.lower()] = { 'parameter_name': row.parameter_name, 'current_value': row.current_value, 'default_value': row.default_value} return facts
12,536
[ 0.003155024955049157, 0.014166346751153469, 0.08377017825841904, -0.026058800518512726, 0.0034193648025393486, -0.036655135452747345, 0.005599458701908588, -0.03838329389691353, 0.0013892058050259948, 0.00441987719386816, 0.030265500769019127, -0.04802459478378296, -0.010863518342375755, -...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "app", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "contents"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "builder", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "text", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "outdir", "value": {"_type": "Name", "_fields": {"id": "app", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "contents.html"}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "encoding", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "utf-8"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<th class=\"field-name\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<th class=\"field-name\" colspan=\"2\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<td class=\"option-group\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}, {"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "<td class=\"option-group\" colspan=\"2\">"}}, {"_type": "Name", "_fields": {"id": "result", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "regex_count", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}}}], "name": "test_html_with_docutilsconf", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_html_with_docutilsconf(app): app.builder.build(['contents']) result = (app.outdir / 'contents.html').text(encoding='utf-8') assert regex_count(r'<th class="field-name">', result) == 0 assert regex_count(r'<th class="field-name" colspan="2">', result) == 2 assert regex_count(r'<td class="option-group">', result) == 0 assert regex_count(r'<td class="option-group" colspan="2">', result) == 2
12,537
[ 0.010081402026116848, 0.01609635539352894, 0.03693690150976181, -0.04059186205267906, -0.018226400017738342, 0.07285718619823456, 0.009391558356583118, -0.025124838575720787, 0.022050797939300537, 0.04182631894946098, 0.018819423392415047, -0.08466925472021103, 0.014474617317318916, 0.0206...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "AnsibleModule", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "argument_spec", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "parameter", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "required", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "aliases", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "name"}}]}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "value", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "db", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "cluster", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "localhost"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "port", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "5433"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "login_user", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "dbadmin"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "login_password", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "no_log", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "supports_check_mode", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fail_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "msg", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "The python pyodbc module is required."}}}}]}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "pyodbc_found", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "parameter"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "value"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "current_value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "db"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "db"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}, "targets": [{"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "cluster"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "port"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "login_user"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "login_password"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "true"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Driver=Vertica;Server={0};Port={1};Database={2};User={3};Password={4};ConnectionLoadBalance={5}"}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "dsn", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dsn", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "connect", "value": {"_type": "Name", "_fields": {"id": "pyodbc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "autocommit", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "db_conn", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cursor", "value": {"_type": "Name", "_fields": {"id": "db_conn", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cursor", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "get_exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fail_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "msg", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Unable to connect to database: {0}."}}}}, "keywords": []}}}}]}}}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cursor", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "current_value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "check", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "check_mode", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "cursor", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "current_value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "present", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "get_exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fail_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "msg", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}}}], "name": null, "type": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Error", "value": {"_type": "Name", "_fields": {"id": "pyodbc", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "finalbody": []}}]}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "get_exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fail_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "msg", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "ansible_facts", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "vertica_configuration"}}], "values": [{"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "NotSupportedError", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "get_exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fail_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "msg", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "ansible_facts", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "vertica_configuration"}}], "values": [{"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "CannotDropError", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": null, "cause": null}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "SystemExit", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "get_exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fail_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "msg", "value": {"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "changed", "value": {"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "parameter", "value": {"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "ansible_facts", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "vertica_configuration"}}], "values": [{"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}}}], "name": "main", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def main(): module = AnsibleModule( argument_spec=dict( parameter=dict(required=True, aliases=['name']), value=dict(default=None), db=dict(default=None), cluster=dict(default='localhost'), port=dict(default='5433'), login_user=dict(default='dbadmin'), login_password=dict(default=None, no_log=True), ), supports_check_mode = True) if not pyodbc_found: module.fail_json(msg="The python pyodbc module is required.") parameter_name = module.params['parameter'] current_value = module.params['value'] db = '' if module.params['db']: db = module.params['db'] changed = False try: dsn = ( "Driver=Vertica;" "Server={0};" "Port={1};" "Database={2};" "User={3};" "Password={4};" "ConnectionLoadBalance={5}" ).format(module.params['cluster'], module.params['port'], db, module.params['login_user'], module.params['login_password'], 'true') db_conn = pyodbc.connect(dsn, autocommit=True) cursor = db_conn.cursor() except Exception: e = get_exception() module.fail_json(msg="Unable to connect to database: {0}.".format(e)) try: configuration_facts = get_configuration_facts(cursor) if module.check_mode: changed = not check(configuration_facts, parameter_name, current_value) else: try: changed = present(configuration_facts, cursor, parameter_name, current_value) except pyodbc.Error: e = get_exception() module.fail_json(msg=str(e)) except NotSupportedError: e = get_exception() module.fail_json(msg=str(e), ansible_facts={'vertica_configuration': configuration_facts}) except CannotDropError: e = get_exception() module.fail_json(msg=str(e), ansible_facts={'vertica_configuration': configuration_facts}) except SystemExit: # avoid catching this on python 2.4 raise except Exception: e = get_exception() module.fail_json(msg=e) module.exit_json(changed=changed, parameter=parameter_name, ansible_facts={'vertica_configuration': configuration_facts})
12,538
[ 0.048269178718328476, 0.014420805498957634, 0.006627575494349003, -0.033615242689847946, -0.007032779045403004, 0.03525825962424278, 0.008931130170822144, 0.005761661101132631, 0.02400137111544609, 0.01253355573862791, 0.0075101424008607864, -0.04791393131017685, 0.0003070249513257295, 0.0...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "configuration_facts", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "cursor", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "parameter_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "current_value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "parameter_key", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}, "targets": [{"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "current_value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "select set_config_parameter('{0}', '{1}')"}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "execute", "value": {"_type": "Name", "_fields": {"id": "cursor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}, "targets": [{"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "current_value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Name", "_fields": {"id": "current_value", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "current_value"}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "parameter_key", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}]}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cursor", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parameter_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "configuration_facts", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "changed", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "present", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def present(configuration_facts, cursor, parameter_name, current_value): parameter_key = parameter_name.lower() changed = False if current_value and current_value.lower() != configuration_facts[parameter_key]['current_value'].lower(): cursor.execute("select set_config_parameter('{0}', '{1}')".format(parameter_name, current_value)) changed = True if changed: configuration_facts.update(get_configuration_facts(cursor, parameter_name)) return changed
12,539
[ 0.036492932587862015, 0.03371438384056091, -0.0018136401195079088, -0.01483198069036007, -0.010184756480157375, -0.04625699296593666, -0.013012225739657879, -0.046687472611665726, -0.0324033759534359, 0.020486917346715927, 0.00924552883952856, -0.007763308938592672, 0.034242697060108185, -...
9
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "parent", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "parent", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "MultiPageWidgetExtensionFactory", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "obj", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "iid", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "parent", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "iid", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "QDesignerContainerExtension"}}, "value": {"_type": "Name", "_fields": {"id": "Q_TYPEID", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parent", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "MultiPageWidgetContainerExtension", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "PyMultiPageWidget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "name": "createExtension", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "MultiPageWidgetExtensionFactory", "bases": [{"_type": "Name", "_fields": {"id": "QExtensionFactory", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class MultiPageWidgetExtensionFactory(QExtensionFactory): def __init__(self, parent=None): super(MultiPageWidgetExtensionFactory, self).__init__(parent) def createExtension(self, obj, iid, parent): if iid != Q_TYPEID['QDesignerContainerExtension']: return None if isinstance(obj, PyMultiPageWidget): return MultiPageWidgetContainerExtension(obj, parent) return None
12,540
[ 0.04924239590764046, 0.021789181977510452, 0.00861645583063364, -0.008207065984606743, -0.028397219255566597, -0.0148728983476758, -0.015460493974387646, -0.028397219255566597, -0.03756755590438843, 0.0162311103194952, -0.0011763942893594503, 0.005924114491790533, 0.039763811975717545, -0....
9
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "widget", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "parent", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "parent", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "MultiPageWidgetContainerExtension", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "widget", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addPage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "addWidget", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "count", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getCurrentIndex", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "currentIndex", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "widget", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "insertPage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "insertWidget", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "removePage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "remove", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "setCurrentIndex", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "setCurrentIndex", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "widget", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_widget", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "widget", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "MultiPageWidgetContainerExtension", "bases": [{"_type": "Name", "_fields": {"id": "QPyDesignerContainerExtension", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class MultiPageWidgetContainerExtension(QPyDesignerContainerExtension): def __init__(self, widget, parent=None): super(MultiPageWidgetContainerExtension, self).__init__(parent) self._widget = widget def addWidget(self, widget): self._widget.addPage(widget) def count(self): return self._widget.count() def currentIndex(self): return self._widget.getCurrentIndex() def insertWidget(self, index, widget): self._widget.insertPage(index, widget) def remove(self, index): self._widget.removePage(index) def setCurrentIndex(self, index): self._widget.setCurrentIndex(index) def widget(self, index): return self._widget.widget(index)
12,541
[ 0.025228746235370636, 0.03152405470609665, 0.0003964262723457068, 0.020560715347528458, -0.02553757280111313, -0.013683387078344822, 0.010547610931098461, 0.029172221198678017, -0.02282940223813057, 0.028364522382616997, 0.004457197152078152, 0.0072455438785254955, 0.04102640599012375, -0....
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "formEditor", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "initialized", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extensionManager", "value": {"_type": "Name", "_fields": {"id": "formEditor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "MultiPageWidgetExtensionFactory", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "factory", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "factory", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "QDesignerContainerExtension"}}, "value": {"_type": "Name", "_fields": {"id": "Q_TYPEID", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "registerExtensions", "value": {"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "initialized", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "initialize", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def initialize(self, formEditor): if self.initialized: return manager = formEditor.extensionManager() if manager: self.factory = MultiPageWidgetExtensionFactory(manager) manager.registerExtensions(self.factory, Q_TYPEID['QDesignerContainerExtension']) self.initialized = True
12,542
[ 0.04011828079819679, 0.04288724809885025, -0.0196258295327425, 0.015324423089623451, -0.040773533284664154, -0.00046765911974944174, -0.0074508399702608585, -0.012840809300541878, -0.01824134774506092, 0.03200162202119827, -0.0007999084773473442, 0.009321476332843304, 0.028873326256871223, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "parent", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "parent", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "MultiPageWidgetPlugin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "initialized", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "formEditor", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "initialized", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extensionManager", "value": {"_type": "Name", "_fields": {"id": "formEditor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "MultiPageWidgetExtensionFactory", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "factory", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "factory", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "QDesignerContainerExtension"}}, "value": {"_type": "Name", "_fields": {"id": "Q_TYPEID", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "registerExtensions", "value": {"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "initialized", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "initialize", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "initialized", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "name": "isInitialized", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "parent", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "parent", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "PyMultiPageWidget", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "currentIndexChanged", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "connect", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "currentIndexChanged", "value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pageTitleChanged", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "connect", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pageTitleChanged", "value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "createWidget", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "PyMultiPageWidget"}}}}], "name": "name", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "PyQt Examples"}}}}], "name": "group", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "QIcon", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "icon", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}}}], "name": "toolTip", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}}}], "name": "whatsThis", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}], "name": "isContainer", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "<widget class=\"PyMultiPageWidget\" name=\"multipagewidget\"> <widget class=\"QWidget\" name=\"page\" /></widget>"}}}}], "name": "domXml", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "multipagewidget"}}}}], "name": "includeFile", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sender", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "findFormWindow", "value": {"_type": "Name", "_fields": {"id": "QDesignerFormWindowInterface", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "emitSelectionChanged", "value": {"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "PyMultiPageWidget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": []}}], "name": "currentIndexChanged", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "title", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sender", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getCurrentIndex", "value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "widget", "value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "findFormWindow", "value": {"_type": "Name", "_fields": {"id": "QDesignerFormWindowInterface", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "core", "value": {"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "editor", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extensionManager", "value": {"_type": "Name", "_fields": {"id": "editor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "QDesignerPropertySheetExtension"}}, "value": {"_type": "Name", "_fields": {"id": "Q_TYPEID", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extension", "value": {"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "QPyDesignerPropertySheetExtension", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cast", "value": {"_type": "Name", "_fields": {"id": "sip", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "windowTitle"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "indexOf", "value": {"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "propertyIndex", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "propertyIndex", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": true}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "setChanged", "value": {"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "PyMultiPageWidget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": []}}], "name": "pageTitleChanged", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "MultiPageWidgetPlugin", "bases": [{"_type": "Name", "_fields": {"id": "QPyDesignerCustomWidgetPlugin", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class MultiPageWidgetPlugin(QPyDesignerCustomWidgetPlugin): def __init__(self, parent=None): super(MultiPageWidgetPlugin, self).__init__(parent) self.initialized = False def initialize(self, formEditor): if self.initialized: return manager = formEditor.extensionManager() if manager: self.factory = MultiPageWidgetExtensionFactory(manager) manager.registerExtensions(self.factory, Q_TYPEID['QDesignerContainerExtension']) self.initialized = True def isInitialized(self): return self.initialized def createWidget(self, parent): widget = PyMultiPageWidget(parent) widget.currentIndexChanged.connect(self.currentIndexChanged) widget.pageTitleChanged.connect(self.pageTitleChanged) return widget def name(self): return "PyMultiPageWidget" def group(self): return "PyQt Examples" def icon(self): return QIcon() def toolTip(self): return "" def whatsThis(self): return "" def isContainer(self): return True def domXml(self): return ('<widget class="PyMultiPageWidget" name="multipagewidget">' ' <widget class="QWidget" name="page" />' '</widget>') def includeFile(self): return "multipagewidget" def currentIndexChanged(self, index): widget = self.sender() if widget and isinstance(widget, PyMultiPageWidget): form = QDesignerFormWindowInterface.findFormWindow(widget) if form: form.emitSelectionChanged() def pageTitleChanged(self, title): widget = self.sender() if widget and isinstance(widget, PyMultiPageWidget): page = widget.widget(widget.getCurrentIndex()) form = QDesignerFormWindowInterface.findFormWindow(widget) if form: editor = form.core() manager = editor.extensionManager() sheet = manager.extension(page, Q_TYPEID['QDesignerPropertySheetExtension']) # This explicit cast is necessary here sheet = sip.cast(sheet, QPyDesignerPropertySheetExtension) propertyIndex = sheet.indexOf('windowTitle') sheet.setChanged(propertyIndex, True)
12,543
[ 0.03359983488917351, 0.04567939415574074, -0.012056812644004822, -0.003346902783960104, -0.035419728606939316, -0.0014786656247451901, 0.019290899857878685, -0.014354431070387363, 0.0011274826247245073, 0.0014672912657260895, 0.01706152781844139, 0.04790876805782318, 0.029482318088412285, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "title", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sender", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getCurrentIndex", "value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "widget", "value": {"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "findFormWindow", "value": {"_type": "Name", "_fields": {"id": "QDesignerFormWindowInterface", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "core", "value": {"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "editor", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extensionManager", "value": {"_type": "Name", "_fields": {"id": "editor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "QDesignerPropertySheetExtension"}}, "value": {"_type": "Name", "_fields": {"id": "Q_TYPEID", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extension", "value": {"_type": "Name", "_fields": {"id": "manager", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "QPyDesignerPropertySheetExtension", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cast", "value": {"_type": "Name", "_fields": {"id": "sip", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "windowTitle"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "indexOf", "value": {"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "propertyIndex", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "propertyIndex", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": true}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "setChanged", "value": {"_type": "Name", "_fields": {"id": "sheet", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "form", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "widget", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "PyMultiPageWidget", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": []}}], "name": "pageTitleChanged", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def pageTitleChanged(self, title): widget = self.sender() if widget and isinstance(widget, PyMultiPageWidget): page = widget.widget(widget.getCurrentIndex()) form = QDesignerFormWindowInterface.findFormWindow(widget) if form: editor = form.core() manager = editor.extensionManager() sheet = manager.extension(page, Q_TYPEID['QDesignerPropertySheetExtension']) # This explicit cast is necessary here sheet = sip.cast(sheet, QPyDesignerPropertySheetExtension) propertyIndex = sheet.indexOf('windowTitle') sheet.setChanged(propertyIndex, True)
12,544
[ 0.07280568778514862, 0.08195570111274719, 0.00896267220377922, 0.04433022439479828, 0.027686670422554016, -0.007848500274121761, 0.015332183800637722, 0.03222223371267319, -0.004690859466791153, -0.0110332565382123, -0.014858907088637352, -0.012423506006598473, 0.012581264600157738, -0.020...
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "user", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "obj", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "can_be_created_by"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "If `can_be_created_by` is None, then `user_can_create_object` method must be overridden with custom behavior."}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_get_target_object", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has_role_for", "value": {"_type": "Name", "_fields": {"id": "user", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "user_can_create_object", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def user_can_create_object(self, user, obj): roles = getattr(self, "can_be_created_by", None) assert isinstance(roles, tuple), \ "If `can_be_created_by` is None, then `user_can_create_object` method must be overridden with custom behavior." target_object = self._get_target_object(obj) return user.has_role_for(roles, target_object)
12,545
[ 0.04613267630338669, 0.08499787747859955, -0.0162827018648386, 0.04190647974610329, 0.05545400455594063, 0.023066338151693344, -0.02822071686387062, 0.01461394689977169, -0.01516690757125616, -0.031321242451667786, -0.02128896676003933, -0.026996305212378502, -0.00726747652515769, 0.024784...
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "user", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "obj", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "can_be_read_by"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "If `can_be_read_by` is None, then `user_can_read_object` method must be overridden with custom behavior."}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_get_target_object", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has_role_for", "value": {"_type": "Name", "_fields": {"id": "user", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "user_can_read_object", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def user_can_read_object(self, user, obj): roles = getattr(self, "can_be_read_by", None) assert isinstance(roles, tuple), \ "If `can_be_read_by` is None, then `user_can_read_object` method must be overridden with custom behavior." target_object = self._get_target_object(obj) return user.has_role_for(roles, target_object)
12,546
[ 0.0429583415389061, 0.06277614086866379, -0.005884026642888784, 0.0402289442718029, 0.015278691425919533, 0.027293972671031952, 0.040248721837997437, 0.01707851141691208, -0.000761462259106338, 0.015110576525330544, -0.020668262615799904, -0.01118459552526474, -0.02875756286084652, 0.01075...
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "user", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "obj", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "can_be_updated_by"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "If `can_be_updated_by` is None, then `user_can_update_object` method must be overridden with custom behavior."}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_get_target_object", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has_role_for", "value": {"_type": "Name", "_fields": {"id": "user", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "user_can_update_object", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def user_can_update_object(self, user, obj): roles = getattr(self, "can_be_updated_by", None) assert isinstance(roles, tuple), \ "If `can_be_updated_by` is None, then `user_can_update_object` method must be overridden with custom behavior." target_object = self._get_target_object(obj) return user.has_role_for(roles, target_object)
12,547
[ 0.058413755148649216, 0.09218420833349228, -0.008865694515407085, 0.03055693581700325, 0.019452236592769623, 0.041756708174943924, 0.0002819552319124341, 0.05548546463251114, 0.0074966223910450935, -0.003527262946590781, -0.0052528646774590015, -0.042441245168447495, -0.010895534418523312, ...
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "user", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "obj", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "can_be_deleted_by"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "If `can_be_deleted_by` is None, then `user_can_delete_object` method must be overridden with custom behavior."}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_get_target_object", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "roles", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_object", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has_role_for", "value": {"_type": "Name", "_fields": {"id": "user", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "user_can_delete_object", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def user_can_delete_object(self, user, obj): roles = getattr(self, "can_be_deleted_by", None) assert isinstance(roles, tuple), \ "If `can_be_deleted_by` is None, then `user_can_delete_object` method must be overridden with custom behavior." target_object = self._get_target_object(obj) return user.has_role_for(roles, target_object)
12,548
[ 0.03791353479027748, 0.06345780193805695, 0.06293515861034393, 0.03606250137090683, -0.010256906971335411, -0.0014549673069268465, 0.0014413567259907722, 0.003824563231319189, -0.007023041136562824, 0.029660100117325783, 0.0008438538061454892, -0.011411081068217754, 0.008041109889745712, -...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": {"_type": "arg", "_fields": {"arg": "perms", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "perms", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "each of the arguments to __init__ must be a subclass (or instance of a subclass) of BasePermissions"}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "perm", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "BasePermissions", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "perm", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "perms", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "perms", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "perm", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __init__(self, *perms): self.perms = [] for perm in perms: # ensure that perm is an instance of a subclass of BasePermissions assert isinstance(perm, BasePermissions), \ "each of the arguments to __init__ must be a subclass (or instance of a subclass) of BasePermissions" # add it into the children permissions list self.perms.append(perm)
12,549
[ 0.037977319210767746, 0.06363649666309357, 0.06259184330701828, 0.03610565885901451, -0.010239730589091778, -0.0014948808820918202, 0.001658107154071331, 0.003971840254962444, -0.006947999820113182, 0.02955484203994274, 0.0007345183403231204, -0.011360550299286842, 0.008204841986298561, -0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": {"_type": "arg", "_fields": {"arg": "perms", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "perms", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "each of the arguments to __init__ must be a subclass (or instance of a subclass) of BasePermissions"}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "perm", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "BasePermissions", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "perm", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "perms", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "perms", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "perm", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __init__(self, *perms): self.perms = [] for perm in perms: # ensure that perm is an instance of a subclass of BasePermissions assert isinstance(perm, BasePermissions), \ "each of the arguments to __init__ must be a subclass (or instance of a subclass) of BasePermissions" # add it into the children permissions list self.perms.append(perm)
12,550
[ 0.024418173357844353, 0.019815592095255852, 0.05064127966761589, -0.030090821906924248, -0.009579040110111237, -0.013859312050044537, 0.001088600605726242, -0.014980948530137539, -0.008876405656337738, -0.0027766970451921225, 0.008031954988837242, -0.06673097610473633, -0.002688061911612749,...
10
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "orm", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "provider_url"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.URLField"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "gf", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}}}, {"_type": "keyword", "_fields": {"arg": "unique", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "max_length", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 255}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "keep_default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "eligibility_duration"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.PositiveIntegerField"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "gf", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "keep_default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "active"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.BooleanField"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "gf", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "keep_default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}], "name": "forwards", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "orm", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "provider_url"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "eligibility_duration"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "active"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "backwards", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit.creditcourse"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "credit.crediteligibility"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "credit.creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "credit.creditrequirement"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "credit.creditrequirementstatus"}}], "values": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "Meta"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "course_key"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "enabled"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "id"}}], "values": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "object_name"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "CreditCourse"}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "xmodule_django.models.CourseKeyField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "unique"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "db_index"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "255"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.BooleanField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "False"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.AutoField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "primary_key"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}]}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "Meta"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "course"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "created"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "modified"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "provider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "username"}}], "values": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "unique_together"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "object_name"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "(('username', 'course'),)"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "CreditEligibility"}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.related.ForeignKey"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "related_name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "to"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "'eligibilities'"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "orm['credit.CreditCourse']"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoCreatedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.AutoField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "primary_key"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoLastModifiedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.related.ForeignKey"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "related_name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "to"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "'eligibilities'"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "orm['credit.CreditProvider']"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "db_index"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "255"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}]}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "Meta"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "active"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "created"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "display_name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "eligibility_duration"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "modified"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "provider_id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "provider_url"}}], "values": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "object_name"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "CreditProvider"}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.BooleanField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoCreatedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "255"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.PositiveIntegerField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [], "values": []}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.AutoField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "primary_key"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoLastModifiedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "unique"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "db_index"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "255"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.URLField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "unique"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "255"}}]}}]}}]}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "Meta"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "active"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "course"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "created"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "criteria"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "display_name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "modified"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "namespace"}}], "values": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "unique_together"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "object_name"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "(('namespace', 'name', 'course'),)"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "CreditRequirement"}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.BooleanField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.related.ForeignKey"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "related_name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "to"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "'credit_requirements'"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "orm['credit.CreditCourse']"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoCreatedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "jsonfield.fields.JSONField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [], "values": []}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "255"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.AutoField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "primary_key"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoLastModifiedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "255"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "255"}}]}}]}}]}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "Meta"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "created"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "modified"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "reason"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "requirement"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "status"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "username"}}], "values": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "object_name"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "CreditRequirementStatus"}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoCreatedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.AutoField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "primary_key"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "model_utils.fields.AutoLastModifiedField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "datetime.datetime.now"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "jsonfield.fields.JSONField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "default"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "{}"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.related.ForeignKey"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "related_name"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "to"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "'statuses'"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "orm['credit.CreditRequirement']"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "32"}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.CharField"}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "db_index"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "255"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "True"}}]}}]}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "models", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "complete_apps", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "name": "Migration", "bases": [{"_type": "Name", "_fields": {"id": "SchemaMigration", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class Migration(SchemaMigration): def forwards(self, orm): # Adding field 'CreditProvider.provider_url' db.add_column('credit_creditprovider', 'provider_url', self.gf('django.db.models.fields.URLField')(default='', unique=True, max_length=255), keep_default=False) # Adding field 'CreditProvider.eligibility_duration' db.add_column('credit_creditprovider', 'eligibility_duration', self.gf('django.db.models.fields.PositiveIntegerField')(default=0), keep_default=False) # Adding field 'CreditProvider.active' db.add_column('credit_creditprovider', 'active', self.gf('django.db.models.fields.BooleanField')(default=True), keep_default=False) def backwards(self, orm): # Deleting field 'CreditProvider.provider_url' db.delete_column('credit_creditprovider', 'provider_url') # Deleting field 'CreditProvider.eligibility_duration' db.delete_column('credit_creditprovider', 'eligibility_duration') # Deleting field 'CreditProvider.active' db.delete_column('credit_creditprovider', 'active') models = { 'credit.creditcourse': { 'Meta': {'object_name': 'CreditCourse'}, 'course_key': ('xmodule_django.models.CourseKeyField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}), 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) }, 'credit.crediteligibility': { 'Meta': {'unique_together': "(('username', 'course'),)", 'object_name': 'CreditEligibility'}, 'course': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'eligibilities'", 'to': "orm['credit.CreditCourse']"}), 'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}), 'provider': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'eligibilities'", 'to': "orm['credit.CreditProvider']"}), 'username': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}) }, 'credit.creditprovider': { 'Meta': {'object_name': 'CreditProvider'}, 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}), 'display_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'eligibility_duration': ('django.db.models.fields.PositiveIntegerField', [], {}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}), 'provider_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}), 'provider_url': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '255'}) }, 'credit.creditrequirement': { 'Meta': {'unique_together': "(('namespace', 'name', 'course'),)", 'object_name': 'CreditRequirement'}, 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'course': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'credit_requirements'", 'to': "orm['credit.CreditCourse']"}), 'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}), 'criteria': ('jsonfield.fields.JSONField', [], {}), 'display_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'namespace': ('django.db.models.fields.CharField', [], {'max_length': '255'}) }, 'credit.creditrequirementstatus': { 'Meta': {'object_name': 'CreditRequirementStatus'}, 'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}), 'reason': ('jsonfield.fields.JSONField', [], {'default': '{}'}), 'requirement': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'statuses'", 'to': "orm['credit.CreditRequirement']"}), 'status': ('django.db.models.fields.CharField', [], {'max_length': '32'}), 'username': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}) } } complete_apps = ['credit']
12,551
[ 0.052734773606061935, 0.013572458177804947, 0.052140191197395325, -0.018374843522906303, -0.014464329928159714, 0.006374596152454615, 0.022742729634046555, 0.03880785405635834, 0.015264727175235748, -0.008066865615546703, 0.05483867600560188, -0.05451851710677147, 0.008604275062680244, 0.0...
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "orm", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "provider_url"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "eligibility_duration"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "active"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "backwards", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def backwards(self, orm): # Deleting field 'CreditProvider.provider_url' db.delete_column('credit_creditprovider', 'provider_url') # Deleting field 'CreditProvider.eligibility_duration' db.delete_column('credit_creditprovider', 'eligibility_duration') # Deleting field 'CreditProvider.active' db.delete_column('credit_creditprovider', 'active')
12,552
[ 0.01824221946299076, -0.013318080455064774, 0.05606648325920105, 0.017852868884801865, 0.0048325276002287865, -0.03565993160009384, 0.02354425936937332, 0.00846837554126978, 0.023933609947562218, -0.012573733925819397, 0.014932739548385143, -0.025193272158503532, 0.020578322932124138, -0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "orm", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "provider_url"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.URLField"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "gf", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}}}, {"_type": "keyword", "_fields": {"arg": "unique", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "max_length", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 255}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "keep_default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "eligibility_duration"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.PositiveIntegerField"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "gf", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "keep_default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "credit_creditprovider"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "active"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.db.models.fields.BooleanField"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "gf", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_column", "value": {"_type": "Name", "_fields": {"id": "db", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "keep_default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}], "name": "forwards", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def forwards(self, orm): # Adding field 'CreditProvider.provider_url' db.add_column('credit_creditprovider', 'provider_url', self.gf('django.db.models.fields.URLField')(default='', unique=True, max_length=255), keep_default=False) # Adding field 'CreditProvider.eligibility_duration' db.add_column('credit_creditprovider', 'eligibility_duration', self.gf('django.db.models.fields.PositiveIntegerField')(default=0), keep_default=False) # Adding field 'CreditProvider.active' db.add_column('credit_creditprovider', 'active', self.gf('django.db.models.fields.BooleanField')(default=True), keep_default=False)
12,553
[ 0.004333648830652237, 0.0032595209777355194, -0.00865015760064125, -0.07157805562019348, 0.06604743748903275, 0.005907703191041946, 0.00670187221840024, -0.02827013097703457, -0.016180479899048805, -0.03594900295138359, 0.014500726014375687, -0.020408429205417633, 0.023699374869465828, 0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "open: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "open", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "open", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "save: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "save", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "save", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "get_valid_name: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_valid_name", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "get_valid_name", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "get_available_name: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_available_name", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "get_available_name", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "path", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "delete: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "delete", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "exists: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exists", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "exists", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "listdir: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "listdir", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "listdir", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "size: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "size", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "url", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "url", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "accessed_time: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "accessed_time", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "accessed_time", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "created_time: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "created_time", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "created_time", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "modified_time: %s"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "debug", "value": {"_type": "Name", "_fields": {"id": "slog", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "modified_time", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TestStorageMixin", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "modified_time", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "TestStorageMixin", "bases": [{"_type": "Name", "_fields": {"id": "object", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class TestStorageMixin(object): def open(self, name, *args, **kwargs): slog.debug('open: %s' % name) return super(TestStorageMixin, self).open(name, *args, **kwargs) def save(self, name, *args, **kwargs): slog.debug('save: %s' % name) return super(TestStorageMixin, self).save(name, *args, **kwargs) def get_valid_name(self, name, *args, **kwargs): slog.debug('get_valid_name: %s' % name) return super(TestStorageMixin, self).get_valid_name(name, *args, **kwargs) def get_available_name(self, name, *args, **kwargs): slog.debug('get_available_name: %s' % name) return super(TestStorageMixin, self).get_available_name(name, *args, **kwargs) def path(self, name, *args, **kwargs): # slog.debug('path: %s' % name) return super(TestStorageMixin, self).path(name, *args, **kwargs) def delete(self, name, *args, **kwargs): slog.debug('delete: %s' % name) return super(TestStorageMixin, self).delete(name, *args, **kwargs) def exists(self, name, *args, **kwargs): slog.debug('exists: %s' % name) return super(TestStorageMixin, self).exists(name, *args, **kwargs) def listdir(self, name, *args, **kwargs): slog.debug('listdir: %s' % name) return super(TestStorageMixin, self).listdir(name, *args, **kwargs) def size(self, name, *args, **kwargs): slog.debug('size: %s' % name) return super(TestStorageMixin, self).size(name, *args, **kwargs) def url(self, name, *args, **kwargs): # slog.debug('url: %s' % name) return super(TestStorageMixin, self).url(name, *args, **kwargs) def accessed_time(self, name, *args, **kwargs): slog.debug('accessed_time: %s' % name) return super(TestStorageMixin, self).accessed_time(name, *args, **kwargs) def created_time(self, name, *args, **kwargs): slog.debug('created_time: %s' % name) return super(TestStorageMixin, self).created_time(name, *args, **kwargs) def modified_time(self, name, *args, **kwargs): slog.debug('modified_time: %s' % name) return super(TestStorageMixin, self).modified_time(name, *args, **kwargs)
12,554
[ 0.012492325156927109, 0.00925894919782877, 0.008498496375977993, 0.0017008603317663074, 0.004310200456529856, 0.026354627683758736, 0.02707444503903389, -0.02147844061255455, 0.024427372962236404, -0.04871542379260063, 0.05568140745162964, 0.015673456713557243, 0.045441415160894394, 0.0100...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "already_mounted", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": false}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "Device or resource busy"}}, "targets": [{"_type": "Name", "_fields": {"id": "err_msg", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "err_msg", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ProcessExecutionError", "value": {"_type": "Name", "_fields": {"id": "processutils", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "side_effect", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "already_mounted", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mount_path", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "export_path", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "export_type", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mount_share", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "options", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mount_options", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mkdir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-p"}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mount_path", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assert_any_call", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mount"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-t"}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "export_type", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mount_options", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "export_path", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mount_path", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sentinel", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assert_any_call", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "run_as_root", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}}}], "name": "_test_mount_share", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _test_mount_share(self, mock_execute, already_mounted=False): if already_mounted: err_msg = 'Device or resource busy' mock_execute.side_effect = [ None, processutils.ProcessExecutionError(err_msg)] remotefs.mount_share( mock.sentinel.mount_path, mock.sentinel.export_path, mock.sentinel.export_type, options=[mock.sentinel.mount_options]) mock_execute.assert_any_call('mkdir', '-p', mock.sentinel.mount_path) mock_execute.assert_any_call('mount', '-t', mock.sentinel.export_type, mock.sentinel.mount_options, mock.sentinel.export_path, mock.sentinel.mount_path, run_as_root=True)
12,555
[ 0.015741661190986633, 0.010005395859479904, 0.025518568232655525, -0.05546260252594948, 0.015104299411177635, 0.04300396144390106, -0.0019812367390841246, -0.010877260006964207, 0.015801791101694107, 0.025614775717258453, 0.026480626314878464, 0.011129800230264664, 0.019806353375315666, -0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_mkdtemp", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "host"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dest"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "remove_dir", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "RsyncDriver", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rsync"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--archive"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--delete-excluded"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Venus/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "host:dest"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rsync"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--archive"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--delete"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--include"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dest"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--exclude"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "*"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Venus/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "host:"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rm"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-rf"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Venus"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_mkdtemp", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_remove_remote_dir_rsync", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_remove_remote_dir_rsync(self, mock_execute, mock_mkdtemp): remotefs.RsyncDriver().remove_dir('host', 'dest', None, None) rsync_call_args = mock.call('rsync', '--archive', '--delete-excluded', '/tmp/Venus/', 'host:dest', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[0], rsync_call_args) rsync_call_args = mock.call('rsync', '--archive', '--delete', '--include', 'dest', '--exclude', '*', '/tmp/Venus/', 'host:', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[1], rsync_call_args) rm_call_args = mock.call('rm', '-rf', '/tmp/Venus') self.assertEqual(mock_execute.mock_calls[2], rm_call_args) self.assertEqual(3, mock_execute.call_count) self.assertEqual(1, mock_mkdtemp.call_count)
12,556
[ 0.02037372626364231, 0.023867394775152206, 0.021286163479089737, -0.04970373213291168, 0.01952132023870945, 0.025260061025619507, 0.0020394737366586924, -0.0002281089109601453, 0.0002736931783147156, 0.016231749206781387, 0.030110375955700874, -0.008349986746907234, 0.03438441455364227, 0....
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_mkdtemp", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "host"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dest"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "remove_file", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "RsyncDriver", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rsync"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--archive"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--delete"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--include"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dest"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--exclude"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "*"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Mercury/"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "host:"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rm"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-rf"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Mercury"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_mkdtemp", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_remove_remote_file_rsync", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_remove_remote_file_rsync(self, mock_execute, mock_mkdtemp): remotefs.RsyncDriver().remove_file('host', 'dest', None, None) rsync_call_args = mock.call('rsync', '--archive', '--delete', '--include', 'dest', '--exclude', '*', '/tmp/Mercury/', 'host:', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[0], rsync_call_args) rm_call_args = mock.call('rm', '-rf', '/tmp/Mercury') self.assertEqual(mock_execute.mock_calls[1], rm_call_args) self.assertEqual(2, mock_execute.call_count) self.assertEqual(1, mock_mkdtemp.call_count)
12,557
[ 0.010837173089385033, 0.004793807864189148, 0.04033132642507553, -0.04023919254541397, 0.027663005515933037, 0.007520375773310661, 0.02303331159055233, 0.0012006113538518548, -0.001237320713698864, 0.022422928363084793, 0.01739014871418476, 0.038603827357292175, 0.027409639209508896, -0.05...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_mkdtemp", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "host"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dest_dir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "create_dir", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "RsyncDriver", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mkdir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-p"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Jupiter/dest_dir"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "mkdir_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "mkdir_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rsync"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--archive"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--relative"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--no-implied-dirs"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Jupiter/./dest_dir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "host:/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rm"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-rf"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Jupiter"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_mkdtemp", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_create_remote_dir_rsync", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_create_remote_dir_rsync(self, mock_execute, mock_mkdtemp): remotefs.RsyncDriver().create_dir('host', 'dest_dir', None, None) mkdir_call_args = mock.call('mkdir', '-p', '/tmp/Jupiter/dest_dir', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[0], mkdir_call_args) rsync_call_args = mock.call('rsync', '--archive', '--relative', '--no-implied-dirs', '/tmp/Jupiter/./dest_dir', 'host:/', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[1], rsync_call_args) rm_call_args = mock.call('rm', '-rf', '/tmp/Jupiter') self.assertEqual(mock_execute.mock_calls[2], rm_call_args) self.assertEqual(3, mock_execute.call_count) self.assertEqual(1, mock_mkdtemp.call_count)
12,558
[ 0.027817511931061745, 0.01929316483438015, 0.04328460618853569, -0.05186709761619568, 0.02684064209461212, -0.0032998407259583473, 0.028026839718222618, -0.0038289781659841537, -0.010483899153769016, 0.010716486722230911, 0.019700193777680397, 0.02052588202059269, 0.04507553204894066, -0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_mkdtemp", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "host"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dest_dir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "create_file", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "RsyncDriver", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mkdir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-p"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Mars/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "mkdir_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "mkdir_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "touch"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Mars/dest_dir"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "touch_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "touch_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rsync"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--archive"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--relative"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--no-implied-dirs"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Mars/./dest_dir"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "host:/"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rsync_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rm"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "-rf"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/tmp/Mars"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call", "value": {"_type": "Name", "_fields": {"id": "mock", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mock_calls", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "rm_call_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 4}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "call_count", "value": {"_type": "Name", "_fields": {"id": "mock_mkdtemp", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "test_create_remote_file_rsync", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_create_remote_file_rsync(self, mock_execute, mock_mkdtemp): remotefs.RsyncDriver().create_file('host', 'dest_dir', None, None) mkdir_call_args = mock.call('mkdir', '-p', '/tmp/Mars/', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[0], mkdir_call_args) touch_call_args = mock.call('touch', '/tmp/Mars/dest_dir', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[1], touch_call_args) rsync_call_args = mock.call('rsync', '--archive', '--relative', '--no-implied-dirs', '/tmp/Mars/./dest_dir', 'host:/', on_completion=None, on_execute=None) self.assertEqual(mock_execute.mock_calls[2], rsync_call_args) rm_call_args = mock.call('rm', '-rf', '/tmp/Mars') self.assertEqual(mock_execute.mock_calls[3], rm_call_args) self.assertEqual(4, mock_execute.call_count) self.assertEqual(1, mock_mkdtemp.call_count)
12,559
[ 0.014898223802447319, 0.011672775261104107, 0.03872845694422722, -0.047545067965984344, 0.0301426500082016, 0.023795614019036293, 0.03512795642018318, -0.01047837920486927, 0.01215168833732605, -0.0033581589814275503, 0.03535876050591469, 0.012244008481502533, 0.022722387686371803, -0.0072...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "1.2.3.4:/home/star_wars"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/home/favourite"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "copy_file", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "RsyncDriver", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "compression", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rsync"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--sparse"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "1.2.3.4:/home/star_wars"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/home/favourite"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--compress"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assert_called_once_with", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}}}], "name": "test_remote_copy_file_rsync", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_remote_copy_file_rsync(self, mock_execute): remotefs.RsyncDriver().copy_file('1.2.3.4:/home/star_wars', '/home/favourite', None, None, compression=True) mock_execute.assert_called_once_with('rsync', '--sparse', '1.2.3.4:/home/star_wars', '/home/favourite', '--compress', on_completion=None, on_execute=None)
12,560
[ 0.021540367975831032, 0.013669191859662533, 0.02736116573214531, -0.04879901558160782, 0.015229757875204086, 0.02802184410393238, 0.039777349680662155, -0.009801949374377728, 0.0318264365196228, 0.0009547076188027859, 0.03907110542058945, 0.021540367975831032, 0.024672891944646835, -0.0090...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "1.2.3.4:/home/star_wars"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/home/favourite"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "copy_file", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "RsyncDriver", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "compression", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "rsync"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--sparse"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "1.2.3.4:/home/star_wars"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/home/favourite"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assert_called_once_with", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}}}], "name": "test_remote_copy_file_rsync_without_compression", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_remote_copy_file_rsync_without_compression(self, mock_execute): remotefs.RsyncDriver().copy_file('1.2.3.4:/home/star_wars', '/home/favourite', None, None, compression=False) mock_execute.assert_called_once_with('rsync', '--sparse', '1.2.3.4:/home/star_wars', '/home/favourite', on_completion=None, on_execute=None)
12,561
[ 0.03426831215620041, 0.01155173685401678, -0.020911039784550667, -0.0313020758330822, -0.007751823402941227, -0.013007218949496746, -0.005504117347300053, -0.024945857003331184, 0.02691720612347126, 0.025166941806674004, -0.020045120269060135, -0.0020300750620663166, 0.01755790412425995, -...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "function_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "args_dict", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "args_dict", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "args_dict", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "function_name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_theme", "value": {"_type": "Name", "_fields": {"id": "document", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "args_dict", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "inherit_function_args", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def inherit_function_args(function_name, args_dict): #Allow to add args defined for an other function to the args_dict for key, value in document._theme[function_name].items(): if key not in args_dict: args_dict[key] = value return args_dict
12,562
[ 0.04249889403581619, -0.012908647768199444, 0.049305882304906845, -0.03636365011334419, 0.05418721213936806, 0.009762655012309551, 0.030631449073553085, -0.010630321688950062, 0.012751908041536808, -0.0086038988083601, 0.04818631336092949, -0.016256162896752357, 0.03228841349482536, 0.0023...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mock_execute", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "1.2.3.4:/home/SpaceOdyssey"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/home/favourite"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": true}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "copy_file", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "SshDriver", "value": {"_type": "Name", "_fields": {"id": "remotefs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "scp"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "1.2.3.4:/home/SpaceOdyssey"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "/home/favourite"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assert_called_once_with", "value": {"_type": "Name", "_fields": {"id": "mock_execute", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "on_completion", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "on_execute", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}}}], "name": "test_remote_copy_file_ssh", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_remote_copy_file_ssh(self, mock_execute): remotefs.SshDriver().copy_file('1.2.3.4:/home/SpaceOdyssey', '/home/favourite', None, None, True) mock_execute.assert_called_once_with('scp', '1.2.3.4:/home/SpaceOdyssey', '/home/favourite', on_completion=None, on_execute=None)
12,563
[ 0.052054472267627716, -0.013316260650753975, -0.00135659403167665, -0.011076707392930984, 0.014212082140147686, 0.03261273354291916, 0.000057312881835969165, 0.006434175185859203, 0.03709184005856514, 0.029513675719499588, -0.0006555988220497966, -0.04384681582450867, -0.03375066816806793, ...
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "àáâãäåçèéêë"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "aaaaaaceeee"}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_ascii", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "ìíîïñòóôõöùúûüý"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "iiiinooooouuuuy"}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_ascii", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "إ"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_ascii", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "this is à test"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "this is a test"}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_ascii", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_to_ascii", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_to_ascii(): # check some classical latin accentuated symbols a = '\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb' expected = 'aaaaaaceeee' assert_equal(strip_accents_ascii(a), expected) a = '\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf9\xfa\xfb\xfc\xfd' expected = 'iiiinooooouuuuy' assert_equal(strip_accents_ascii(a), expected) # check some arabic a = '\u0625' # halef with a hamza below expected = '' # halef has no direct ascii match assert_equal(strip_accents_ascii(a), expected) # mix letters accentuated and not a = "this is \xe0 test" expected = 'this is a test' assert_equal(strip_accents_ascii(a), expected)
12,564
[ 0.051350049674510956, -0.012143263593316078, -0.003468198934569955, -0.01784341223537922, -0.0030282035004347563, 0.04126517474651337, 0.004406043794006109, 0.011619532480835915, 0.0372701995074749, 0.026844285428524017, -0.006388306617736816, -0.03488295525312424, -0.03444448485970497, 0....
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "àáâãäåçèéêë"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "aaaaaaceeee"}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_unicode", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "ìíîïñòóôõöùúûüý"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "iiiinooooouuuuy"}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_unicode", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "إ"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "ا"}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_unicode", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "this is à test"}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "this is a test"}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "strip_accents_unicode", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_strip_accents", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_strip_accents(): # check some classical latin accentuated symbols a = '\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb' expected = 'aaaaaaceeee' assert_equal(strip_accents_unicode(a), expected) a = '\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf9\xfa\xfb\xfc\xfd' expected = 'iiiinooooouuuuy' assert_equal(strip_accents_unicode(a), expected) # check some arabic a = '\u0625' # halef with a hamza below expected = '\u0627' # simple halef assert_equal(strip_accents_unicode(a), expected) # mix letters accentuated and not a = "this is \xe0 test" expected = 'this is a test' assert_equal(strip_accents_unicode(a), expected)
12,565
[ -0.002424093661829829, 0.026673084124922752, -0.007768911775201559, -0.010211797431111336, -0.052315324544906616, -0.0024697300978004932, 0.025320101529359818, 0.015086829662322998, 0.03732513636350632, 0.05686821788549423, 0.009674899280071259, -0.05149924010038376, 0.008917872793972492, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "word"}}}}, {"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "unicode"}}}}, {"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "J'ai mangé du kangourou ce midi, c'était pas três bon."}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "ai"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mange"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "du"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "kangourou"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ce"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "midi"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "etait"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "pas"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tres"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "bon"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ai mange"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mange du"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "du kangourou"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "kangourou ce"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ce midi"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "midi etait"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "etait pas"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "pas tres"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tres bon"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_word_analyzer_unigrams_and_bigrams", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_word_analyzer_unigrams_and_bigrams(): wa = CountVectorizer(analyzer="word", strip_accents='unicode', ngram_range=(1, 2)).build_analyzer() text = "J'ai mang\xe9 du kangourou ce midi, c'\xe9tait pas tr\xeas bon." expected = ['ai', 'mange', 'du', 'kangourou', 'ce', 'midi', 'etait', 'pas', 'tres', 'bon', 'ai mange', 'mange du', 'du kangourou', 'kangourou ce', 'ce midi', 'midi etait', 'etait pas', 'pas tres', 'tres bon'] assert_equal(wa(text), expected)
12,566
[ 0.015864599496126175, 0.0329148955643177, -0.01943354122340679, -0.050178613513708115, -0.026180146262049675, -0.0074698785319924355, 0.011572383344173431, 0.007629947736859322, 0.036543119698762894, 0.06274697929620743, 0.008821571245789528, -0.026962704956531525, 0.010113978758454323, 0....
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "Vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "ascii"}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "J'ai mangé du kangourou ce midi, c'était pas três bon."}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "ai"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mange"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "du"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "kangourou"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ce"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "midi"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "etait"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "pas"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tres"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "bon"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "This is a test, really.\n\n I met Harry yesterday."}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "this"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "is"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "test"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "really"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "met"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "harry"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "yesterday"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "Vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "input", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "file"}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "This is a test with a file-like object!"}}], "func": {"_type": "Name", "_fields": {"id": "StringIO", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "this"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "is"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "test"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "with"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "file"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "like"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "object"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "Vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "preprocessor", "value": {"_type": "Name", "_fields": {"id": "uppercase", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "J'ai mangé du kangourou ce midi, c'était pas três bon."}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "AI"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "MANGE"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "DU"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "KANGOUROU"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "CE"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "MIDI"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ETAIT"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "PAS"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TRES"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "BON"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "Vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "tokenizer", "value": {"_type": "Name", "_fields": {"id": "split_tokenize", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "ascii"}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "J'ai mangé du kangourou ce midi, c'était pas três bon."}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "j'ai"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mange"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "du"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "kangourou"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ce"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "midi,"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "c'etait"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "pas"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tres"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "bon."}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "Vectorizer", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_word_analyzer_unigrams", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_word_analyzer_unigrams(): for Vectorizer in (CountVectorizer, HashingVectorizer): wa = Vectorizer(strip_accents='ascii').build_analyzer() text = ("J'ai mang\xe9 du kangourou ce midi, " "c'\xe9tait pas tr\xeas bon.") expected = ['ai', 'mange', 'du', 'kangourou', 'ce', 'midi', 'etait', 'pas', 'tres', 'bon'] assert_equal(wa(text), expected) text = "This is a test, really.\n\n I met Harry yesterday." expected = ['this', 'is', 'test', 'really', 'met', 'harry', 'yesterday'] assert_equal(wa(text), expected) wa = Vectorizer(input='file').build_analyzer() text = StringIO("This is a test with a file-like object!") expected = ['this', 'is', 'test', 'with', 'file', 'like', 'object'] assert_equal(wa(text), expected) # with custom preprocessor wa = Vectorizer(preprocessor=uppercase).build_analyzer() text = ("J'ai mang\xe9 du kangourou ce midi, " " c'\xe9tait pas tr\xeas bon.") expected = ['AI', 'MANGE', 'DU', 'KANGOUROU', 'CE', 'MIDI', 'ETAIT', 'PAS', 'TRES', 'BON'] assert_equal(wa(text), expected) # with custom tokenizer wa = Vectorizer(tokenizer=split_tokenize, strip_accents='ascii').build_analyzer() text = ("J'ai mang\xe9 du kangourou ce midi, " "c'\xe9tait pas tr\xeas bon.") expected = ["j'ai", 'mange', 'du', 'kangourou', 'ce', 'midi,', "c'etait", 'pas', 'tres', 'bon.'] assert_equal(wa(text), expected)
12,567
[ 0.023683490231633186, 0.018789220601320267, -0.004321281798183918, -0.0608321912586689, -0.047295358031988144, 0.0003407709882594645, 0.00693553825840354, 0.01742837391793728, 0.016210775822401047, 0.06532059609889984, -0.0008908167365007102, -0.02089017443358898, 0.02173771895468235, 0.01...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "unicode"}}}}, {"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "J'ai mangé du kangourou ce midi, c'était pas três bon"}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "j'a"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "'ai"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ai "}}, {"_type": "Constant", "_fields": {"kind": null, "value": "i m"}}, {"_type": "Constant", "_fields": {"kind": null, "value": " ma"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "s tres"}}, {"_type": "Constant", "_fields": {"kind": null, "value": " tres "}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tres b"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "res bo"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "es bon"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "upper": null}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "This \n\tis a test, really.\n\n I met Harry yesterday"}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "thi"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "his"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "is "}}, {"_type": "Constant", "_fields": {"kind": null, "value": "s i"}}, {"_type": "Constant", "_fields": {"kind": null, "value": " is"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": " yeste"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "yester"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "esterd"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "sterda"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "terday"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "upper": null}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "input", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "file"}}}}, {"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "This is a test with a file-like object!"}}], "func": {"_type": "Name", "_fields": {"id": "StringIO", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "thi"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "his"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "is "}}, {"_type": "Constant", "_fields": {"kind": null, "value": "s i"}}, {"_type": "Constant", "_fields": {"kind": null, "value": " is"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_char_ngram_analyzer", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_char_ngram_analyzer(): cnga = CountVectorizer(analyzer='char', strip_accents='unicode', ngram_range=(3, 6)).build_analyzer() text = "J'ai mang\xe9 du kangourou ce midi, c'\xe9tait pas tr\xeas bon" expected = ["j'a", "'ai", 'ai ', 'i m', ' ma'] assert_equal(cnga(text)[:5], expected) expected = ['s tres', ' tres ', 'tres b', 'res bo', 'es bon'] assert_equal(cnga(text)[-5:], expected) text = "This \n\tis a test, really.\n\n I met Harry yesterday" expected = ['thi', 'his', 'is ', 's i', ' is'] assert_equal(cnga(text)[:5], expected) expected = [' yeste', 'yester', 'esterd', 'sterda', 'terday'] assert_equal(cnga(text)[-5:], expected) cnga = CountVectorizer(input='file', analyzer='char', ngram_range=(3, 6)).build_analyzer() text = StringIO("This is a test with a file-like object!") expected = ['thi', 'his', 'is ', 's i', ' is'] assert_equal(cnga(text)[:5], expected)
12,568
[ 0.01275520958006382, 0.030879881232976913, -0.01964784413576126, -0.014771497808396816, -0.029411498457193375, -0.003205239539965987, 0.028469102457165718, -0.014618083834648132, 0.0464184433221817, 0.012097724713385105, 0.035065870732069016, -0.016196047887206078, -0.009725299663841724, 0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "J'ai mangé du kangourou ce midi, c'était pas três bon."}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "utf-8"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "encode", "value": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "text_bytes", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}}}, {"_type": "keyword", "_fields": {"arg": "encoding", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "ascii"}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "UnicodeDecodeError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "wa", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "text_bytes", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}}}, {"_type": "keyword", "_fields": {"arg": "encoding", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "ascii"}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ca", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "UnicodeDecodeError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ca", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "text_bytes", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_unicode_decode_error", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_unicode_decode_error(): # decode_error default to strict, so this should fail # First, encode (as bytes) a unicode string. text = "J'ai mang\xe9 du kangourou ce midi, c'\xe9tait pas tr\xeas bon." text_bytes = text.encode('utf-8') # Then let the Analyzer try to decode it as ascii. It should fail, # because we have given it an incorrect encoding. wa = CountVectorizer(ngram_range=(1, 2), encoding='ascii').build_analyzer() assert_raises(UnicodeDecodeError, wa, text_bytes) ca = CountVectorizer(analyzer='char', ngram_range=(3, 6), encoding='ascii').build_analyzer() assert_raises(UnicodeDecodeError, ca, text_bytes)
12,569
[ 0.019141854718327522, 0.02316032163798809, 0.008476076647639275, -0.02458001859486103, -0.05953105166554451, -0.004989996552467346, 0.015087295323610306, 0.014569947496056557, 0.012175711803138256, 0.06742360442876816, -0.0008662561886012554, 0.005705860909074545, 0.023172352463006973, -0....
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char_wb"}}}}, {"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "unicode"}}}}, {"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "This \n\tis a test, really.\n\n I met Harry yesterday"}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": " th"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "thi"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "his"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "is "}}, {"_type": "Constant", "_fields": {"kind": null, "value": " thi"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "yester"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "esterd"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "sterda"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "terday"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "erday "}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 5}}}}, "upper": null}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "input", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "file"}}}}, {"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char_wb"}}}}, {"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}}}]}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "A test with a file-like object!"}}], "func": {"_type": "Name", "_fields": {"id": "StringIO", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": " a "}}, {"_type": "Constant", "_fields": {"kind": null, "value": " te"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tes"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "est"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "st "}}, {"_type": "Constant", "_fields": {"kind": null, "value": " tes"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 6}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cnga", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Name", "_fields": {"id": "expected", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_char_wb_ngram_analyzer", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_char_wb_ngram_analyzer(): cnga = CountVectorizer(analyzer='char_wb', strip_accents='unicode', ngram_range=(3, 6)).build_analyzer() text = "This \n\tis a test, really.\n\n I met Harry yesterday" expected = [' th', 'thi', 'his', 'is ', ' thi'] assert_equal(cnga(text)[:5], expected) expected = ['yester', 'esterd', 'sterda', 'terday', 'erday '] assert_equal(cnga(text)[-5:], expected) cnga = CountVectorizer(input='file', analyzer='char_wb', ngram_range=(3, 6)).build_analyzer() text = StringIO("A test with a file-like object!") expected = [' a ', ' te', 'tes', 'est', 'st ', ' tes'] assert_equal(cnga(text)[:6], expected)
12,570
[ -0.02485642209649086, 0.015162905678153038, 0.0013406414072960615, -0.0509825237095356, -0.03474527224898338, 0.0084970872849226, -0.013221760280430317, 0.03210824728012085, 0.007727954536676407, 0.04841874539852142, 0.027029527351260185, -0.015797745436429977, -0.015663452446460724, 0.003...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "pizza"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "beer"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vocab", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Name", "_fields": {"id": "vocab", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "terms", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "vocab", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "typ", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "vocabulary", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "vocab", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "Mapping", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "terms", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "terms", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "iter", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "defaultdict", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "partial", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "typ", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_countvectorizer_custom_vocabulary", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_countvectorizer_custom_vocabulary(): vocab = {"pizza": 0, "beer": 1} terms = set(vocab.keys()) # Try a few of the supported types. for typ in [dict, list, iter, partial(defaultdict, int)]: v = typ(vocab) vect = CountVectorizer(vocabulary=v) vect.fit(JUNK_FOOD_DOCS) if isinstance(v, Mapping): assert_equal(vect.vocabulary_, vocab) else: assert_equal(set(vect.vocabulary_), terms) X = vect.transform(JUNK_FOOD_DOCS) assert_equal(X.shape[1], len(terms))
12,571
[ 0.026133211329579353, 0.0004416362789925188, 0.039721593260765076, 0.005733985919505358, -0.10568740963935852, 0.00543424254283309, 0.008098631165921688, 0.047026459127664566, 0.007182747591286898, 0.07815539836883545, 0.02833133190870285, -0.018384281545877457, 0.02371305786073208, 0.0110...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_params", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "stop_words", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "english"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_stop_words", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "ENGLISH_STOP_WORDS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_params", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "stop_words", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "_bad_str_stop_"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_stop_words", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_params", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "stop_words", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "_bad_unicode_stop_"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_stop_words", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "some"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "other"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "words"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "stoplist", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_params", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "stop_words", "value": {"_type": "Name", "_fields": {"id": "stoplist", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_stop_words", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "stoplist", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_countvectorizer_stop_words", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_countvectorizer_stop_words(): cv = CountVectorizer() cv.set_params(stop_words='english') assert_equal(cv.get_stop_words(), ENGLISH_STOP_WORDS) cv.set_params(stop_words='_bad_str_stop_') assert_raises(ValueError, cv.get_stop_words) cv.set_params(stop_words='_bad_unicode_stop_') assert_raises(ValueError, cv.get_stop_words) stoplist = ['some', 'other', 'words'] cv.set_params(stop_words=stoplist) assert_equal(cv.get_stop_words(), stoplist)
12,572
[ -0.012331370264291763, -0.01750447414815426, -0.01637176238000393, -0.02811926230788231, -0.029987651854753494, -0.005692749284207821, 0.00384187581948936, 0.031202103942632675, -0.015215696766972542, 0.051053743809461594, 0.02688145451247692, -0.008069107308983803, -0.021124478429555893, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "pizza"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "beer"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "what_we_like", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "count"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "vocabulary", "value": {"_type": "Name", "_fields": {"id": "what_we_like", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "tfidf"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}]}}], "func": {"_type": "Name", "_fields": {"id": "Pipeline", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pipe", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "pipe", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "count"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "named_steps", "value": {"_type": "Name", "_fields": {"id": "pipe", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "what_we_like", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "what_we_like", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_countvectorizer_custom_vocabulary_pipeline", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_countvectorizer_custom_vocabulary_pipeline(): what_we_like = ["pizza", "beer"] pipe = Pipeline([ ('count', CountVectorizer(vocabulary=what_we_like)), ('tfidf', TfidfTransformer())]) X = pipe.fit_transform(ALL_FOOD_DOCS) assert_equal(set(pipe.named_steps['count'].vocabulary_), set(what_we_like)) assert_equal(X.shape[1], len(what_we_like))
12,573
[ 0.009146241471171379, 0.002966348547488451, -0.007397783920168877, -0.030676385387778282, -0.018087491393089294, 0.02262142114341259, -0.006463263183832169, 0.040708914399147034, -0.01596522517502308, 0.08103195577859879, 0.01891951635479927, -0.03754962980747223, -0.0037380815483629704, -...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "vocabulary", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "foo"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "we shouldn't get here"}}, "test": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "empty vocabulary"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_in", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "e", "type": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}}}, {"_type": "keyword", "_fields": {"arg": "stop_words", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "english"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "to be or not to be"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "and me too"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "and so do you"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "we shouldn't get here"}}, "test": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "empty vocabulary"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_in", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "e", "type": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "test_countvectorizer_empty_vocabulary", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_countvectorizer_empty_vocabulary(): try: vect = CountVectorizer(vocabulary=[]) vect.fit(["foo"]) assert False, "we shouldn't get here" except ValueError as e: assert_in("empty vocabulary", str(e).lower()) try: v = CountVectorizer(max_df=1.0, stop_words="english") # fit on stopwords only v.fit(["to be or not to be", "and me too", "and so do you"]) assert False, "we shouldn't get here" except ValueError as e: assert_in("empty vocabulary", str(e).lower())
12,574
[ 0.014914672821760178, -0.00711143808439374, -0.008459855802357197, 0.009526864625513554, 0.0030251459684222937, -0.02790638618171215, -0.003848853288218379, 0.0018995102727785707, 0.032713789492845535, 0.09192691743373871, 0.027038708329200745, 0.027132511138916016, -0.03895168751478195, 0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "smooth_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l2"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "all", "value": {"_type": "Compare", "_fields": {"ops": [{"_type": "GtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sum", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "axis", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "smooth_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l2"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "all", "value": {"_type": "Compare", "_fields": {"ops": [{"_type": "GtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_tf_idf_smoothing", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_tf_idf_smoothing(): X = [[1, 1, 1], [1, 1, 0], [1, 0, 0]] tr = TfidfTransformer(smooth_idf=True, norm='l2') tfidf = tr.fit_transform(X).toarray() assert_true((tfidf >= 0).all()) # check normalization assert_array_almost_equal((tfidf ** 2).sum(axis=1), [1., 1., 1.]) # this is robust to features with only zeros X = [[1, 1, 0], [1, 1, 0], [1, 0, 0]] tr = TfidfTransformer(smooth_idf=True, norm='l2') tfidf = tr.fit_transform(X).toarray() assert_true((tfidf >= 0).all())
12,575
[ 0.016818156465888023, -0.0007335658301599324, -0.030807536095380783, 0.011564712040126324, -0.004516536835581064, -0.029642745852470398, -0.00038702561869286, 0.012681960128247738, 0.01861288584768772, 0.10839688777923584, 0.02169126272201538, 0.016247646883130074, -0.02731316350400448, 0....
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "smooth_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l2"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "all", "value": {"_type": "Compare", "_fields": {"ops": [{"_type": "GtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sum", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "axis", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "smooth_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l2"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "clean_warning_registry", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "With", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.0}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "w", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "numpy_provides_div0_warning", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "catch_warnings", "value": {"_type": "Name", "_fields": {"id": "warnings", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "record", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "optional_vars": {"_type": "Name", "_fields": {"id": "w", "ctx": {"_type": "Store", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "divide by zero"}}, "targets": [{"_type": "Name", "_fields": {"id": "in_warning_message", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "RuntimeWarning", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "in_warning_message", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_warns_message", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Numpy does not provide div 0 warnings."}}], "func": {"_type": "Name", "_fields": {"id": "SkipTest", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "numpy_provides_div0_warning", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}], "name": "test_tfidf_no_smoothing", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_tfidf_no_smoothing(): X = [[1, 1, 1], [1, 1, 0], [1, 0, 0]] tr = TfidfTransformer(smooth_idf=False, norm='l2') tfidf = tr.fit_transform(X).toarray() assert_true((tfidf >= 0).all()) # check normalization assert_array_almost_equal((tfidf ** 2).sum(axis=1), [1., 1., 1.]) # the lack of smoothing make IDF fragile in the presence of feature with # only zeros X = [[1, 1, 0], [1, 1, 0], [1, 0, 0]] tr = TfidfTransformer(smooth_idf=False, norm='l2') clean_warning_registry() with warnings.catch_warnings(record=True) as w: 1. / np.array([0.]) numpy_provides_div0_warning = len(w) == 1 in_warning_message = 'divide by zero' tfidf = assert_warns_message(RuntimeWarning, in_warning_message, tr.fit_transform, X).toarray() if not numpy_provides_div0_warning: raise SkipTest("Numpy does not provide div 0 warnings.")
12,576
[ -0.022283246740698814, -0.016786474734544754, 0.01746172457933426, -0.027768170461058617, 0.03499452769756317, -0.00646225968375802, 0.016146764159202576, -0.0033110936637967825, 0.00873086228966713, 0.0623125322163105, 0.002090905327349901, 0.031085187569260597, -0.01848052255809307, 0.03...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "sublinear_tf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "use_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "tr", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_greater", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_greater", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "assert_less", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}], "func": {"_type": "Name", "_fields": {"id": "assert_less", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_sublinear_tf", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_sublinear_tf(): X = [[1], [2], [3]] tr = TfidfTransformer(sublinear_tf=True, use_idf=False, norm=None) tfidf = tr.fit_transform(X).toarray() assert_equal(tfidf[0], 1) assert_greater(tfidf[1], tfidf[0]) assert_greater(tfidf[2], tfidf[1]) assert_less(tfidf[1], 2) assert_less(tfidf[2], 3)
12,577
[ 0.002754868706688285, -0.01385047659277916, -0.03300203010439873, -0.013500831089913845, -0.00467509962618351, -0.03469386324286461, 0.02682119980454445, 0.014651277102530003, 0.035911984741687775, 0.06262039393186569, -0.0016467178938910365, 0.025580521672964096, -0.01473022997379303, 0.0...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l2"}}}}, {"_type": "keyword", "_fields": {"arg": "use_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "smooth_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "sublinear_tf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "norm", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "norm", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_tfidf", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "use_idf", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "use_idf", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_tfidf", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "smooth_idf", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "smooth_idf", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_tfidf", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sublinear_tf", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sublinear_tf", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_tfidf", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_tfidf_vectorizer_setters", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_tfidf_vectorizer_setters(): tv = TfidfVectorizer(norm='l2', use_idf=False, smooth_idf=False, sublinear_tf=False) tv.norm = 'l1' assert_equal(tv._tfidf.norm, 'l1') tv.use_idf = True assert_true(tv._tfidf.use_idf) tv.smooth_idf = True assert_true(tv._tfidf.smooth_idf) tv.sublinear_tf = True assert_true(tv._tfidf.sublinear_tf)
12,578
[ -0.014002057723701, 0.026689928025007248, -0.017060527577996254, -0.044706229120492935, -0.0006387991015799344, 0.0024357247166335583, 0.009265013039112091, 0.0163675919175148, 0.004420444834977388, 0.05380995571613312, 0.02955724485218525, 0.015507398173213005, 0.0031570338178426027, -0.0...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "value": {"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "iter", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "value": {"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Name", "_fields": {"id": "n_train", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.5}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "tocsr", "value": {"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tocsr"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "pizza"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "vocabulary", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "v2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "tocsr", "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tocsr"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "salad"}}, "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "tomato"}}, "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "water"}}, "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "the"}}, "comparators": [{"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_false", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "copyright"}}, "comparators": [{"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_false", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "coke"}}, "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "burger"}}, "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "beer"}}, "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "pizza"}}, "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "value": {"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "v2", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "t1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "t1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "idf_", "value": {"_type": "Name", "_fields": {"id": "t1", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "n_train", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_test", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "t1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf_test", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "tfidf_test", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}}}, {"_type": "keyword", "_fields": {"arg": "use_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "t2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "t2", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "idf_", "value": {"_type": "Name", "_fields": {"id": "t2", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "use_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "t3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "t3", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "counts_train", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 5}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "t3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "X_incompt", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "t3", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "X_incompt", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sum", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "axis", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}]}}, "right": {"_type": "Name", "_fields": {"id": "n_train", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "value": {"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "iter", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max_df", "value": {"_type": "Name", "_fields": {"id": "v1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "max_df", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fixed_vocabulary_", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_false", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tfidf", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tfidf2", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "tv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tfidf_test2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tfidf_test", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tfidf_test2", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "vocabulary", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_params", "value": {"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "ascii"}}}}, {"_type": "keyword", "_fields": {"arg": "lowercase", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_preprocessor", "value": {"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "strip_accents_ascii", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_params", "value": {"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "_gabbledegook_"}}}}, {"_type": "keyword", "_fields": {"arg": "preprocessor", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_preprocessor", "value": {"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "_invalid_analyzer_type_"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "set_params", "value": {"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Name", "_fields": {"id": "v3", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_vectorizer", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer(): # raw documents as an iterator train_data = iter(ALL_FOOD_DOCS[:-1]) test_data = [ALL_FOOD_DOCS[-1]] n_train = len(ALL_FOOD_DOCS) - 1 # test without vocabulary v1 = CountVectorizer(max_df=0.5) counts_train = v1.fit_transform(train_data) if hasattr(counts_train, 'tocsr'): counts_train = counts_train.tocsr() assert_equal(counts_train[0, v1.vocabulary_["pizza"]], 2) # build a vectorizer v1 with the same vocabulary as the one fitted by v1 v2 = CountVectorizer(vocabulary=v1.vocabulary_) # compare that the two vectorizer give the same output on the test sample for v in (v1, v2): counts_test = v.transform(test_data) if hasattr(counts_test, 'tocsr'): counts_test = counts_test.tocsr() vocabulary = v.vocabulary_ assert_equal(counts_test[0, vocabulary["salad"]], 1) assert_equal(counts_test[0, vocabulary["tomato"]], 1) assert_equal(counts_test[0, vocabulary["water"]], 1) # stop word from the fixed list assert_false("the" in vocabulary) # stop word found automatically by the vectorizer DF thresholding # words that are high frequent across the complete corpus are likely # to be not informative (either real stop words of extraction # artifacts) assert_false("copyright" in vocabulary) # not present in the sample assert_equal(counts_test[0, vocabulary["coke"]], 0) assert_equal(counts_test[0, vocabulary["burger"]], 0) assert_equal(counts_test[0, vocabulary["beer"]], 0) assert_equal(counts_test[0, vocabulary["pizza"]], 0) # test tf-idf t1 = TfidfTransformer(norm='l1') tfidf = t1.fit(counts_train).transform(counts_train).toarray() assert_equal(len(t1.idf_), len(v1.vocabulary_)) assert_equal(tfidf.shape, (n_train, len(v1.vocabulary_))) # test tf-idf with new data tfidf_test = t1.transform(counts_test).toarray() assert_equal(tfidf_test.shape, (len(test_data), len(v1.vocabulary_))) # test tf alone t2 = TfidfTransformer(norm='l1', use_idf=False) tf = t2.fit(counts_train).transform(counts_train).toarray() assert_equal(t2.idf_, None) # test idf transform with unlearned idf vector t3 = TfidfTransformer(use_idf=True) assert_raises(ValueError, t3.transform, counts_train) # test idf transform with incompatible n_features X = [[1, 1, 5], [1, 1, 0]] t3.fit(X) X_incompt = [[1, 3], [1, 3]] assert_raises(ValueError, t3.transform, X_incompt) # L1-normalized term frequencies sum to one assert_array_almost_equal(np.sum(tf, axis=1), [1.0] * n_train) # test the direct tfidf vectorizer # (equivalent to term count vectorizer + tfidf transformer) train_data = iter(ALL_FOOD_DOCS[:-1]) tv = TfidfVectorizer(norm='l1') tv.max_df = v1.max_df tfidf2 = tv.fit_transform(train_data).toarray() assert_false(tv.fixed_vocabulary_) assert_array_almost_equal(tfidf, tfidf2) # test the direct tfidf vectorizer with new data tfidf_test2 = tv.transform(test_data).toarray() assert_array_almost_equal(tfidf_test, tfidf_test2) # test transform on unfitted vectorizer with empty vocabulary v3 = CountVectorizer(vocabulary=None) assert_raises(ValueError, v3.transform, train_data) # ascii preprocessor? v3.set_params(strip_accents='ascii', lowercase=False) assert_equal(v3.build_preprocessor(), strip_accents_ascii) # error on bad strip_accents param v3.set_params(strip_accents='_gabbledegook_', preprocessor=None) assert_raises(ValueError, v3.build_preprocessor) # error with bad analyzer type v3.set_params = '_invalid_analyzer_type_' assert_raises(ValueError, v3.build_analyzer)
12,579
[ -0.02306770719587803, 0.04128031060099602, -0.008155612275004387, -0.008430655114352703, 0.015964431688189507, -0.0228046216070652, 0.00868178065866232, 0.04393507167696953, 0.013273796997964382, 0.028652267530560493, 0.026284510269761086, 0.012257334776222706, -0.026451926678419113, 0.013...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "nnz", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "token_nnz", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "n_features", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "min", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "min", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "norm", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "linalg", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}], "func": {"_type": "Name", "_fields": {"id": "assert_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}}}, {"_type": "keyword", "_fields": {"arg": "non_negative", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "n_features", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "nnz", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "ngrams_nnz", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "ngrams_nnz", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "token_nnz", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "ngrams_nnz", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "right": {"_type": "Name", "_fields": {"id": "token_nnz", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "min", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "norm", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "linalg", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}], "func": {"_type": "Name", "_fields": {"id": "assert_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_hashing_vectorizer", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_hashing_vectorizer(): v = HashingVectorizer() X = v.transform(ALL_FOOD_DOCS) token_nnz = X.nnz assert_equal(X.shape, (len(ALL_FOOD_DOCS), v.n_features)) assert_equal(X.dtype, v.dtype) # By default the hashed values receive a random sign and l2 normalization # makes the feature values bounded assert_true(np.min(X.data) > -1) assert_true(np.min(X.data) < 0) assert_true(np.max(X.data) > 0) assert_true(np.max(X.data) < 1) # Check that the rows are normalized for i in range(X.shape[0]): assert_almost_equal(np.linalg.norm(X[0].data, 2), 1.0) # Check vectorization with some non-default parameters v = HashingVectorizer(ngram_range=(1, 2), non_negative=True, norm='l1') X = v.transform(ALL_FOOD_DOCS) assert_equal(X.shape, (len(ALL_FOOD_DOCS), v.n_features)) assert_equal(X.dtype, v.dtype) # ngrams generate more non zeros ngrams_nnz = X.nnz assert_true(ngrams_nnz > token_nnz) assert_true(ngrams_nnz < 2 * token_nnz) # makes the feature values bounded assert_true(np.min(X.data) > 0) assert_true(np.max(X.data) < 1) # Check that the rows are normalized for i in range(X.shape[0]): assert_almost_equal(np.linalg.norm(X[0].data, 1), 1.0)
12,580
[ -0.004701066296547651, 0.01813352480530739, 0.025393996387720108, -0.017745202407240868, -0.03205433115363121, -0.030548106878995895, -0.01713329739868641, 0.013108856044709682, 0.021910851821303368, 0.04975246265530586, 0.042974453419446945, -0.024382000789046288, -0.009355063550174236, -...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.5}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_feature_names", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raises", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "n_samples", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "n_features", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "n_features", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_feature_names", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "feature_names", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "feature_names", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "n_features", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "beer"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "burger"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "celeri"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "coke"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "pizza"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "salad"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "sparkling"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "tomato"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "water"}}]}}, {"_type": "Name", "_fields": {"id": "feature_names", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "idx", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "cv", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "feature_names", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "idx", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}], "name": "test_feature_names", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_feature_names(): cv = CountVectorizer(max_df=0.5) # test for Value error on unfitted/empty vocabulary assert_raises(ValueError, cv.get_feature_names) X = cv.fit_transform(ALL_FOOD_DOCS) n_samples, n_features = X.shape assert_equal(len(cv.vocabulary_), n_features) feature_names = cv.get_feature_names() assert_equal(len(feature_names), n_features) assert_array_equal(['beer', 'burger', 'celeri', 'coke', 'pizza', 'salad', 'sparkling', 'tomato', 'water'], feature_names) for idx, name in enumerate(feature_names): assert_equal(idx, cv.vocabulary_.get(name))
12,581
[ 0.002065367763862014, 0.03058013506233692, 0.047308556735515594, -0.04344071447849274, -0.039427828043699265, -0.010388785041868687, 0.014987892471253872, -0.025140982121229172, 0.011470573022961617, 0.05690564587712288, 0.034302935004234314, -0.04259462282061577, -0.03084605000913143, 0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "max_features", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "cv_1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "max_features", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "cv_3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "max_features", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "cv_None", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sum", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "cv_1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "axis", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "counts_1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sum", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "cv_3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "axis", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "counts_3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sum", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "cv_None", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "axis", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "counts_None", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_feature_names", "value": {"_type": "Name", "_fields": {"id": "cv_1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "features_1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_feature_names", "value": {"_type": "Name", "_fields": {"id": "cv_3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "features_3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_feature_names", "value": {"_type": "Name", "_fields": {"id": "cv_None", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "features_None", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 7}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "counts_1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 7}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "counts_3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 7}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "counts_None", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "the"}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_1", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "argmax", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "value": {"_type": "Name", "_fields": {"id": "features_1", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "the"}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_3", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "argmax", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "value": {"_type": "Name", "_fields": {"id": "features_3", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "the"}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "counts_None", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "argmax", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "value": {"_type": "Name", "_fields": {"id": "features_None", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_count_vectorizer_max_features", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_count_vectorizer_max_features(): # Regression test: max_features didn't work correctly in 0.14. cv_1 = CountVectorizer(max_features=1) cv_3 = CountVectorizer(max_features=3) cv_None = CountVectorizer(max_features=None) counts_1 = cv_1.fit_transform(JUNK_FOOD_DOCS).sum(axis=0) counts_3 = cv_3.fit_transform(JUNK_FOOD_DOCS).sum(axis=0) counts_None = cv_None.fit_transform(JUNK_FOOD_DOCS).sum(axis=0) features_1 = cv_1.get_feature_names() features_3 = cv_3.get_feature_names() features_None = cv_None.get_feature_names() # The most common feature is "the", with frequency 7. assert_equal(7, counts_1.max()) assert_equal(7, counts_3.max()) assert_equal(7, counts_None.max()) # The most common feature should be the same assert_equal("the", features_1[np.argmax(counts_1)]) assert_equal("the", features_3[np.argmax(counts_3)]) assert_equal("the", features_None[np.argmax(counts_None)])
12,582
[ 0.0008423668332397938, 0.017593516036868095, -0.009018280543386936, -0.049527671188116074, -0.04754563048481941, 0.004369231406599283, 0.0012431468348950148, 0.019867032766342163, 0.0046898555010557175, 0.04024706408381462, 0.041692785918712616, -0.024484017863869667, -0.016345996409654617, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vec_factories", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "burger"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "beer"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "salad"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "pizza"}}]}}], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "expected_vocabulary", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": "u", "value": "celeri"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "tomato"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "copyright"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "coke"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "sparkling"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "water"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "the"}}]}}], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "expected_stop_words", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "vec_factory", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.6}}}}, {"_type": "keyword", "_fields": {"arg": "max_features", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 4}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "expected_vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "expected_stop_words", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "vec_factories", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "vec_factory", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_vectorizer_max_features", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer_max_features(): vec_factories = ( CountVectorizer, TfidfVectorizer, ) expected_vocabulary = set(['burger', 'beer', 'salad', 'pizza']) expected_stop_words = set([u'celeri', u'tomato', u'copyright', u'coke', u'sparkling', u'water', u'the']) for vec_factory in vec_factories: # test bounded number of extracted features vectorizer = vec_factory(max_df=0.6, max_features=4) vectorizer.fit(ALL_FOOD_DOCS) assert_equal(set(vectorizer.vocabulary_), expected_vocabulary) assert_equal(vectorizer.stop_words_, expected_stop_words)
12,583
[ 0.021736737340688705, 0.01714584045112133, 0.008305016905069351, -0.023380693048238754, -0.0227474644780159, 0.03835894912481308, 0.002703392645344138, 0.022601336240768433, -0.013407365418970585, 0.056746888905763626, 0.04868542030453682, 0.006350536830723286, -0.008865179494023323, -0.00...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "abc"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dea"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "eat"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 6}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.5}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "max_df", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 4}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "max_df", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 4}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_vectorizer_max_df", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer_max_df(): test_data = ['abc', 'dea', 'eat'] vect = CountVectorizer(analyzer='char', max_df=1.0) vect.fit(test_data) assert_true('a' in vect.vocabulary_.keys()) assert_equal(len(vect.vocabulary_.keys()), 6) assert_equal(len(vect.stop_words_), 0) vect.max_df = 0.5 # 0.5 * 3 documents -> max_doc_count == 1.5 vect.fit(test_data) assert_true('a' not in vect.vocabulary_.keys()) # {ae} ignored assert_equal(len(vect.vocabulary_.keys()), 4) # {bcdt} remain assert_true('a' in vect.stop_words_) assert_equal(len(vect.stop_words_), 2) vect.max_df = 1 vect.fit(test_data) assert_true('a' not in vect.vocabulary_.keys()) # {ae} ignored assert_equal(len(vect.vocabulary_.keys()), 4) # {bcdt} remain assert_true('a' in vect.stop_words_) assert_equal(len(vect.stop_words_), 2)
12,584
[ -0.004117670468986034, 0.011277387849986553, -0.0007112753228284419, -0.03034774772822857, -0.01753721758723259, 0.03517138957977295, 0.00778691191226244, 0.039170894771814346, -0.013246839866042137, 0.06728861480951309, 0.045473143458366394, -0.0017285732319578528, -0.004929691087454557, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "abc"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dea"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "eat"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "min_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 6}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "min_df", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "c"}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "c"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 4}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.8}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "min_df", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "c"}}, "comparators": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "c"}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 5}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_vectorizer_min_df", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer_min_df(): test_data = ['abc', 'dea', 'eat'] vect = CountVectorizer(analyzer='char', min_df=1) vect.fit(test_data) assert_true('a' in vect.vocabulary_.keys()) assert_equal(len(vect.vocabulary_.keys()), 6) assert_equal(len(vect.stop_words_), 0) vect.min_df = 2 vect.fit(test_data) assert_true('c' not in vect.vocabulary_.keys()) # {bcdt} ignored assert_equal(len(vect.vocabulary_.keys()), 2) # {ae} remain assert_true('c' in vect.stop_words_) assert_equal(len(vect.stop_words_), 4) vect.min_df = 0.8 # 0.8 * 3 documents -> min_doc_count == 2.4 vect.fit(test_data) assert_true('c' not in vect.vocabulary_.keys()) # {bcdet} ignored assert_equal(len(vect.vocabulary_.keys()), 1) # {a} remains assert_true('c' in vect.stop_words_) assert_equal(len(vect.stop_words_), 5)
12,585
[ 0.02320619858801365, 0.015106244012713432, 0.024561885744333267, -0.002091918606311083, -0.008635394275188446, 0.03217196837067604, 0.03697953745722771, -0.010657534934580326, 0.019013816490769386, 0.07924512028694153, 0.018763184547424316, -0.011426517739892006, 0.04069343954324722, 0.017...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "aaabc"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "abbde"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "a"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "b"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "c"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "d"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "e"}}]}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_feature_names", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}]}}, {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}}}, {"_type": "keyword", "_fields": {"arg": "binary", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}]}}, {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "max_df", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}}}, {"_type": "keyword", "_fields": {"arg": "binary", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X_sparse", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "X_sparse", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_count_binary_occurrences", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_count_binary_occurrences(): # by default multiple occurrences are counted as longs test_data = ['aaabc', 'abbde'] vect = CountVectorizer(analyzer='char', max_df=1.0) X = vect.fit_transform(test_data).toarray() assert_array_equal(['a', 'b', 'c', 'd', 'e'], vect.get_feature_names()) assert_array_equal([[3, 1, 1, 0, 0], [1, 2, 0, 1, 1]], X) # using boolean features, we can fetch the binary occurrence info # instead. vect = CountVectorizer(analyzer='char', max_df=1.0, binary=True) X = vect.fit_transform(test_data).toarray() assert_array_equal([[1, 1, 1, 0, 0], [1, 1, 0, 1, 1]], X) # check the ability to change the dtype vect = CountVectorizer(analyzer='char', max_df=1.0, binary=True, dtype=np.float32) X_sparse = vect.fit_transform(test_data) assert_equal(X_sparse.dtype, np.float32)
12,586
[ 0.008281857706606388, 0.025379696860909462, 0.05667584389448166, -0.021012792363762856, -0.0018973143305629492, 0.009150543250143528, 0.030028337612748146, 0.013124191202223301, 0.019592374563217163, 0.05451587215065956, 0.028314445167779922, 0.005156351253390312, 0.03120223619043827, 0.00...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "aaabc"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "abbde"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "non_negative", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float64", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "non_negative", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "binary", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float64", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "non_negative", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "binary", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float64", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float64", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_hashed_binary_occurrences", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_hashed_binary_occurrences(): # by default multiple occurrences are counted as longs test_data = ['aaabc', 'abbde'] vect = HashingVectorizer(analyzer='char', non_negative=True, norm=None) X = vect.transform(test_data) assert_equal(np.max(X[0:1].data), 3) assert_equal(np.max(X[1:2].data), 2) assert_equal(X.dtype, np.float64) # using boolean features, we can fetch the binary occurrence info # instead. vect = HashingVectorizer(analyzer='char', non_negative=True, binary=True, norm=None) X = vect.transform(test_data) assert_equal(np.max(X.data), 1) assert_equal(X.dtype, np.float64) # check the ability to change the dtype vect = HashingVectorizer(analyzer='char', non_negative=True, binary=True, norm=None, dtype=np.float64) X = vect.transform(test_data) assert_equal(X.dtype, np.float64)
12,587
[ -0.0064145768992602825, 0.026705089956521988, 0.02466021478176117, -0.028311775997281075, -0.00974358431994915, -0.01711365394294262, -0.028579557314515114, 0.0047531165182590485, -0.0029395073652267456, 0.03249889984726906, 0.05584455281496048, -0.06567942351102829, -0.018294325098395348, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "NOTJUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "NOTJUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "target", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "train_test_split", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "test_size", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.2}}}}, {"_type": "keyword", "_fields": {"arg": "random_state", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_train", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_test", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "vect"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "svc"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "LinearSVC", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}]}}], "func": {"_type": "Name", "_fields": {"id": "Pipeline", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pipeline", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "vect__ngram_range"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "svc__loss"}}], "values": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "hinge"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "squared_hinge"}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "parameters", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "pipeline", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parameters", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "GridSearchCV", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "n_jobs", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "predict", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_train", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pred", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "pred", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_test", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "best_score_", "value": {"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "vect"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "named_steps", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "best_estimator_", "value": {"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "best_vectorizer", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ngram_range", "value": {"_type": "Name", "_fields": {"id": "best_vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_count_vectorizer_pipeline_grid_selection", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_count_vectorizer_pipeline_grid_selection(): # raw documents data = JUNK_FOOD_DOCS + NOTJUNK_FOOD_DOCS # label junk food as -1, the others as +1 target = [-1] * len(JUNK_FOOD_DOCS) + [1] * len(NOTJUNK_FOOD_DOCS) # split the dataset for model development and final evaluation train_data, test_data, target_train, target_test = train_test_split( data, target, test_size=.2, random_state=0) pipeline = Pipeline([('vect', CountVectorizer()), ('svc', LinearSVC())]) parameters = { 'vect__ngram_range': [(1, 1), (1, 2)], 'svc__loss': ('hinge', 'squared_hinge') } # find the best parameters for both the feature extraction and the # classifier grid_search = GridSearchCV(pipeline, parameters, n_jobs=1) # Check that the best model found by grid search is 100% correct on the # held out evaluation set. pred = grid_search.fit(train_data, target_train).predict(test_data) assert_array_equal(pred, target_test) # on this toy dataset bigram representation which is used in the last of # the grid_search is considered the best estimator since they all converge # to 100% accuracy models assert_equal(grid_search.best_score_, 1.0) best_vectorizer = grid_search.best_estimator_.named_steps['vect'] assert_equal(best_vectorizer.ngram_range, (1, 1))
12,588
[ 0.006466451566666365, 0.023104211315512657, 0.0005820801015943289, -0.022342784330248833, 0.015808144584298134, -0.029047891497612, -0.004429348744452, 0.006267571356147528, 0.019978949800133705, 0.03813956305384636, 0.0405261255800724, -0.004489012993872166, 0.0023624140303581953, -0.0085...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "transformed_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "transformed_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "inverse_transform", "value": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "inversed_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "build_analyzer", "value": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "analyze", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "doc", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "analyze", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "unique", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "terms", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inversed_terms", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "unique", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "inversed_terms", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "terms", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inversed_terms", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inversed_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "zip", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "doc", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inversed_terms", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Name", "_fields": {"id": "transformed_data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "transformed_data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "transformed_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "inverse_transform", "value": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "inversed_data2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "terms", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "terms2", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inversed_data", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inversed_data2", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "zip", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "terms", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "terms2", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}], "iter": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "vectorizer", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_vectorizer_inverse_transform", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer_inverse_transform(): # raw documents data = ALL_FOOD_DOCS for vectorizer in (TfidfVectorizer(), CountVectorizer()): transformed_data = vectorizer.fit_transform(data) inversed_data = vectorizer.inverse_transform(transformed_data) analyze = vectorizer.build_analyzer() for doc, inversed_terms in zip(data, inversed_data): terms = np.sort(np.unique(analyze(doc))) inversed_terms = np.sort(np.unique(inversed_terms)) assert_array_equal(terms, inversed_terms) # Test that inverse_transform also works with numpy arrays transformed_data = transformed_data.toarray() inversed_data2 = vectorizer.inverse_transform(transformed_data) for terms, terms2 in zip(inversed_data, inversed_data2): assert_array_equal(np.sort(terms), np.sort(terms2))
12,589
[ -0.0032772275153547525, 0.01560351625084877, 0.034337520599365234, -0.029568418860435486, -0.008511008694767952, -0.027562951669096947, -0.02398001216351986, 0.0000950571775319986, -0.006316000130027533, 0.0318429134786129, 0.027856435626745224, -0.05977271869778633, -0.018819602206349373, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "NOTJUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "NOTJUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "target", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "train_test_split", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "test_size", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.1}}}}, {"_type": "keyword", "_fields": {"arg": "random_state", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_train", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_test", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "vect"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "svc"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "LinearSVC", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}]}}], "func": {"_type": "Name", "_fields": {"id": "Pipeline", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pipeline", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "vect__ngram_range"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "vect__norm"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "svc__loss"}}], "values": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "l2"}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "hinge"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "squared_hinge"}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "parameters", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "pipeline", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parameters", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "GridSearchCV", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "n_jobs", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "test_data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "predict", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "train_data", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_train", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pred", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "pred", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target_test", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "best_score_", "value": {"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "vect"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "named_steps", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "best_estimator_", "value": {"_type": "Name", "_fields": {"id": "grid_search", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "best_vectorizer", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ngram_range", "value": {"_type": "Name", "_fields": {"id": "best_vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "norm", "value": {"_type": "Name", "_fields": {"id": "best_vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "l2"}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fixed_vocabulary_", "value": {"_type": "Name", "_fields": {"id": "best_vectorizer", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_false", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_vectorizer_pipeline_grid_selection", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer_pipeline_grid_selection(): # raw documents data = JUNK_FOOD_DOCS + NOTJUNK_FOOD_DOCS # label junk food as -1, the others as +1 target = [-1] * len(JUNK_FOOD_DOCS) + [1] * len(NOTJUNK_FOOD_DOCS) # split the dataset for model development and final evaluation train_data, test_data, target_train, target_test = train_test_split( data, target, test_size=.1, random_state=0) pipeline = Pipeline([('vect', TfidfVectorizer()), ('svc', LinearSVC())]) parameters = { 'vect__ngram_range': [(1, 1), (1, 2)], 'vect__norm': ('l1', 'l2'), 'svc__loss': ('hinge', 'squared_hinge'), } # find the best parameters for both the feature extraction and the # classifier grid_search = GridSearchCV(pipeline, parameters, n_jobs=1) # Check that the best model found by grid search is 100% correct on the # held out evaluation set. pred = grid_search.fit(train_data, target_train).predict(test_data) assert_array_equal(pred, target_test) # on this toy dataset bigram representation which is used in the last of # the grid_search is considered the best estimator since they all converge # to 100% accuracy models assert_equal(grid_search.best_score_, 1.0) best_vectorizer = grid_search.best_estimator_.named_steps['vect'] assert_equal(best_vectorizer.ngram_range, (1, 1)) assert_equal(best_vectorizer.norm, 'l2') assert_false(best_vectorizer.fixed_vocabulary_)
12,590
[ 0.033253252506256104, 0.018153812736272812, 0.06630945205688477, -0.03640615567564964, 0.007094027474522591, -0.005591473076492548, 0.012919505126774311, 0.007346505764871836, 0.007198713719844818, 0.020678596571087837, 0.006355066318064928, -0.044436197727918625, -0.009674233384430408, 0....
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "NOTJUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "NOTJUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "target", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "vect"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "svc"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "LinearSVC", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}]}}], "func": {"_type": "Name", "_fields": {"id": "Pipeline", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pipeline", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "pipeline", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "target", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "cross_val_score", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "cv", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "cv_scores", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cv_scores", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_vectorizer_pipeline_cross_validation", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer_pipeline_cross_validation(): # raw documents data = JUNK_FOOD_DOCS + NOTJUNK_FOOD_DOCS # label junk food as -1, the others as +1 target = [-1] * len(JUNK_FOOD_DOCS) + [1] * len(NOTJUNK_FOOD_DOCS) pipeline = Pipeline([('vect', TfidfVectorizer()), ('svc', LinearSVC())]) cv_scores = cross_val_score(pipeline, data, target, cv=3) assert_array_equal(cv_scores, [1., 1., 1.])
12,591
[ -0.009391912259161472, 0.021944621577858925, -0.003405096009373665, -0.026227382943034172, -0.008366462774574757, -0.006852416321635246, 0.02299419976770878, 0.0035408171825110912, 0.010393233969807625, 0.051248352974653244, 0.032404206693172455, -0.009940829128026962, -0.009385880082845688,...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "Машинное обучение — обширный подраздел искусственного интеллекта, изучающий методы построения алгоритмов, способных обучаться."}}, "targets": [{"_type": "Name", "_fields": {"id": "document", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "document", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X_counted", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X_counted", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 15}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "non_negative", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "document", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X_hashed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shape", "value": {"_type": "Name", "_fields": {"id": "X_hashed", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Pow", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 20}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "nnz", "value": {"_type": "Name", "_fields": {"id": "X_counted", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "nnz", "value": {"_type": "Name", "_fields": {"id": "X_hashed", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X_counted", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "X_hashed", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_vectorizer_unicode", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_vectorizer_unicode(): # tests that the count vectorizer works with cyrillic. document = ( "\xd0\x9c\xd0\xb0\xd1\x88\xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0" "\xb5 \xd0\xbe\xd0\xb1\xd1\x83\xd1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0" "\xb5 \xe2\x80\x94 \xd0\xbe\xd0\xb1\xd1\x88\xd0\xb8\xd1\x80\xd0\xbd" "\xd1\x8b\xd0\xb9 \xd0\xbf\xd0\xbe\xd0\xb4\xd1\x80\xd0\xb0\xd0\xb7" "\xd0\xb4\xd0\xb5\xd0\xbb \xd0\xb8\xd1\x81\xd0\xba\xd1\x83\xd1\x81" "\xd1\x81\xd1\x82\xd0\xb2\xd0\xb5\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb3" "\xd0\xbe \xd0\xb8\xd0\xbd\xd1\x82\xd0\xb5\xd0\xbb\xd0\xbb\xd0" "\xb5\xd0\xba\xd1\x82\xd0\xb0, \xd0\xb8\xd0\xb7\xd1\x83\xd1\x87" "\xd0\xb0\xd1\x8e\xd1\x89\xd0\xb8\xd0\xb9 \xd0\xbc\xd0\xb5\xd1\x82" "\xd0\xbe\xd0\xb4\xd1\x8b \xd0\xbf\xd0\xbe\xd1\x81\xd1\x82\xd1\x80" "\xd0\xbe\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x8f \xd0\xb0\xd0\xbb\xd0\xb3" "\xd0\xbe\xd1\x80\xd0\xb8\xd1\x82\xd0\xbc\xd0\xbe\xd0\xb2, \xd1\x81" "\xd0\xbf\xd0\xbe\xd1\x81\xd0\xbe\xd0\xb1\xd0\xbd\xd1\x8b\xd1\x85 " "\xd0\xbe\xd0\xb1\xd1\x83\xd1\x87\xd0\xb0\xd1\x82\xd1\x8c\xd1\x81\xd1" "\x8f.") vect = CountVectorizer() X_counted = vect.fit_transform([document]) assert_equal(X_counted.shape, (1, 15)) vect = HashingVectorizer(norm=None, non_negative=True) X_hashed = vect.transform([document]) assert_equal(X_hashed.shape, (1, 2 ** 20)) # No collisions on such a small dataset assert_equal(X_counted.nnz, X_hashed.nnz) # When norm is None and non_negative, the tokens are counted up to # collisions assert_array_equal(np.sort(X_counted.data), np.sort(X_hashed.data))
12,592
[ -0.0004315802361816168, 0.020335743203759193, 0.008444718085229397, -0.03299332037568092, -0.042774748057127, 0.005783966742455959, -0.008432048372924328, -0.012575218454003334, -0.012987001799046993, 0.05539431422948837, 0.015419688075780869, -0.011225837282836437, 0.005901166703552008, 0...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "pizza"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "celeri"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "vocabulary", "value": {"_type": "Name", "_fields": {"id": "vocabulary", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X_1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ALL_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X_2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Name", "_fields": {"id": "X_1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Name", "_fields": {"id": "X_2", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_almost_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fixed_vocabulary_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_tfidf_vectorizer_with_fixed_vocabulary", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_tfidf_vectorizer_with_fixed_vocabulary(): # non regression smoke test for inheritance issues vocabulary = ['pizza', 'celeri'] vect = TfidfVectorizer(vocabulary=vocabulary) X_1 = vect.fit_transform(ALL_FOOD_DOCS) X_2 = vect.transform(ALL_FOOD_DOCS) assert_array_almost_equal(X_1.toarray(), X_2.toarray()) assert_true(vect.fixed_vocabulary_)
12,593
[ -0.006894356105476618, -0.002159564755856991, -0.027177387848496437, -0.04185367748141289, -0.025702258571982384, 0.03042767383158207, -0.01847662404179573, 0.033202916383743286, -0.026927366852760315, 0.022576984018087387, 0.05320467799901962, -0.004453516565263271, -0.00025470988475717604,...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "l1"}}}}]}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "binary", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "ngram_range", "value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}}}]}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "preprocessor", "value": {"_type": "Name", "_fields": {"id": "strip_tags", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Name", "_fields": {"id": "lazy_analyze", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "preprocessor", "value": {"_type": "Name", "_fields": {"id": "strip_tags", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Name", "_fields": {"id": "strip_eacute", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "analyzer", "value": {"_type": "Name", "_fields": {"id": "lazy_analyze", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "instances", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dumps", "value": {"_type": "Name", "_fields": {"id": "pickle", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "s", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "s", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "loads", "value": {"_type": "Name", "_fields": {"id": "pickle", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "copy", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "copy", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "type", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__class__", "value": {"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_params", "value": {"_type": "Name", "_fields": {"id": "copy", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_params", "value": {"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "copy", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "instances", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_pickling_vectorizer", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_pickling_vectorizer(): instances = [ HashingVectorizer(), HashingVectorizer(norm='l1'), HashingVectorizer(binary=True), HashingVectorizer(ngram_range=(1, 2)), CountVectorizer(), CountVectorizer(preprocessor=strip_tags), CountVectorizer(analyzer=lazy_analyze), CountVectorizer(preprocessor=strip_tags).fit(JUNK_FOOD_DOCS), CountVectorizer(strip_accents=strip_eacute).fit(JUNK_FOOD_DOCS), TfidfVectorizer(), TfidfVectorizer(analyzer=lazy_analyze), TfidfVectorizer().fit(JUNK_FOOD_DOCS), ] for orig in instances: s = pickle.dumps(orig) copy = pickle.loads(s) assert_equal(type(copy), orig.__class__) assert_equal(copy.get_params(), orig.get_params()) assert_array_equal( copy.fit_transform(JUNK_FOOD_DOCS).toarray(), orig.fit_transform(JUNK_FOOD_DOCS).toarray())
12,594
[ 0.03997379541397095, 0.02409093640744686, -0.017691418528556824, -0.028936946764588356, -0.04855285957455635, 0.03387570381164551, -0.005527119152247906, 0.045376285910606384, -0.0065676202066242695, 0.020891176536679268, 0.04004335403442383, -0.006034327205270529, -0.024485109373927116, 0...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "preprocessor", "value": {"_type": "Name", "_fields": {"id": "strip_tags", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "strip_accents", "value": {"_type": "Name", "_fields": {"id": "strip_eacute", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "keywords": []}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "fitted_vectorizers", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "vect_transform", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "stop_words_", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "stop_None_transform", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "stop_words_"}}], "func": {"_type": "Name", "_fields": {"id": "delattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "stop_del_transform", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stop_None_transform", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "vect_transform", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stop_del_transform", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "vect_transform", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "fitted_vectorizers", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "vect", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "test_stop_words_removal", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_stop_words_removal(): # Ensure that deleting the stop_words_ attribute doesn't affect transform fitted_vectorizers = ( TfidfVectorizer().fit(JUNK_FOOD_DOCS), CountVectorizer(preprocessor=strip_tags).fit(JUNK_FOOD_DOCS), CountVectorizer(strip_accents=strip_eacute).fit(JUNK_FOOD_DOCS) ) for vect in fitted_vectorizers: vect_transform = vect.transform(JUNK_FOOD_DOCS).toarray() vect.stop_words_ = None stop_None_transform = vect.transform(JUNK_FOOD_DOCS).toarray() delattr(vect, 'stop_words_') stop_del_transform = vect.transform(JUNK_FOOD_DOCS).toarray() assert_array_equal(stop_None_transform, vect_transform) assert_array_equal(stop_del_transform, vect_transform)
12,595
[ 0.005975724197924137, -0.010395601391792297, -0.06137024238705635, -0.02077850140631199, 0.00756967393681407, -0.0024353775661438704, -0.012383275665342808, 0.011995901353657246, -0.02916102670133114, 0.02123573049902916, 0.06182747334241867, -0.012707145884633064, -0.0064329528249800205, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "JUNK_FOOD_DOCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "CountVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfTransformer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dumps", "value": {"_type": "Name", "_fields": {"id": "pickle", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "s", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "s", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "loads", "value": {"_type": "Name", "_fields": {"id": "pickle", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "copy", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "copy", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "type", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__class__", "value": {"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "copy", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "orig", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_pickling_transformer", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_pickling_transformer(): X = CountVectorizer().fit_transform(JUNK_FOOD_DOCS) orig = TfidfTransformer().fit(X) s = pickle.dumps(orig) copy = pickle.loads(s) assert_equal(type(copy), orig.__class__) assert_array_equal( copy.fit_transform(X).toarray(), orig.fit_transform(X).toarray())
12,596
[ -0.00645502470433712, 0.04232802987098694, 0.005937063135206699, 0.009941518306732178, 0.038095228374004364, -0.05426899343729019, -0.02321358397603035, 0.039810627698898315, 0.025307707488536835, 0.017009185627102852, 0.027134496718645096, -0.009100526571273804, -0.027780555188655853, 0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "np.nan is an invalid document, expected byte or unicode string."}}, "targets": [{"_type": "Name", "_fields": {"id": "message", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Name", "_fields": {"id": "exception", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "HashingVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "hv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "hello world"}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "nan", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hello hello"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "hv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "func", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "exception", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "message", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_raise_message", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_hashingvectorizer_nan_in_docs", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_hashingvectorizer_nan_in_docs(): # np.nan can appear when using pandas to load text fields from a csv file # with missing values. message = "np.nan is an invalid document, expected byte or unicode string." exception = ValueError def func(): hv = HashingVectorizer() hv.fit_transform(['hello world', np.nan, 'hello hello']) assert_raise_message(exception, message, func)
12,597
[ 0.003580369520932436, 0.0025065720546990633, -0.013518872670829296, -0.020453879609704018, -0.025833839550614357, -0.007223442196846008, -0.006380080245435238, -0.0685223788022995, 0.011349332518875599, -0.013155193068087101, 0.020315932109951973, -0.042186908423900604, 0.04248788580298424, ...
14
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "stock.move"}}, "targets": [{"_type": "Name", "_fields": {"id": "_inherit", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "cr", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "uid", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ids", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "field_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "arg", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "context", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "context", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "context", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "-"}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "customer"}}]}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "+"}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "supplier"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "customer"}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}]}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "="}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "transit"}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "transit"}}]}}]}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "<>"}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "inventory"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "procurement"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "production"}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}]}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}]}}]}}]}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cr", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "uid", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ids", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "browse", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "context", "value": {"_type": "Name", "_fields": {"id": "context", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "_get_direction", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "direction"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "sell_price"}}], "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "_get_direction", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "function", "value": {"_type": "Name", "_fields": {"id": "fields", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "method", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "char"}}}}, {"_type": "keyword", "_fields": {"arg": "string", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Dir"}}}}, {"_type": "keyword", "_fields": {"arg": "readonly", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sale_line_id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "price_unit"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "related", "value": {"_type": "Name", "_fields": {"id": "fields", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "float"}}}}, {"_type": "keyword", "_fields": {"arg": "relation", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "sale.order.line"}}}}, {"_type": "keyword", "_fields": {"arg": "string", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Sell Price Unit"}}}}, {"_type": "keyword", "_fields": {"arg": "readonly", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "_columns", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "name": "stock_move", "bases": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Model", "value": {"_type": "Name", "_fields": {"id": "orm", "ctx": {"_type": "Load", "_fields": {}}}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class stock_move(orm.Model): _inherit = "stock.move" def _get_direction(self, cr, uid, ids, field_name, arg, context=None): if context is None: context = {} res = {} for move in self.browse(cr, uid, ids, context=context): # import pdb; pdb.set_trace() # ('supplier', 'Supplier Location'), ('view', 'View'), ('internal', 'Internal Location'), ('customer', 'Customer Location'), # ('inventory', 'Inventory'), ('procurement', 'Procurement'), ('production', 'Production'), # ('transit', 'Transit Location for Inter-Companies Transfers') if move.location_id.usage == 'internal' and move.location_dest_id.usage == 'customer': res[move.id] = '-' elif move.location_id.usage in ['supplier', 'customer'] and move.location_dest_id.usage == 'internal': res[move.id] = '+' elif move.location_id.usage in ['internal', 'transit'] and move.location_dest_id.usage in ['internal', 'transit']: res[move.id] = '=' elif move.location_id.usage in ['inventory', 'procurement', 'production'] and move.location_dest_id.usage == 'internal': res[move.id] = '<>' else: res[move.id] = [] # if move.picking_id: # if move.picking_id.type == 'in': # res[move.id] = '+' # elif move.picking_id.type == 'out': # res[move.id] = '-' # else: # res[move.id] = '=' # else: # res[move.id] = [] return res _columns = { 'direction': fields.function(_get_direction, method=True, type="char", string='Dir', readonly=True), 'sell_price': fields.related('sale_line_id', 'price_unit', type='float', relation='sale.order.line', string='Sell Price Unit', readonly=True) }
12,598
[ 0.010006492957472801, 0.004547376185655594, -0.005360014270991087, -0.04143039137125015, -0.0037035916466265917, -0.016807736828923225, 0.0177477914839983, 0.03887072205543518, 0.02681989222764969, 0.09092487394809723, -0.011790333315730095, 0.011258012615144253, 0.026095030829310417, 0.03...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "TfidfVectorizer", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "binary", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "use_idf", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "norm", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "binary", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "assert_true", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "hello world"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hello hello"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fit_transform", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ravel", "value": {"_type": "Name", "_fields": {"id": "X", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "toarray", "value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "hello world"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hello hello"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transform", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "X2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ravel", "value": {"_type": "Name", "_fields": {"id": "X2", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "assert_array_equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "test_tfidfvectorizer_binary", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def test_tfidfvectorizer_binary(): # Non-regression test: TfidfVectorizer used to ignore its "binary" param. v = TfidfVectorizer(binary=True, use_idf=False, norm=None) assert_true(v.binary) X = v.fit_transform(['hello world', 'hello hello']).toarray() assert_array_equal(X.ravel(), [1, 1, 1, 0]) X2 = v.transform(['hello world', 'hello hello']).toarray() assert_array_equal(X2.ravel(), [1, 1, 1, 0])
12,599
[ -0.02473745495080948, 0.0010099827777594328, 0.07558000087738037, -0.044892121106386185, 0.0332552008330822, -0.003988944459706545, -0.003335117595270276, -0.01234473381191492, 0.011295011267066002, 0.06962957978248596, 0.006820195354521275, -0.000373776099877432, -0.011408980935811996, 0....
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ArgumentParser", "value": {"_type": "Name", "_fields": {"id": "argparse", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-c"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_argument", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Produce a context format diff (default)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-u"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_argument", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Produce a unified format diff"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-m"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_argument", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Produce HTML side by side diff (can use -c and -l in conjunction)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_argument", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Produce a ndiff format diff"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-l"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--lines"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_argument", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "Set number of context lines (default 3)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "fromfile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_argument", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "tofile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_argument", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parse_args", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fromfile", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "fromfile", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "tofile", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "tofile", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fromfile", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "file_mtime", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "fromdate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tofile", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "file_mtime", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "todate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "readlines", "value": {"_type": "Name", "_fields": {"id": "ff", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "fromlines", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fromfile", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "optional_vars": {"_type": "Name", "_fields": {"id": "ff", "ctx": {"_type": "Store", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "readlines", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tolines", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tofile", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "optional_vars": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Store", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fromlines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tolines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "fromfile", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tofile", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "fromdate", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "todate", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "unified_diff", "value": {"_type": "Name", "_fields": {"id": "difflib", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "n", "value": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "diff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "u", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fromlines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tolines", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ndiff", "value": {"_type": "Name", "_fields": {"id": "difflib", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "diff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "n", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fromlines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tolines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "fromfile", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tofile", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "make_file", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "HtmlDiff", "value": {"_type": "Name", "_fields": {"id": "difflib", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "context", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "c", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "numlines", "value": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "diff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "m", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fromlines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tolines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "fromfile", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tofile", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "fromdate", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "todate", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "context_diff", "value": {"_type": "Name", "_fields": {"id": "difflib", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "n", "value": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "diff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}]}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "diff", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "writelines", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "stdout", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "main", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def main(): parser = argparse.ArgumentParser() parser.add_argument('-c', action='store_true', default=False, help='Produce a context format diff (default)') parser.add_argument('-u', action='store_true', default=False, help='Produce a unified format diff') parser.add_argument('-m', action='store_true', default=False, help='Produce HTML side by side diff ' '(can use -c and -l in conjunction)') parser.add_argument('-n', action='store_true', default=False, help='Produce a ndiff format diff') parser.add_argument('-l', '--lines', type=int, default=3, help='Set number of context lines (default 3)') parser.add_argument('fromfile') parser.add_argument('tofile') options = parser.parse_args() n = options.lines fromfile = options.fromfile tofile = options.tofile fromdate = file_mtime(fromfile) todate = file_mtime(tofile) with open(fromfile) as ff: fromlines = ff.readlines() with open(tofile) as tf: tolines = tf.readlines() if options.u: diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n) elif options.n: diff = difflib.ndiff(fromlines, tolines) elif options.m: diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile,context=options.c,numlines=n) else: diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n) sys.stdout.writelines(diff)
12,600
[ -0.02752836048603058, -0.002032747259363532, 0.007552551571279764, -0.0031074576545506716, -0.021770279854536057, -0.0036711052525788546, -0.0077103073708713055, -0.03599458187818527, 0.011982856318354607, 0.023492444306612015, 0.008669987320899963, -0.0038190013729035854, 0.0319981053471565...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "cr", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "uid", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ids", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "field_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "arg", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "context", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "context", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "context", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "-"}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "customer"}}]}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "+"}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "supplier"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "customer"}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}]}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "="}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "transit"}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "transit"}}]}}]}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "<>"}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "inventory"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "procurement"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "production"}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "usage", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "location_dest_id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "internal"}}]}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}]}}]}}]}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cr", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "uid", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ids", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "browse", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "context", "value": {"_type": "Name", "_fields": {"id": "context", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "move", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "res", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "_get_direction", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _get_direction(self, cr, uid, ids, field_name, arg, context=None): if context is None: context = {} res = {} for move in self.browse(cr, uid, ids, context=context): # import pdb; pdb.set_trace() # ('supplier', 'Supplier Location'), ('view', 'View'), ('internal', 'Internal Location'), ('customer', 'Customer Location'), # ('inventory', 'Inventory'), ('procurement', 'Procurement'), ('production', 'Production'), # ('transit', 'Transit Location for Inter-Companies Transfers') if move.location_id.usage == 'internal' and move.location_dest_id.usage == 'customer': res[move.id] = '-' elif move.location_id.usage in ['supplier', 'customer'] and move.location_dest_id.usage == 'internal': res[move.id] = '+' elif move.location_id.usage in ['internal', 'transit'] and move.location_dest_id.usage in ['internal', 'transit']: res[move.id] = '=' elif move.location_id.usage in ['inventory', 'procurement', 'production'] and move.location_dest_id.usage == 'internal': res[move.id] = '<>' else: res[move.id] = [] # if move.picking_id: # if move.picking_id.type == 'in': # res[move.id] = '+' # elif move.picking_id.type == 'out': # res[move.id] = '-' # else: # res[move.id] = '=' # else: # res[move.id] = [] return res