{"task_id": 3283984, "prompt": "def f_3283984():\n\treturn ", "suffix": "", "canonical_solution": "bytes.fromhex('4a4b4c').decode('utf-8')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == \"JKL\"\n"], "entry_point": "f_3283984", "intent": "decode a hex string '4a4b4c' to UTF-8.", "library": []} {"task_id": 3844801, "prompt": "def f_3844801(myList):\n\treturn ", "suffix": "", "canonical_solution": "all(x == myList[0] for x in myList)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3]) == False\n", "\n assert candidate([1,1,1,1,1,1]) == True\n", "\n assert candidate([1]) == True\n", "\n assert candidate(['k','k','k','k','k']) == True\n", "\n assert candidate([None,'%$#ga',3]) == False\n"], "entry_point": "f_3844801", "intent": "check if all elements in list `myList` are identical", "library": []} {"task_id": 4302166, "prompt": "def f_4302166():\n\treturn ", "suffix": "", "canonical_solution": "'%*s : %*s' % (20, 'Python', 20, 'Very Good')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == ' Python : Very Good'\n"], "entry_point": "f_4302166", "intent": "format number of spaces between strings `Python`, `:` and `Very Good` to be `20`", "library": []} {"task_id": 7555335, "prompt": "def f_7555335(d):\n\treturn ", "suffix": "", "canonical_solution": "d.decode('cp1251').encode('utf8')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('hello world!'.encode('cp1251')) == b'hello world!'\n", "\n assert candidate('%*(^O*'.encode('cp1251')) == b'%*(^O*'\n", "\n assert candidate(''.encode('cp1251')) == b''\n", "\n assert candidate('hello world!'.encode('cp1251')) != 'hello world!'\n"], "entry_point": "f_7555335", "intent": "convert a string `d` from CP-1251 to UTF-8", "library": []} {"task_id": 2544710, "prompt": "def f_2544710(kwargs):\n\treturn ", "suffix": "", "canonical_solution": "{k: v for k, v in list(kwargs.items()) if v is not None}", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({i: None for i in range(10)}) == {}\n", "\n assert candidate({i: min(i,4) for i in range(6)}) == {0:0,1:1,2:2,3:3,4:4,5:4}\n", "\n assert candidate({'abc': 'abc'})['abc'] == 'abc'\n", "\n assert candidate({'x': None, 'yy': 234}) == {'yy': 234}\n"], "entry_point": "f_2544710", "intent": "get rid of None values in dictionary `kwargs`", "library": []} {"task_id": 2544710, "prompt": "def f_2544710(kwargs):\n\treturn ", "suffix": "", "canonical_solution": "dict((k, v) for k, v in kwargs.items() if v is not None)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({i: None for i in range(10)}) == {}\n", "\n assert candidate({i: min(i,4) for i in range(6)}) == {0:0,1:1,2:2,3:3,4:4,5:4}\n", "\n assert candidate({'abc': 'abc'})['abc'] == 'abc'\n", "\n assert candidate({'x': None, 'yy': 234}) == {'yy': 234}\n"], "entry_point": "f_2544710", "intent": "get rid of None values in dictionary `kwargs`", "library": []} {"task_id": 14971373, "prompt": "def f_14971373():\n\treturn ", "suffix": "", "canonical_solution": "subprocess.check_output('ps -ef | grep something | wc -l', shell=True)", "test_start": "\nimport subprocess\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n output = b' PID TTY TIME CMD\\n 226 pts/1 00:00:00 bash\\n 285 pts/1 00:00:00 python3\\n 352 pts/1 00:00:00 ps\\n'\n subprocess.check_output = Mock(return_value = output)\n assert candidate() == output\n"], "entry_point": "f_14971373", "intent": "capture final output of a chain of system commands `ps -ef | grep something | wc -l`", "library": ["subprocess"]} {"task_id": 6726636, "prompt": "def f_6726636():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"\"\"\".join(['a', 'b', 'c'])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == \"abc\"\n", "\n assert candidate() == 'a' + 'b' + 'c'\n"], "entry_point": "f_6726636", "intent": "concatenate a list of strings `['a', 'b', 'c']`", "library": []} {"task_id": 18079563, "prompt": "def f_18079563(s1, s2):\n\treturn ", "suffix": "", "canonical_solution": "pd.Series(list(set(s1).intersection(set(s2))))", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n x1, x2 = pd.Series([1,2]), pd.Series([1,3])\n assert candidate(x1, x2).equals(pd.Series([1]))\n", "\n x1, x2 = pd.Series([1,2]), pd.Series([1,3, 10, 4, 5, 9])\n assert candidate(x1, x2).equals(pd.Series([1]))\n", "\n x1, x2 = pd.Series([1,2]), pd.Series([1,2, 10])\n assert candidate(x1, x2).equals(pd.Series([1, 2]))\n"], "entry_point": "f_18079563", "intent": "find intersection data between series `s1` and series `s2`", "library": ["pandas"]} {"task_id": 8315209, "prompt": "def f_8315209(client):\n\t", "suffix": "\n\treturn ", "canonical_solution": "client.send('HTTP/1.0 200 OK\\r\\n')", "test_start": "\nimport socket\nfrom unittest.mock import Mock\nimport mock\n\ndef check(candidate):", "test": ["\n with mock.patch('socket.socket') as mock_socket:\n mock_socket.return_value.recv.return_value = ''\n mock_socket.bind(('', 8080))\n mock_socket.listen(5)\n mock_socket.accept = Mock(return_value = mock_socket)\n mock_socket.send = Mock()\n try:\n candidate(mock_socket)\n except:\n assert False\n"], "entry_point": "f_8315209", "intent": "sending http headers to `client`", "library": ["socket"]} {"task_id": 26153795, "prompt": "def f_26153795(when):\n\treturn ", "suffix": "", "canonical_solution": "datetime.datetime.strptime(when, '%Y-%m-%d').date()", "test_start": "\nimport datetime\n\ndef check(candidate):", "test": ["\n assert candidate('2013-05-07') == datetime.date(2013, 5, 7)\n", "\n assert candidate('2000-02-29') == datetime.date(2000, 2, 29)\n", "\n assert candidate('1990-01-08') == datetime.date(1990, 1, 8)\n", "\n assert candidate('1990-1-08') == datetime.date(1990, 1, 8)\n", "\n assert candidate('1990-1-8') == datetime.date(1990, 1, 8)\n", "\n assert candidate('1990-01-8') == datetime.date(1990, 1, 8)\n"], "entry_point": "f_26153795", "intent": "Format a datetime string `when` to extract date only", "library": ["datetime"]} {"task_id": 172439, "prompt": "def f_172439(inputString):\n\treturn ", "suffix": "", "canonical_solution": "inputString.split('\\n')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('line a\\nfollows by line b\t...bye\\n') == ['line a', 'follows by line b\t...bye', '']\n", "\n assert candidate('no new line in this sentence. ') == ['no new line in this sentence. ']\n", "\n assert candidate('a\tbfs hhhdf\tsfdas') == ['a\tbfs hhhdf\tsfdas']\n", "\n assert candidate('') == ['']\n"], "entry_point": "f_172439", "intent": "split a multi-line string `inputString` into separate strings", "library": []} {"task_id": 172439, "prompt": "def f_172439():\n\treturn ", "suffix": "", "canonical_solution": "' a \\n b \\r\\n c '.split('\\n')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == [' a ', ' b \\r', ' c ']\n"], "entry_point": "f_172439", "intent": "Split a multi-line string ` a \\n b \\r\\n c ` by new line character `\\n`", "library": []} {"task_id": 13954222, "prompt": "def f_13954222(b):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\":\"\"\".join(str(x) for x in b)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['x','y','zzz']) == 'x:y:zzz'\n", "\n assert candidate(['111','22','3']) == '111:22:3'\n", "\n assert candidate(['']) == ''\n", "\n assert candidate([':',':']) == ':::'\n", "\n assert candidate([',','#','#$%']) == ',:#:#$%'\n", "\n assert candidate(['a','b','c']) != 'abc'\n"], "entry_point": "f_13954222", "intent": "concatenate elements of list `b` by a colon \":\"", "library": []} {"task_id": 13567345, "prompt": "def f_13567345(a):\n\treturn ", "suffix": "", "canonical_solution": "a.sum(axis=1)", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n a1 = np.array([[i for i in range(3)] for j in range(5)])\n assert np.array_equal(candidate(a1), np.array([3, 3, 3, 3, 3]))\n", "\n a2 = np.array([[i+j for i in range(3)] for j in range(5)])\n assert np.array_equal(candidate(a2), np.array([ 3, 6, 9, 12, 15]))\n", "\n a3 = np.array([[i*j for i in range(3)] for j in range(5)])\n assert np.array_equal(candidate(a3), np.array([ 0, 3, 6, 9, 12]))\n"], "entry_point": "f_13567345", "intent": "Calculate sum over all rows of 2D numpy array `a`", "library": ["numpy"]} {"task_id": 29784889, "prompt": "def f_29784889():\n\t", "suffix": "\n\treturn ", "canonical_solution": "warnings.simplefilter('always')", "test_start": "\nimport warnings \n\ndef check(candidate):", "test": ["\n candidate() \n assert any([(wf[0] == 'always') for wf in warnings.filters])\n"], "entry_point": "f_29784889", "intent": "enable warnings using action 'always'", "library": ["warnings"]} {"task_id": 13550423, "prompt": "def f_13550423(l):\n\treturn ", "suffix": "", "canonical_solution": "' '.join(map(str, l))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['x','y','zzz']) == 'x y zzz'\n", "\n assert candidate(['111','22','3']) == '111 22 3'\n", "\n assert candidate(['']) == ''\n", "\n assert candidate([':',':']) == ': :'\n", "\n assert candidate([',','#','#$%']) == ', # #$%'\n", "\n assert candidate(['a','b','c']) != 'abc'\n"], "entry_point": "f_13550423", "intent": "concatenate items of list `l` with a space ' '", "library": []} {"task_id": 698223, "prompt": "def f_698223():\n\treturn ", "suffix": "", "canonical_solution": "time.strptime('30/03/09 16:31:32.123', '%d/%m/%y %H:%M:%S.%f')", "test_start": "\nimport time \n\ndef check(candidate):", "test": ["\n answer = time.strptime('30/03/09 16:31:32.123', '%d/%m/%y %H:%M:%S.%f')\n assert candidate() == answer\n false_1 = time.strptime('30/03/09 17:31:32.123', '%d/%m/%y %H:%M:%S.%f')\n assert candidate() != false_1\n false_2 = time.strptime('20/03/09 17:31:32.123', '%d/%m/%y %H:%M:%S.%f')\n assert candidate() != false_2\n"], "entry_point": "f_698223", "intent": "parse a time string '30/03/09 16:31:32.123' containing milliseconds in it", "library": ["time"]} {"task_id": 6633523, "prompt": "def f_6633523(my_string):\n\t", "suffix": "\n\treturn my_float", "canonical_solution": "my_float = float(my_string.replace(',', ''))", "test_start": "\ndef check(candidate):", "test": ["\n assert (candidate('1,234.00') - 1234.0) < 1e-6\n", "\n assert (candidate('0.00') - 0.00) < 1e-6\n", "\n assert (candidate('1,000,000.00') - 1000000.00) < 1e-6\n", "\n assert (candidate('1,000,000.00') - 999999.98) > 1e-6\n", "\n assert (candidate('1') - 1.00) < 1e-6\n"], "entry_point": "f_6633523", "intent": "convert a string `my_string` with dot and comma into a float number `my_float`", "library": []} {"task_id": 6633523, "prompt": "def f_6633523():\n\treturn ", "suffix": "", "canonical_solution": "float('123,456.908'.replace(',', ''))", "test_start": "\ndef check(candidate):", "test": ["\n assert (candidate() - 123456.908) < 1e-6\n assert (candidate() - 123456.9) > 1e-6\n assert (candidate() - 1234.908) > 1e-6\n assert type(candidate()) == float\n assert int(candidate()) == 123456\n"], "entry_point": "f_6633523", "intent": "convert a string `123,456.908` with dot and comma into a floating number", "library": []} {"task_id": 3108285, "prompt": "def f_3108285():\n\t", "suffix": "\n\treturn ", "canonical_solution": "sys.path.append('/path/to/whatever')", "test_start": "\nimport sys \n\ndef check(candidate):", "test": ["\n original_paths = [sp for sp in sys.path]\n candidate()\n assert '/path/to/whatever' in sys.path\n"], "entry_point": "f_3108285", "intent": "set python path '/path/to/whatever' in python script", "library": ["sys"]} {"task_id": 2195340, "prompt": "def f_2195340():\n\treturn ", "suffix": "", "canonical_solution": "re.split('(\\\\W+)', 'Words, words, words.')", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate() == ['Words', ', ', 'words', ', ', 'words', '.', '']\n assert candidate() == ['Words', ', '] + ['words', ', ', 'words', '.', '']\n"], "entry_point": "f_2195340", "intent": "split string 'Words, words, words.' using a regex '(\\\\W+)'", "library": ["re"]} {"task_id": 17977584, "prompt": "def f_17977584():\n\treturn ", "suffix": "", "canonical_solution": "open('Output.txt', 'a')", "test_start": "\ndef check(candidate):", "test": ["\n f = candidate()\n assert str(f.__class__) == \"\"\n assert f.name == 'Output.txt'\n assert f.mode == 'a'\n"], "entry_point": "f_17977584", "intent": "open a file `Output.txt` in append mode", "library": []} {"task_id": 22676, "prompt": "def f_22676():\n\treturn ", "suffix": "", "canonical_solution": "urllib.request.urlretrieve('https://github.com/zorazrw/multilingual-conala/blob/master/dataset/test/es_test.json', 'mp3.mp3')", "test_start": "\nimport urllib \n\ndef check(candidate):", "test": ["\n results = candidate()\n assert len(results) == 2\n assert results[0] == \"mp3.mp3\"\n assert results[1].values()[0] == \"GitHub.com\"\n"], "entry_point": "f_22676", "intent": "download a file \"http://www.example.com/songs/mp3.mp3\" over HTTP and save to \"mp3.mp3\"", "library": ["urllib"]} {"task_id": 22676, "prompt": "def f_22676(url):\n\t", "suffix": "\n\treturn html", "canonical_solution": "html = urllib.request.urlopen(url).read()", "test_start": "\nimport urllib \n\ndef check(candidate):", "test": ["\n html = candidate(\"https://github.com/zorazrw/multilingual-conala/blob/master/dataset/test/es_test.json\")\n assert b\"zorazrw/multilingual-conala\" in html\n"], "entry_point": "f_22676", "intent": "download a file 'http://www.example.com/' over HTTP", "library": ["urllib"]} {"task_id": 22676, "prompt": "def f_22676(url):\n\treturn ", "suffix": "", "canonical_solution": "requests.get(url)", "test_start": "\nimport requests \n\ndef check(candidate):", "test": ["\n assert candidate(\"https://github.com/\").url == \"https://github.com/\"\n", "\n assert candidate(\"https://google.com/\").url == \"https://www.google.com/\"\n"], "entry_point": "f_22676", "intent": "download a file `url` over HTTP", "library": ["requests"]} {"task_id": 22676, "prompt": "def f_22676(url):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\tresponse = requests.get(url, stream=True)\n\twith open('10MB', 'wb') as handle:\n\t\tfor data in response.iter_content():\n\t\t\thandle.write(data)\n\t", "test_start": "\nimport requests \n\ndef check(candidate):", "test": ["\n candidate(\"https://github.com/\")\n with open(\"10MB\", 'rb') as fr: \n all_data = [data for data in fr]\n assert all_data[: 2] == [b'\\n', b'\\n']\n"], "entry_point": "f_22676", "intent": "download a file `url` over HTTP and save to \"10MB\"", "library": ["requests"]} {"task_id": 15405636, "prompt": "def f_15405636(parser):\n\treturn ", "suffix": "", "canonical_solution": "parser.add_argument('--version', action='version', version='%(prog)s 2.0')", "test_start": "\nimport argparse \n\ndef check(candidate):", "test": ["\n parser = argparse.ArgumentParser()\n output = candidate(parser)\n assert output.option_strings == ['--version']\n assert output.dest == 'version'\n assert output.nargs == 0\n"], "entry_point": "f_15405636", "intent": "argparse add argument with flag '--version' and version action of '%(prog)s 2.0' to parser `parser`", "library": ["argparse"]} {"task_id": 17665809, "prompt": "def f_17665809(d):\n\treturn ", "suffix": "", "canonical_solution": "{i: d[i] for i in d if i != 'c'}", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'a': 1 , 'b': 2, 'c': 3}) == {'a': 1 , 'b': 2}\n", "\n assert candidate({'c': None}) == {}\n", "\n assert candidate({'a': 1 , 'b': 2, 'c': 3}) != {'a': 1 , 'b': 2, 'c': 3}\n", "\n assert candidate({'c': 1, 'cc': 2, 'ccc':3}) == {'cc': 2, 'ccc':3}\n", "\n assert 'c' not in candidate({'c':i for i in range(10)})\n"], "entry_point": "f_17665809", "intent": "remove key 'c' from dictionary `d`", "library": []} {"task_id": 41861705, "prompt": "def f_41861705(split_df, csv_df):\n\treturn ", "suffix": "", "canonical_solution": "pd.merge(split_df, csv_df, on=['key'], suffixes=('_left', '_right'))", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n split_df = pd.DataFrame({'key': ['foo', 'bar'], 'value': [1, 2]})\n csv_df = pd.DataFrame({'key': ['foo', 'baz'], 'value': [3, 4]})\n result = pd.DataFrame({'key': ['foo'], 'value_left': [1],'value_right': [3]})\n assert all(candidate(csv_df, split_df) == result)\n"], "entry_point": "f_41861705", "intent": "Create new DataFrame object by merging columns \"key\" of dataframes `split_df` and `csv_df` and rename the columns from dataframes `split_df` and `csv_df` with suffix `_left` and `_right` respectively", "library": ["pandas"]} {"task_id": 10697757, "prompt": "def f_10697757(s):\n\treturn ", "suffix": "", "canonical_solution": "s.split(' ', 4)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('1 0 A10B 100 Description: This is a description with spaces') == ['1', '0', 'A10B', '100', 'Description: This is a description with spaces']\n", "\n assert candidate('this-is-a-continuous-sequence') == ['this-is-a-continuous-sequence']\n", "\n assert candidate('') == ['']\n", "\n assert candidate('\t') == ['\t']\n"], "entry_point": "f_10697757", "intent": "Split a string `s` by space with `4` splits", "library": []} {"task_id": 16344756, "prompt": "def f_16344756(app):\n\treturn ", "suffix": "", "canonical_solution": "app.run(debug=True)", "test_start": "\nfrom flask import Flask\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n Flask = Mock()\n app = Flask('mai')\n try:\n candidate(app)\n except:\n return False\n"], "entry_point": "f_16344756", "intent": "enable debug mode on Flask application `app`", "library": ["flask"]} {"task_id": 40133826, "prompt": "def f_40133826(mylist):\n\t", "suffix": "\n\treturn ", "canonical_solution": "pickle.dump(mylist, open('save.txt', 'wb'))", "test_start": "\nimport pickle\n\ndef check(candidate):", "test": ["\n candidate([i for i in range(10)])\n data = pickle.load(open('save.txt', 'rb'))\n assert data == [i for i in range(10)]\n", "\n candidate([\"hello\", \"world\", \"!\"])\n data = pickle.load(open('save.txt', 'rb'))\n assert data == [\"hello\", \"world\", \"!\"]\n"], "entry_point": "f_40133826", "intent": "python save list `mylist` to file object 'save.txt'", "library": ["pickle"]} {"task_id": 4490961, "prompt": "def f_4490961(P, T):\n\treturn ", "suffix": "", "canonical_solution": "scipy.tensordot(P, T, axes=[1, 1]).swapaxes(0, 1)", "test_start": "\nimport scipy\nimport numpy as np\n\ndef check(candidate):", "test": ["\n P = np.array([[6, 2, 7], [1, 1, 8], [8, 7, 1], [9, 6, 4], [2, 1, 1]])\n T = np.array([[[9, 7, 2, 3], [9, 6, 8, 2], [6, 6, 2, 8]],\n [[4, 5, 5, 3], [1, 8, 3, 5], [2, 8, 1, 6]]])\n result = np.array([[[114, 96, 42, 78], [ 66, 61, 26, 69], [141, 104, 74, 46], [159, 123, 74, 71], [ 33, 26, 14, 16]], \n [[ 40, 102, 43, 70], [ 21, 77, 16, 56], [ 41, 104, 62, 65], [ 50, 125, 67, 81], [ 11, 26, 14, 17]]])\n assert np.array_equal(candidate(P, T), result)\n"], "entry_point": "f_4490961", "intent": "Multiply a matrix `P` with a 3d tensor `T` in scipy", "library": ["numpy", "scipy"]} {"task_id": 2173087, "prompt": "def f_2173087():\n\treturn ", "suffix": "", "canonical_solution": "numpy.zeros((3, 3, 3))", "test_start": "\nimport numpy \nimport numpy as np\n\ndef check(candidate):", "test": ["\n result = np.array([[[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]],\n [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]],\n [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]])\n assert np.array_equal(candidate(), result)\n"], "entry_point": "f_2173087", "intent": "Create 3d array of zeroes of size `(3,3,3)`", "library": ["numpy"]} {"task_id": 6266727, "prompt": "def f_6266727(content):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\" \"\"\".join(content.split(' ')[:-1])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('test') == ''\n", "\n assert candidate('this is an example content') == 'this is an example'\n", "\n assert candidate(' ') == ' '\n", "\n assert candidate('') == ''\n", "\n assert candidate('blank and tab\t') == 'blank and'\n"], "entry_point": "f_6266727", "intent": "cut off the last word of a sentence `content`", "library": []} {"task_id": 30385151, "prompt": "def f_30385151(x):\n\t", "suffix": "\n\treturn x", "canonical_solution": "x = np.asarray(x).reshape(1, -1)[(0), :]", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n assert all(candidate(1.) == np.asarray(1.))\n", "\n assert all(candidate(123) == np.asarray(123))\n", "\n assert all(candidate('a') == np.asarray('a'))\n", "\n assert all(candidate(False) == np.asarray(False))\n"], "entry_point": "f_30385151", "intent": "convert scalar `x` to array", "library": ["numpy"]} {"task_id": 15856127, "prompt": "def f_15856127(L):\n\treturn ", "suffix": "", "canonical_solution": "sum(sum(i) if isinstance(i, list) else i for i in L)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3,4]) == 10\n", "\n assert candidate([[1],[2],[3],[4]]) == 10\n", "\n assert candidate([1,1,1,1]) == 4\n", "\n assert candidate([1,[2,3],[4]]) == 10\n", "\n assert candidate([]) == 0\n", "\n assert candidate([[], []]) == 0\n"], "entry_point": "f_15856127", "intent": "sum all elements of nested list `L`", "library": []} {"task_id": 1592158, "prompt": "def f_1592158():\n\treturn ", "suffix": "", "canonical_solution": "struct.unpack('!f', bytes.fromhex('470FC614'))[0]", "test_start": "\nimport struct \n\ndef check(candidate):", "test": ["\n assert (candidate() - 36806.078125) < 1e-6\n", "\n assert (candidate() - 32806.079125) > 1e-6\n"], "entry_point": "f_1592158", "intent": "convert hex string '470FC614' to a float number", "library": ["struct"]} {"task_id": 5010536, "prompt": "def f_5010536(my_dict):\n\t", "suffix": "\n\treturn my_dict", "canonical_solution": "my_dict.update((x, y * 2) for x, y in list(my_dict.items()))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'a': [1], 'b': 4.9}) == {'a': [1, 1], 'b': 9.8}\n", "\n assert candidate({1:1}) == {1:2}\n", "\n assert candidate({(1,2):[1]}) == {(1,2):[1,1]}\n", "\n assert candidate({'asd':0}) == {'asd':0}\n", "\n assert candidate({}) == {}\n"], "entry_point": "f_5010536", "intent": "Multiple each value by `2` for all keys in a dictionary `my_dict`", "library": []} {"task_id": 13745648, "prompt": "def f_13745648():\n\treturn ", "suffix": "", "canonical_solution": "subprocess.call('sleep.sh', shell=True)", "test_start": "\nimport subprocess \nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n subprocess.call = Mock()\n try:\n candidate()\n except:\n assert False\n"], "entry_point": "f_13745648", "intent": "running bash script 'sleep.sh'", "library": ["subprocess"]} {"task_id": 44778, "prompt": "def f_44778(l):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\",\"\"\".join(l)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['a','b','c']) == 'a,b,c'\n", "\n assert candidate(['a','b']) == 'a,b'\n", "\n assert candidate([',',',',',']) == ',,,,,'\n", "\n assert candidate([' ',' ','c']) == ' , ,c'\n", "\n assert candidate([]) == ''\n"], "entry_point": "f_44778", "intent": "Join elements of list `l` with a comma `,`", "library": []} {"task_id": 44778, "prompt": "def f_44778(myList):\n\t", "suffix": "\n\treturn myList", "canonical_solution": "myList = ','.join(map(str, myList))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3]) == '1,2,3'\n", "\n assert candidate([1,2,'a']) == '1,2,a'\n", "\n assert candidate([]) == ''\n", "\n assert candidate(['frg',3253]) == 'frg,3253'\n"], "entry_point": "f_44778", "intent": "make a comma-separated string from a list `myList`", "library": []} {"task_id": 7286365, "prompt": "def f_7286365():\n\treturn ", "suffix": "", "canonical_solution": "list(reversed(list(range(10))))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == [9,8,7,6,5,4,3,2,1,0]\n", "\n assert len(candidate()) == 10\n", "\n assert min(candidate()) == 0\n", "\n assert type(candidate()) == list\n", "\n assert type(candidate()[-2]) == int\n"], "entry_point": "f_7286365", "intent": "reverse the list that contains 1 to 10", "library": []} {"task_id": 18454570, "prompt": "def f_18454570():\n\treturn ", "suffix": "", "canonical_solution": "'lamp, bag, mirror'.replace('bag,', '')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 'lamp, mirror'\n assert type(candidate()) == str\n assert len(candidate()) == 13\n assert candidate().startswith('lamp')\n"], "entry_point": "f_18454570", "intent": "remove substring 'bag,' from a string 'lamp, bag, mirror'", "library": []} {"task_id": 4357787, "prompt": "def f_4357787(s):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\".\"\"\".join(s.split('.')[::-1])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('apple.orange.red.green.yellow') == 'yellow.green.red.orange.apple'\n", "\n assert candidate('apple') == 'apple'\n", "\n assert candidate('apple.orange') == 'orange.apple'\n", "\n assert candidate('123.456') == '456.123'\n", "\n assert candidate('.') == '.'\n"], "entry_point": "f_4357787", "intent": "Reverse the order of words, delimited by `.`, in string `s`", "library": []} {"task_id": 21787496, "prompt": "def f_21787496(s):\n\treturn ", "suffix": "", "canonical_solution": "datetime.datetime.fromtimestamp(s).strftime('%Y-%m-%d %H:%M:%S.%f')", "test_start": "\nimport time\nimport datetime\n\ndef check(candidate): ", "test": ["\n assert candidate(1236472) == '1970-01-15 07:27:52.000000'\n", "\n assert candidate(0) == '1970-01-01 00:00:00.000000'\n", "\n assert candidate(5.3) == '1970-01-01 00:00:05.300000'\n"], "entry_point": "f_21787496", "intent": "convert epoch time represented as milliseconds `s` to string using format '%Y-%m-%d %H:%M:%S.%f'", "library": ["datetime", "time"]} {"task_id": 21787496, "prompt": "def f_21787496():\n\treturn ", "suffix": "", "canonical_solution": "time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(1236472051807 / 1000.0))", "test_start": "\nimport time\n\ndef check(candidate): ", "test": ["\n assert candidate() == '2009-03-08 00:27:31'\n"], "entry_point": "f_21787496", "intent": "parse milliseconds epoch time '1236472051807' to format '%Y-%m-%d %H:%M:%S'", "library": ["time"]} {"task_id": 20573459, "prompt": "def f_20573459():\n\treturn ", "suffix": "", "canonical_solution": "(datetime.datetime.now() - datetime.timedelta(days=7)).date()", "test_start": "\nimport datetime\n\ndef check(candidate): ", "test": ["\n assert datetime.datetime.now().date() - candidate() < datetime.timedelta(days = 7, seconds = 1)\n", "\n assert datetime.datetime.now().date() - candidate() >= datetime.timedelta(days = 7)\n"], "entry_point": "f_20573459", "intent": "get the date 7 days before the current date", "library": ["datetime"]} {"task_id": 15352457, "prompt": "def f_15352457(column, data):\n\treturn ", "suffix": "", "canonical_solution": "sum(row[column] for row in data)", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate(1, [[1,2,3], [4,5,6]]) == 7\n", "\n assert candidate(0, [[1,1,1], [0,1,1]]) == 1\n", "\n assert candidate(5, [[1,1,1,1,1,2], [0,1,1,1,1,1,1,1,1,1,1]]) == 3\n", "\n assert candidate(0, [[1],[2],[3],[4]]) == 10\n"], "entry_point": "f_15352457", "intent": "sum elements at index `column` of each list in list `data`", "library": []} {"task_id": 15352457, "prompt": "def f_15352457(array):\n\treturn ", "suffix": "", "canonical_solution": "[sum(row[i] for row in array) for i in range(len(array[0]))]", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate([[1,2,3], [4,5,6]]) == [5, 7, 9]\n", "\n assert candidate([[1,1,1], [0,1,1]]) == [1, 2, 2]\n", "\n assert candidate([[1,1,1,1,1,2], [0,1,1,1,1,1,1,1,1,1,1]]) == [1, 2, 2, 2, 2, 3]\n", "\n assert candidate([[1],[2],[3],[4]]) == [10]\n"], "entry_point": "f_15352457", "intent": "sum columns of a list `array`", "library": []} {"task_id": 23164058, "prompt": "def f_23164058():\n\treturn ", "suffix": "", "canonical_solution": "base64.b64encode(bytes('your string', 'utf-8'))", "test_start": "\nimport base64\n\ndef check(candidate): ", "test": ["\n assert candidate() == b'eW91ciBzdHJpbmc='\n"], "entry_point": "f_23164058", "intent": "encode binary string 'your string' to base64 code", "library": ["base64"]} {"task_id": 11533274, "prompt": "def f_11533274(dicts):\n\treturn ", "suffix": "", "canonical_solution": "dict((k, [d[k] for d in dicts]) for k in dicts[0])", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate([{'cat': 1, 'dog': 3}, {'cat' : 2, 'dog': ['happy']}]) == {'cat': [1, 2], 'dog': [3, ['happy']]}\n", "\n assert candidate([{'cat': 1}, {'cat' : 2}]) != {'cat': 3}\n"], "entry_point": "f_11533274", "intent": "combine list of dictionaries `dicts` with the same keys in each list to a single dictionary", "library": []} {"task_id": 11533274, "prompt": "def f_11533274(dicts):\n\treturn ", "suffix": "", "canonical_solution": "{k: [d[k] for d in dicts] for k in dicts[0]}", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate([{'cat': 1, 'dog': 3}, {'cat' : 2, 'dog': ['happy']}]) == {'cat': [1, 2], 'dog': [3, ['happy']]}\n", "\n assert candidate([{'cat': 1}, {'cat' : 2}]) != {'cat': 3}\n"], "entry_point": "f_11533274", "intent": "Merge a nested dictionary `dicts` into a flat dictionary by concatenating nested values with the same key `k`", "library": []} {"task_id": 14026704, "prompt": "def f_14026704(request):\n\treturn ", "suffix": "", "canonical_solution": "request.args['myParam']", "test_start": "\nimport multidict\n\nclass Request:\n def __init__(self, args):\n self.args = args\n\ndef check(candidate): ", "test": ["\n args = multidict.MultiDict([('myParam' , 'popeye')])\n request = Request(args)\n assert candidate(request) == 'popeye'\n"], "entry_point": "f_14026704", "intent": "get the url parameter 'myParam' in a Flask view", "library": ["multidict"]} {"task_id": 11236006, "prompt": "def f_11236006(mylist):\n\treturn ", "suffix": "", "canonical_solution": "[k for k, v in list(Counter(mylist).items()) if v > 1]", "test_start": "\nfrom collections import Counter\n\ndef check(candidate):", "test": ["\n assert candidate([1,3,2,2,1,4]) == [1, 2]\n", "\n assert candidate([1,3,2,2,1,4]) != [3,4]\n", "\n assert candidate([]) == []\n", "\n assert candidate([1,1,1,1,1]) == [1]\n", "\n assert candidate([1.,1.,1.]) == [1.]\n"], "entry_point": "f_11236006", "intent": "identify duplicate values in list `mylist`", "library": ["collections"]} {"task_id": 20211942, "prompt": "def f_20211942(db):\n\treturn ", "suffix": "", "canonical_solution": "db.execute(\"INSERT INTO present VALUES('test2', ?, 10)\", (None,))", "test_start": "\nimport sqlite3\n\ndef check(candidate):", "test": ["\n sqliteConnection = sqlite3.connect('dev.db')\n db = sqliteConnection.cursor()\n print(\"Database created and Successfully Connected to SQLite\")\n db.execute(\"CREATE TABLE present (name VARCHAR(5), age INTEGER, height INTEGER)\")\n try:\n candidate(db)\n except:\n assert False\n"], "entry_point": "f_20211942", "intent": "Insert a 'None' value into a SQLite3 table.", "library": ["sqlite3"]} {"task_id": 406121, "prompt": "def f_406121(list_of_menuitems):\n\treturn ", "suffix": "", "canonical_solution": "[image for menuitem in list_of_menuitems for image in menuitem]", "test_start": "\nfrom collections import Counter\n\ndef check(candidate):", "test": ["\n assert candidate([[1,2],[3,4,5]]) == [1,2,3,4,5]\n", "\n assert candidate([[],[]]) == []\n", "\n assert candidate([[1,1,1], []]) == [1,1,1]\n", "\n assert candidate([['1'],['2']]) == ['1','2']\n"], "entry_point": "f_406121", "intent": "flatten list `list_of_menuitems`", "library": ["collections"]} {"task_id": 4741537, "prompt": "def f_4741537(a, b):\n\t", "suffix": "\n\treturn a", "canonical_solution": "a.extend(b)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1, 2, 2, 3], {4, 5, 2}) == [1, 2, 2, 3, 2, 4, 5]\n", "\n assert candidate([], {4,5,2}) == [2,4,5]\n", "\n assert candidate([1,2,3,4],{2}) == [1,2,3,4,2]\n", "\n assert candidate([1], {'a'}) == [1, 'a']\n"], "entry_point": "f_4741537", "intent": "append elements of a set `b` to a list `a`", "library": []} {"task_id": 15851568, "prompt": "def f_15851568(x):\n\treturn ", "suffix": "", "canonical_solution": "x.rpartition('-')[0]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('djhajhdjk-dadwqd-dahdjkahsk') == 'djhajhdjk-dadwqd'\n", "\n assert candidate('/-/') == '/'\n", "\n assert candidate('---') == '--'\n", "\n assert candidate('') == ''\n"], "entry_point": "f_15851568", "intent": "Split a string `x` by last occurrence of character `-`", "library": []} {"task_id": 15851568, "prompt": "def f_15851568(x):\n\treturn ", "suffix": "", "canonical_solution": "x.rsplit('-', 1)[0]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('2022-03-01') == '2022-03'\n", "\n assert candidate('2020-2022') == '2020'\n"], "entry_point": "f_15851568", "intent": "get the last part of a string before the character '-'", "library": []} {"task_id": 17438096, "prompt": "def f_17438096(filename, ftp):\n\t", "suffix": "\n\treturn ", "canonical_solution": "ftp.storlines('STOR ' + filename, open(filename, 'r'))", "test_start": "\nimport ftplib\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n ftplib.FTP = Mock()\n ftp = ftplib.FTP(\"10.10.10.10\")\n ftp.storlines = Mock()\n file_name = 'readme.txt'\n with open (file_name, 'a') as f:\n f.write('apple')\n candidate(file_name, ftp)\n"], "entry_point": "f_17438096", "intent": "upload file using FTP", "library": ["ftplib"]} {"task_id": 28742436, "prompt": "def f_28742436():\n\treturn ", "suffix": "", "canonical_solution": "np.maximum([2, 3, 4], [1, 5, 2])", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n assert all(candidate() == np.array([2, 5, 4]))\n"], "entry_point": "f_28742436", "intent": "create array containing the maximum value of respective elements of array `[2, 3, 4]` and array `[1, 5, 2]`", "library": ["numpy"]} {"task_id": 34280147, "prompt": "def f_34280147(l):\n\treturn ", "suffix": "", "canonical_solution": "l[3:] + l[:3]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"my-string\") == \"stringmy-\"\n", "\n assert candidate(\"my \") == \"my \"\n", "\n assert candidate(\"n;ho0-4w606[q\") == \"o0-4w606[qn;h\"\n"], "entry_point": "f_34280147", "intent": "print a list `l` and move first 3 elements to the end of the list", "library": []} {"task_id": 4172131, "prompt": "def f_4172131():\n\treturn ", "suffix": "", "canonical_solution": "[int(1000 * random.random()) for i in range(10000)]", "test_start": "\nimport random\n\ndef check(candidate):", "test": ["\n result = candidate()\n assert isinstance(result, list)\n assert all([isinstance(item, int) for item in result])\n"], "entry_point": "f_4172131", "intent": "create a random list of integers", "library": ["random"]} {"task_id": 6677332, "prompt": "def f_6677332():\n\treturn ", "suffix": "", "canonical_solution": "datetime.datetime.now().strftime('%H:%M:%S.%f')", "test_start": "\nimport datetime\n\ndef check(candidate):", "test": ["\n time_now = datetime.datetime.now().strftime('%H:%M:%S.%f')\n assert candidate().split('.')[0] == time_now.split('.')[0]\n"], "entry_point": "f_6677332", "intent": "Using %f with strftime() in Python to get microseconds", "library": ["datetime"]} {"task_id": 15325182, "prompt": "def f_15325182(df):\n\treturn ", "suffix": "", "canonical_solution": "df.b.str.contains('^f')", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[1, 'fat'], [2, 'hip'], [3, 'foo']], columns = ['a', 'b'])\n expected = [True, False, True]\n actual = candidate(df)\n for i in range (0, len(expected)):\n assert expected[i] == actual[i]\n"], "entry_point": "f_15325182", "intent": "filter rows in pandas starting with alphabet 'f' using regular expression.", "library": ["pandas"]} {"task_id": 583557, "prompt": "def f_583557(tab):\n\treturn ", "suffix": "", "canonical_solution": "'\\n'.join('\\t'.join(str(col) for col in row) for row in tab)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[1,2,3],[4,5,6]]) == \"1\\t2\\t3\\n4\\t5\\t6\"\n", "\n assert candidate([[1, 'x' ,3],[4.4,5,\"six\"]]) == \"1\\tx\\t3\\n4.4\\t5\\tsix\"\n", "\n assert candidate([]) == \"\"\n", "\n assert candidate([[],[],[]]) == \"\\n\\n\"\n"], "entry_point": "f_583557", "intent": "print a 2 dimensional list `tab` as a table with delimiters", "library": []} {"task_id": 38535931, "prompt": "def f_38535931(df, tuples):\n\treturn ", "suffix": "", "canonical_solution": "df.set_index(list('BC')).drop(tuples, errors='ignore').reset_index()", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[3, 4], [4, 5], [-1, -2]], columns = ['B', 'C'])\n tuples = [(3, 4), (-1, -2)]\n expected = pd.DataFrame([[4, 5]], columns = ['B', 'C'])\n actual = candidate(df, tuples)\n assert pd.DataFrame.equals(actual, expected)\n"], "entry_point": "f_38535931", "intent": "pandas: delete rows in dataframe `df` based on multiple columns values", "library": ["pandas"]} {"task_id": 13945749, "prompt": "def f_13945749(goals, penalties):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"({:d} goals, ${:d})\"\"\".format(goals, penalties)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(0, 0) == \"(0 goals, $0)\"\n", "\n assert candidate(123, 2) == \"(123 goals, $2)\"\n"], "entry_point": "f_13945749", "intent": "format the variables `goals` and `penalties` using string formatting", "library": []} {"task_id": 13945749, "prompt": "def f_13945749(goals, penalties):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"({} goals, ${})\"\"\".format(goals, penalties)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(0, 0) == \"(0 goals, $0)\"\n", "\n assert candidate(123, \"???\") == \"(123 goals, $???)\"\n", "\n assert candidate(\"x\", 0.0) == \"(x goals, $0.0)\"\n"], "entry_point": "f_13945749", "intent": "format string \"({} goals, ${})\" with variables `goals` and `penalties`", "library": []} {"task_id": 18524642, "prompt": "def f_18524642(L):\n\treturn ", "suffix": "", "canonical_solution": "[int(''.join(str(d) for d in x)) for x in L]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[1,2], [2,3,4], [1,0,0]]) == [12,234,100]\n", "\n assert candidate([[1], [2], [3]]) == [1,2,3]\n"], "entry_point": "f_18524642", "intent": "convert list of lists `L` to list of integers", "library": []} {"task_id": 18524642, "prompt": "def f_18524642(L):\n\t", "suffix": "\n\treturn L", "canonical_solution": "L = [int(''.join([str(y) for y in x])) for x in L]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[1,2], [2,3,4], [1,0,0]]) == [12,234,100]\n", "\n assert candidate([[1], [2], [3]]) == [1,2,3]\n", "\n assert candidate([[1, 0], [0, 2], [3], [0, 0, 0, 0]]) == [10,2,3, 0]\n"], "entry_point": "f_18524642", "intent": "convert a list of lists `L` to list of integers", "library": []} {"task_id": 7138686, "prompt": "def f_7138686(lines, myfile):\n\t", "suffix": "\n\treturn ", "canonical_solution": "myfile.write('\\n'.join(lines))", "test_start": "\ndef check(candidate):", "test": ["\n with open('tmp.txt', 'w') as myfile:\n candidate([\"first\", \"second\", \"third\"], myfile)\n with open('tmp.txt', 'r') as fr: \n lines = fr.readlines()\n assert lines == [\"first\\n\", \"second\\n\", \"third\"]\n"], "entry_point": "f_7138686", "intent": "write the elements of list `lines` concatenated by special character '\\n' to file `myfile`", "library": []} {"task_id": 17238587, "prompt": "def f_17238587(text):\n\t", "suffix": "\n\treturn text", "canonical_solution": "text = re.sub('\\\\b(\\\\w+)( \\\\1\\\\b)+', '\\\\1', text)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate(\"text\") == \"text\"\n", "\n assert candidate(\"text text\") == \"text\"\n", "\n assert candidate(\"texttext\") == \"texttext\"\n", "\n assert candidate(\"text and text\") == \"text and text\"\n"], "entry_point": "f_17238587", "intent": "Remove duplicate words from a string `text` using regex", "library": ["re"]} {"task_id": 26053849, "prompt": "def f_26053849(df):\n\treturn ", "suffix": "", "canonical_solution": "df.astype(bool).sum(axis=1)", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df1 = pd.DataFrame([[0,0,0], [0,1,0], [1,1,1]])\n assert candidate(df1).to_list() == [0, 1, 3]\n", "\n df2 = pd.DataFrame([[0,0,0], [0,2,0], [1,10,8.9]])\n assert candidate(df1).to_list() == [0, 1, 3]\n", "\n df2 = pd.DataFrame([[0,0.0,0], [0,2.0,0], [1,10,8.9]])\n assert candidate(df1).to_list() == [0, 1, 3]\n", "\n df = df = pd.DataFrame([[4, 0, 0], [1, 0, 1]])\n expected = [1, 2]\n actual = candidate(df)\n for i in range(0, len(expected)):\n assert expected[i] == actual[i]\n"], "entry_point": "f_26053849", "intent": "count non zero values in each column in pandas data frame `df`", "library": ["pandas"]} {"task_id": 15534223, "prompt": "def f_15534223():\n\treturn ", "suffix": "", "canonical_solution": "re.search('(?.*<', line).group(0)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate(\"hahhdsf>0.0<;sgnd\") == \">0.0<\"\n", "\n assert candidate(\"hahhdsf>2.34<;xbnfm\") == \">2.34<\"\n"], "entry_point": "f_18168684", "intent": "search for occurrences of regex pattern '>.*<' in xml string `line`", "library": ["re"]} {"task_id": 4914277, "prompt": "def f_4914277(filename):\n\treturn ", "suffix": "", "canonical_solution": "open(filename, 'w').close()", "test_start": "\ndef check(candidate):", "test": ["\n filename = 'tmp.txt'\n with open(filename, 'w') as fw: fw.write(\"hello world!\")\n with open(filename, 'r') as fr: \n lines = fr.readlines()\n assert len(lines) == 1 and lines[0] == \"hello world!\"\n candidate(filename)\n with open(filename, 'r') as fr: \n lines = fr.readlines()\n assert len(lines) == 0\n"], "entry_point": "f_4914277", "intent": "erase all the contents of a file `filename`", "library": []} {"task_id": 19068269, "prompt": "def f_19068269(string_date):\n\treturn ", "suffix": "", "canonical_solution": "datetime.datetime.strptime(string_date, '%Y-%m-%d %H:%M:%S.%f')", "test_start": "\nimport datetime \n\ndef check(candidate):", "test": ["\n assert candidate('2022-10-22 11:59:59.20') == datetime.datetime(2022, 10, 22, 11, 59, 59, 200000)\n", "\n assert candidate('2000-01-01 11:59:59.20') == datetime.datetime(2000, 1, 1, 11, 59, 59, 200000)\n", "\n assert candidate('1990-09-09 09:59:59.24') == datetime.datetime(1990, 9, 9, 9, 59, 59, 240000)\n", "\n d = candidate('2022-12-14 07:06:00.25')\n assert d == datetime.datetime(2022, 12, 14, 7, 6, 0, 250000)\n"], "entry_point": "f_19068269", "intent": "convert a string `string_date` into datetime using the format '%Y-%m-%d %H:%M:%S.%f'", "library": ["datetime"]} {"task_id": 20683167, "prompt": "def f_20683167(thelist):\n\treturn ", "suffix": "", "canonical_solution": "[index for index, item in enumerate(thelist) if item[0] == '332']", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[0,1,2], ['a','bb','ccc'], ['332',33,2], [33,22,332]]) == [2]\n", "\n assert candidate([[0,1,2], ['332'], ['332'], ['332']]) == [1,2,3]\n", "\n assert candidate([[0,1,2], [332], [332], [332]]) == []\n"], "entry_point": "f_20683167", "intent": "find the index of a list with the first element equal to '332' within the list of lists `thelist`", "library": []} {"task_id": 30693804, "prompt": "def f_30693804(text):\n\treturn ", "suffix": "", "canonical_solution": "re.sub('[^\\\\sa-zA-Z0-9]', '', text).lower().strip()", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate('ABjfK329r0&&*#5t') == 'abjfk329r05t'\n", "\n assert candidate('jseguwphegoi339yup h') == 'jseguwphegoi339yup h'\n", "\n assert candidate(' ') == ''\n"], "entry_point": "f_30693804", "intent": "lower a string `text` and remove non-alphanumeric characters aside from space", "library": ["re"]} {"task_id": 30693804, "prompt": "def f_30693804(text):\n\treturn ", "suffix": "", "canonical_solution": "re.sub('(?!\\\\s)[\\\\W_]', '', text).lower().strip()", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate('ABjfK329r0&&*#5t') == 'abjfk329r05t'\n", "\n assert candidate('jseguwphegoi339yup h') == 'jseguwphegoi339yup h'\n", "\n assert candidate(' ') == ''\n"], "entry_point": "f_30693804", "intent": "remove all non-alphanumeric characters except space from a string `text` and lower it", "library": ["re"]} {"task_id": 17138464, "prompt": "def f_17138464(x, y):\n\treturn ", "suffix": "", "canonical_solution": "plt.plot(x, y, label='H\\u2082O')", "test_start": "\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef check(candidate):", "test": ["\n pic = candidate(np.array([1,2,3]),np.array([4,5,6]))[0]\n assert pic.get_label() == 'H\u2082O'\n x, y = pic.get_data()\n assert all(x == np.array([1,2,3]))\n assert all(y == np.array([4,5,6]))\n", "\n pic = candidate(np.array([6, 7, 899]),np.array([0, 1, 245]))[0]\n assert pic.get_label() == 'H\u2082O'\n x, y = pic.get_data()\n assert all(x == np.array([6, 7, 899]))\n assert all(y == np.array([0, 1, 245]))\n"], "entry_point": "f_17138464", "intent": "subscript text 'H20' with '2' as subscripted in matplotlib labels for arrays 'x' and 'y'.", "library": ["matplotlib", "numpy"]} {"task_id": 17138464, "prompt": "def f_17138464(x, y):\n\treturn ", "suffix": "", "canonical_solution": "plt.plot(x, y, label='$H_2O$')", "test_start": "\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef check(candidate):", "test": ["\n pic = candidate(np.array([1,2,3]),np.array([4,5,6]))[0]\n assert pic.get_label() == '$H_2O$'\n x, y = pic.get_data()\n assert all(x == np.array([1,2,3]))\n assert all(y == np.array([4,5,6]))\n", "\n pic = candidate(np.array([6, 7, 899]),np.array([0, 1, 245]))[0]\n assert pic.get_label() == '$H_2O$'\n x, y = pic.get_data()\n assert all(x == np.array([6, 7, 899]))\n assert all(y == np.array([0, 1, 245]))\n"], "entry_point": "f_17138464", "intent": "subscript text 'H20' with '2' as subscripted in matplotlib labels for arrays 'x' and 'y'.", "library": ["matplotlib", "numpy"]} {"task_id": 9138112, "prompt": "def f_9138112(mylist):\n\treturn ", "suffix": "", "canonical_solution": "[x for x in mylist if len(x) == 3]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[1,2,3], 'abc', [345,53], 'avsvasf']) == [[1,2,3], 'abc']\n", "\n assert candidate([[435,654.4,45,2],[34,34,757,65,32423]]) == []\n"], "entry_point": "f_9138112", "intent": "loop over a list `mylist` if sublists length equals 3", "library": []} {"task_id": 1807026, "prompt": "def f_1807026():\n\t", "suffix": "\n\treturn lst", "canonical_solution": "lst = [Object() for _ in range(100)]", "test_start": "\nclass Object(): \n def __init__(self): \n self.name = \"object\"\n\ndef check(candidate):", "test": ["\n lst = candidate()\n assert all([x.name == \"object\" for x in lst])\n"], "entry_point": "f_1807026", "intent": "initialize a list `lst` of 100 objects Object()", "library": []} {"task_id": 13793321, "prompt": "def f_13793321(df1, df2):\n\treturn ", "suffix": "", "canonical_solution": "df1.merge(df2, on='Date_Time')", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df1 = pd.DataFrame([[1, 2, 3]], columns=[\"Date\", \"Time\", \"Date_Time\"])\n df2 = pd.DataFrame([[1, 3],[4, 9]], columns=[\"Name\", \"Date_Time\"])\n assert candidate(df1, df2).to_dict() == {'Date': {0: 1}, 'Time': {0: 2}, 'Date_Time': {0: 3}, 'Name': {0: 1}}\n"], "entry_point": "f_13793321", "intent": "joining data from dataframe `df1` with data from dataframe `df2` based on matching values of column 'Date_Time' in both dataframes", "library": ["pandas"]} {"task_id": 3367288, "prompt": "def f_3367288(str1):\n\treturn ", "suffix": "", "canonical_solution": "'first string is: %s, second one is: %s' % (str1, 'geo.tif')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"s001\") == \"first string is: s001, second one is: geo.tif\"\n", "\n assert candidate(\"\") == \"first string is: , second one is: geo.tif\"\n", "\n assert candidate(\" \") == \"first string is: , second one is: geo.tif\"\n"], "entry_point": "f_3367288", "intent": "use `%s` operator to print variable values `str1` inside a string", "library": []} {"task_id": 3475251, "prompt": "def f_3475251():\n\treturn ", "suffix": "", "canonical_solution": "[x.strip() for x in '2.MATCHES $$TEXT$$ STRING'.split('$$TEXT$$')]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == ['2.MATCHES', 'STRING']\n"], "entry_point": "f_3475251", "intent": "Split a string '2.MATCHES $$TEXT$$ STRING' by a delimiter '$$TEXT$$'", "library": []} {"task_id": 273192, "prompt": "def f_273192(directory):\n\t", "suffix": "\n\treturn ", "canonical_solution": "if (not os.path.exists(directory)):\n\t os.makedirs(directory)", "test_start": "\nimport os \n\ndef check(candidate):", "test": ["\n candidate(\"hello\")\n assert os.path.exists(\"hello\")\n", "\n candidate(\"_some_dir\")\n assert os.path.exists(\"_some_dir\")\n"], "entry_point": "f_273192", "intent": "check if directory `directory ` exists and create it if necessary", "library": ["os"]} {"task_id": 273192, "prompt": "def f_273192(path):\n\t", "suffix": "\n\treturn ", "canonical_solution": "try:\n\t os.makedirs(path)\n\texcept OSError:\n\t if (not os.path.isdir(path)):\n\t raise", "test_start": "\nimport os \n\ndef check(candidate):", "test": ["\n candidate(\"hello\")\n assert os.path.exists(\"hello\")\n", "\n candidate(\"_some_dir\")\n assert os.path.exists(\"_some_dir\")\n"], "entry_point": "f_273192", "intent": "check if a directory `path` exists and create it if necessary", "library": ["os"]} {"task_id": 273192, "prompt": "def f_273192(path):\n\t", "suffix": "\n\treturn ", "canonical_solution": "try:\n\t os.makedirs(path)\n\texcept OSError as exception:\n\t if (exception.errno != errno.EEXIST):\n\t raise", "test_start": "\nimport os \n\ndef check(candidate):", "test": ["\n candidate(\"hello\")\n assert os.path.exists(\"hello\")\n", "\n candidate(\"_some_dir\")\n assert os.path.exists(\"_some_dir\")\n"], "entry_point": "f_273192", "intent": "check if a directory `path` exists and create it if necessary", "library": ["os"]} {"task_id": 18785032, "prompt": "def f_18785032(text):\n\treturn ", "suffix": "", "canonical_solution": "re.sub('\\\\bH3\\\\b', 'H1', text)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(\"hello world and H3\") == \"hello world and H1\"\n", "\n assert candidate(\"hello world and H1\") == \"hello world and H1\"\n", "\n assert candidate(\"hello world!\") == \"hello world!\"\n"], "entry_point": "f_18785032", "intent": "Replace a separate word 'H3' by 'H1' in a string 'text'", "library": ["re"]} {"task_id": 1450897, "prompt": "def f_1450897():\n\treturn ", "suffix": "", "canonical_solution": "re.sub('\\\\D', '', 'aas30dsa20')", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate() == \"3020\"\n"], "entry_point": "f_1450897", "intent": "substitute ASCII letters in string 'aas30dsa20' with empty string ''", "library": ["re"]} {"task_id": 1450897, "prompt": "def f_1450897():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"\"\"\".join([x for x in 'aas30dsa20' if x.isdigit()])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == \"3020\"\n"], "entry_point": "f_1450897", "intent": "get digits only from a string `aas30dsa20` using lambda function", "library": []} {"task_id": 14435268, "prompt": "def f_14435268(soup):\n\treturn ", "suffix": "", "canonical_solution": "soup.find('name').string", "test_start": "\nfrom bs4 import BeautifulSoup\n\ndef check(candidate):", "test": ["\n content = \"LastNameFirstName+90 333 12345\"\n soup = BeautifulSoup(content)\n assert candidate(soup) == \"LastName\"\n", "\n content = \"hello world!\"\n soup = BeautifulSoup(content)\n assert candidate(soup) == \"hello world!\"\n"], "entry_point": "f_14435268", "intent": "access a tag called \"name\" in beautifulsoup `soup`", "library": ["bs4"]} {"task_id": 20180210, "prompt": "def f_20180210(A, B):\n\treturn ", "suffix": "", "canonical_solution": "np.concatenate((A, B))", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n A = np.array([1,2])\n B = np.array([3,4])\n assert np.allclose(candidate(A, B), np.array([1,2,3,4]))\n", "\n A = np.array([[1,2]])\n B = np.array([[3,4]])\n assert np.allclose(candidate(A, B), np.array([[1,2],[3,4]]))\n", "\n A = np.array([[1],[2]])\n B = np.array([[3],[4]])\n assert np.allclose(candidate(A, B), np.array([[1],[2],[3],[4]]))\n", "\n a = np.array([[1, 3, 4], [4, 5, 6], [6, 0, -1]])\n b = np.array([[5, 6, 1], [0, 2, -1], [9, 4, 1]])\n expected = np.array([[ 1, 3, 4], [ 4, 5, 6],\n [ 6, 0, -1], [ 5, 6, 1], [ 0, 2, -1], [ 9, 4, 1]])\n assert np.array_equal(candidate(a, b), expected)\n"], "entry_point": "f_20180210", "intent": "Create new matrix object by concatenating data from matrix A and matrix B", "library": ["numpy"]} {"task_id": 20180210, "prompt": "def f_20180210(A, B):\n\treturn ", "suffix": "", "canonical_solution": "np.vstack((A, B))", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n A = np.array([1,2])\n B = np.array([3,4])\n assert np.allclose(candidate(A, B), np.array([[1,2],[3,4]]))\n", "\n A = np.array([[1,2]])\n B = np.array([[3,4]])\n assert np.allclose(candidate(A, B), np.array([[1,2],[3,4]]))\n", "\n A = np.array([[1],[2]])\n B = np.array([[3],[4]])\n assert np.allclose(candidate(A, B), np.array([[1],[2],[3],[4]]))\n", "\n a = np.array([[1, 3, 4], [4, 5, 6], [6, 0, -1]])\n b = np.array([[5, 6, 1], [0, 2, -1], [9, 4, 1]])\n expected = np.array([[ 1, 3, 4], [ 4, 5, 6],\n [ 6, 0, -1], [ 5, 6, 1], [ 0, 2, -1], [ 9, 4, 1]])\n assert np.array_equal(candidate(a, b), expected)\n"], "entry_point": "f_20180210", "intent": "concat two matrices `A` and `B` in numpy", "library": ["numpy"]} {"task_id": 2011048, "prompt": "def f_2011048(filepath):\n\treturn ", "suffix": "", "canonical_solution": "os.stat(filepath).st_size", "test_start": "\nimport os\n\ndef check(candidate):", "test": ["\n with open(\"tmp.txt\", 'w') as fw: fw.write(\"hello world!\")\n assert candidate(\"tmp.txt\") == 12\n", "\n with open(\"tmp.txt\", 'w') as fw: fw.write(\"\")\n assert candidate(\"tmp.txt\") == 0\n", "\n with open(\"tmp.txt\", 'w') as fw: fw.write('\\n')\n assert candidate(\"tmp.txt\") == 1\n", "\n filename = 'o.txt'\n with open (filename, 'w') as f:\n f.write('a')\n assert candidate(filename) == 1\n"], "entry_point": "f_2011048", "intent": "Get the characters count in a file `filepath`", "library": ["os"]} {"task_id": 2600191, "prompt": "def f_2600191(l):\n\treturn ", "suffix": "", "canonical_solution": "l.count('a')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"123456asf\") == 1\n", "\n assert candidate(\"123456gyjnccfgsf\") == 0\n", "\n assert candidate(\"aA\"*10) == 10\n"], "entry_point": "f_2600191", "intent": "count the occurrences of item \"a\" in list `l`", "library": []} {"task_id": 2600191, "prompt": "def f_2600191(l):\n\treturn ", "suffix": "", "canonical_solution": "Counter(l)", "test_start": "\nfrom collections import Counter \n\ndef check(candidate):", "test": ["\n assert dict(candidate(\"123456asf\")) == {'1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, 'a': 1, 's': 1, 'f': 1}\n", "\n assert candidate(\"123456gyjnccfgsf\") == {'1': 1,'2': 1,'3': 1,'4': 1,'5': 1,'6': 1,'g': 2,'y': 1,'j': 1,'n': 1,'c': 2,'f': 2,'s': 1}\n", "\n assert candidate(\"aA\"*10) == {'a': 10, 'A': 10}\n", "\n y = candidate([1, 6])\n assert y[1] == 1\n assert y[6] == 1\n"], "entry_point": "f_2600191", "intent": "count the occurrences of items in list `l`", "library": ["collections"]} {"task_id": 2600191, "prompt": "def f_2600191(l):\n\treturn ", "suffix": "", "canonical_solution": "[[x, l.count(x)] for x in set(l)]", "test_start": "\nfrom collections import Counter \n\ndef check(candidate):", "test": ["\n assert sorted(candidate(\"123456asf\")) == [['1', 1],['2', 1],['3', 1],['4', 1],['5', 1],['6', 1],['a', 1],['f', 1],['s', 1]]\n", "\n assert sorted(candidate(\"aA\"*10)) == [['A', 10], ['a', 10]]\n"], "entry_point": "f_2600191", "intent": "count the occurrences of items in list `l`", "library": ["collections"]} {"task_id": 2600191, "prompt": "def f_2600191(l):\n\treturn ", "suffix": "", "canonical_solution": "dict(((x, l.count(x)) for x in set(l)))", "test_start": "\nfrom collections import Counter \n\ndef check(candidate):", "test": ["\n assert candidate(\"123456asf\") == {'4': 1, 'a': 1, '1': 1, 's': 1, '6': 1, 'f': 1, '3': 1, '5': 1, '2': 1}\n", "\n assert candidate(\"aA\"*10) == {'A': 10, 'a': 10}\n", "\n assert candidate([1, 6]) == {1: 1, 6: 1}\n"], "entry_point": "f_2600191", "intent": "count the occurrences of items in list `l`", "library": ["collections"]} {"task_id": 2600191, "prompt": "def f_2600191(l):\n\treturn ", "suffix": "", "canonical_solution": "l.count('b')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"123456abbbsf\") == 3\n", "\n assert candidate(\"123456gyjnccfgsf\") == 0\n", "\n assert candidate(\"Ab\"*10) == 10\n"], "entry_point": "f_2600191", "intent": "count the occurrences of item \"b\" in list `l`", "library": []} {"task_id": 12842997, "prompt": "def f_12842997(srcfile, dstdir):\n\t", "suffix": "\n\treturn ", "canonical_solution": "shutil.copy(srcfile, dstdir)", "test_start": "\nimport shutil\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n shutil.copy = Mock()\n try:\n candidate('opera.txt', '/')\n except:\n return False \n"], "entry_point": "f_12842997", "intent": "copy file `srcfile` to directory `dstdir`", "library": ["shutil"]} {"task_id": 1555968, "prompt": "def f_1555968(x):\n\treturn ", "suffix": "", "canonical_solution": "max(k for k, v in x.items() if v != 0)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'a': 1, 'b': 2, 'c': 2000}) == 'c'\n", "\n assert candidate({'a': 0., 'b': 0, 'c': 200.02}) == 'c'\n", "\n assert candidate({'key1': -100, 'key2': 0.}) == 'key1'\n", "\n x = {1:\"g\", 2:\"a\", 5:\"er\", -4:\"dr\"}\n assert candidate(x) == 5\n"], "entry_point": "f_1555968", "intent": "find the key associated with the largest value in dictionary `x` whilst key is non-zero value", "library": []} {"task_id": 17021863, "prompt": "def f_17021863(file):\n\t", "suffix": "\n\treturn ", "canonical_solution": "file.seek(0)", "test_start": "\ndef check(candidate):", "test": ["\n with open ('a.txt', 'w') as f:\n f.write('kangaroo\\nkoala\\noxford\\n')\n f = open('a.txt', 'r')\n f.read()\n candidate(f)\n assert f.readline() == 'kangaroo\\n'\n"], "entry_point": "f_17021863", "intent": "Put the curser at beginning of the file", "library": []} {"task_id": 38152389, "prompt": "def f_38152389(df):\n\t", "suffix": "\n\treturn df", "canonical_solution": "df['c'] = np.where(df['a'].isnull, df['b'], df['a'])", "test_start": "\nimport numpy as np \nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df = pd.DataFrame({'a': [1,2,3], 'b': [0,0,0]})\n assert np.allclose(candidate(df), pd.DataFrame({'a': [1,2,3], 'b': [0,0,0], 'c': [0,0,0]}))\n", "\n df = pd.DataFrame({'a': [0,2,3], 'b': [4,5,6]})\n assert np.allclose(candidate(df), pd.DataFrame({'a': [0,2,3], 'b': [4,5,6], 'c': [4,5,6]}))\n"], "entry_point": "f_38152389", "intent": "combine values from column 'b' and column 'a' of dataframe `df` into column 'c' of datafram `df`", "library": ["numpy", "pandas"]} {"task_id": 4175686, "prompt": "def f_4175686(d):\n\t", "suffix": "\n\treturn d", "canonical_solution": "del d['ele']", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({\"ale\":1, \"ele\": 2}) == {\"ale\": 1}\n"], "entry_point": "f_4175686", "intent": "remove key 'ele' from dictionary `d`", "library": []} {"task_id": 11574195, "prompt": "def f_11574195():\n\treturn ", "suffix": "", "canonical_solution": "['it'] + ['was'] + ['annoying']", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == ['it', 'was', 'annoying']\n"], "entry_point": "f_11574195", "intent": "merge list `['it']` and list `['was']` and list `['annoying']` into one list", "library": []} {"task_id": 587647, "prompt": "def f_587647(x):\n\treturn ", "suffix": "", "canonical_solution": "str(int(x) + 1).zfill(len(x))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"001\") == \"002\"\n", "\n assert candidate(\"100\") == \"101\"\n"], "entry_point": "f_587647", "intent": "increment a value with leading zeroes in a number `x`", "library": []} {"task_id": 17315881, "prompt": "def f_17315881(df):\n\treturn ", "suffix": "", "canonical_solution": "all(df.index[:-1] <= df.index[1:])", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df1 = pd.DataFrame({'a': [1,2], 'bb': [0,2]})\n assert candidate(df1) == True\n", "\n df2 = pd.DataFrame({'a': [1,2,3,4,5], 'bb': [0,3,5,7,9]})\n shuffled = df2.sample(frac=3, replace=True)\n assert candidate(shuffled) == False\n", "\n df = pd.DataFrame([[1, 2], [5, 4]], columns=['a', 'b'])\n assert candidate(df)\n"], "entry_point": "f_17315881", "intent": "check if a pandas dataframe `df`'s index is sorted", "library": ["pandas"]} {"task_id": 16296643, "prompt": "def f_16296643(t):\n\treturn ", "suffix": "", "canonical_solution": "list(t)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate((0, 1, 2)) == [0,1,2]\n", "\n assert candidate(('a', [], 100)) == ['a', [], 100]\n"], "entry_point": "f_16296643", "intent": "Convert tuple `t` to list", "library": []} {"task_id": 16296643, "prompt": "def f_16296643(t):\n\treturn ", "suffix": "", "canonical_solution": "tuple(t)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([0,1,2]) == (0, 1, 2)\n", "\n assert candidate(['a', [], 100]) == ('a', [], 100)\n"], "entry_point": "f_16296643", "intent": "Convert list `t` to tuple", "library": []} {"task_id": 16296643, "prompt": "def f_16296643(level1):\n\t", "suffix": "\n\treturn level1", "canonical_solution": "level1 = map(list, level1)", "test_start": "\ndef check(candidate):", "test": ["\n t = ((1, 2), (3, 4))\n t = candidate(t)\n assert list(t) == [[1, 2], [3, 4]]\n"], "entry_point": "f_16296643", "intent": "Convert tuple `level1` to list", "library": []} {"task_id": 3880399, "prompt": "def f_3880399(dataobject, logFile):\n\treturn ", "suffix": "", "canonical_solution": "pprint.pprint(dataobject, logFile)", "test_start": "\nimport pprint \n\ndef check(candidate):", "test": ["\n f = open('kkk.txt', 'w')\n candidate('hello', f)\n f.close()\n with open('kkk.txt', 'r') as f:\n assert 'hello' in f.readline()\n"], "entry_point": "f_3880399", "intent": "send the output of pprint object `dataobject` to file `logFile`", "library": ["pprint"]} {"task_id": 21800169, "prompt": "def f_21800169(df):\n\treturn ", "suffix": "", "canonical_solution": "df.loc[df['BoolCol']]", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[True, 2, 3], [False, 5, 6]], columns = ['BoolCol', 'a', 'b'])\n y = candidate(df)\n assert y['a'][0] == 2\n assert y['b'][0] == 3\n"], "entry_point": "f_21800169", "intent": "get index of rows in column 'BoolCol'", "library": ["pandas"]} {"task_id": 21800169, "prompt": "def f_21800169(df):\n\treturn ", "suffix": "", "canonical_solution": "df.iloc[np.flatnonzero(df['BoolCol'])]", "test_start": "\nimport numpy as np\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[True, 2, 3], [False, 5, 6]], columns = ['BoolCol', 'a', 'b'])\n y = candidate(df)\n assert y['a'][0] == 2\n assert y['b'][0] == 3\n"], "entry_point": "f_21800169", "intent": "Create a list containing the indexes of rows where the value of column 'BoolCol' in dataframe `df` are equal to True", "library": ["numpy", "pandas"]} {"task_id": 21800169, "prompt": "def f_21800169(df):\n\treturn ", "suffix": "", "canonical_solution": "df[df['BoolCol'] == True].index.tolist()", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[True, 2, 3], [False, 5, 6]], columns = ['BoolCol', 'a', 'b'])\n y = candidate(df)\n assert y == [0]\n"], "entry_point": "f_21800169", "intent": "from dataframe `df` get list of indexes of rows where column 'BoolCol' values match True", "library": ["pandas"]} {"task_id": 21800169, "prompt": "def f_21800169(df):\n\treturn ", "suffix": "", "canonical_solution": "df[df['BoolCol']].index.tolist()", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[True, 2, 3], [False, 5, 6]], columns = ['BoolCol', 'a', 'b'])\n y = candidate(df)\n assert y == [0]\n"], "entry_point": "f_21800169", "intent": "get index of rows in dataframe `df` which column 'BoolCol' matches value True", "library": ["pandas"]} {"task_id": 299446, "prompt": "def f_299446(owd):\n\t", "suffix": "\n\treturn ", "canonical_solution": "os.chdir(owd)", "test_start": "\nimport os\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n os.chdir = Mock()\n try:\n candidate('/')\n except:\n assert False\n"], "entry_point": "f_299446", "intent": "change working directory to the directory `owd`", "library": ["os"]} {"task_id": 14695134, "prompt": "def f_14695134(c, testfield):\n\t", "suffix": "\n\treturn ", "canonical_solution": "c.execute(\"INSERT INTO test VALUES (?, 'bar')\", (testfield,))", "test_start": "\nimport sqlite3\n\ndef check(candidate):", "test": ["\n conn = sqlite3.connect('dev.db')\n cur = conn.cursor()\n cur.execute(\"CREATE TABLE test (x VARCHAR(10), y VARCHAR(10))\")\n candidate(cur, 'kang')\n cur.execute(\"SELECT * FROM test\")\n rows = cur.fetchall()\n assert len(rows) == 1\n"], "entry_point": "f_14695134", "intent": "insert data from a string `testfield` to sqlite db `c`", "library": ["sqlite3"]} {"task_id": 24242433, "prompt": "def f_24242433():\n\treturn ", "suffix": "", "canonical_solution": "b'\\\\x89\\\\n'.decode('unicode_escape')", "test_start": "\nimport sqlite3\n\ndef check(candidate):", "test": ["\n assert candidate() == '\\x89\\n'\n"], "entry_point": "f_24242433", "intent": "decode string \"\\\\x89\\\\n\" into a normal string", "library": ["sqlite3"]} {"task_id": 24242433, "prompt": "def f_24242433(raw_string):\n\treturn ", "suffix": "", "canonical_solution": "raw_string.decode('unicode_escape')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(b\"Hello\") == \"Hello\"\n", "\n assert candidate(b\"hello world!\") == \"hello world!\"\n", "\n assert candidate(b\". ?? !!x\") == \". ?? !!x\"\n"], "entry_point": "f_24242433", "intent": "convert a raw string `raw_string` into a normal string", "library": []} {"task_id": 24242433, "prompt": "def f_24242433(raw_byte_string):\n\treturn ", "suffix": "", "canonical_solution": "raw_byte_string.decode('unicode_escape')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(b\"Hello\") == \"Hello\"\n", "\n assert candidate(b\"hello world!\") == \"hello world!\"\n", "\n assert candidate(b\". ?? !!x\") == \". ?? !!x\"\n"], "entry_point": "f_24242433", "intent": "convert a raw string `raw_byte_string` into a normal string", "library": []} {"task_id": 22882922, "prompt": "def f_22882922(s):\n\treturn ", "suffix": "", "canonical_solution": "[m.group(0) for m in re.finditer('(\\\\d)\\\\1*', s)]", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate('111234') == ['111', '2', '3', '4']\n"], "entry_point": "f_22882922", "intent": "split a string `s` with into all strings of repeated characters", "library": ["re"]} {"task_id": 4143502, "prompt": "def f_4143502():\n\treturn ", "suffix": "", "canonical_solution": "plt.scatter(np.random.randn(100), np.random.randn(100), facecolors='none')", "test_start": "\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef check(candidate):", "test": ["\n assert 'matplotlib' in str(type(candidate()))\n"], "entry_point": "f_4143502", "intent": "scatter a plot with x, y position of `np.random.randn(100)` and face color equal to none", "library": ["matplotlib", "numpy"]} {"task_id": 4143502, "prompt": "def f_4143502():\n\treturn ", "suffix": "", "canonical_solution": "plt.plot(np.random.randn(100), np.random.randn(100), 'o', mfc='none')", "test_start": "\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef check(candidate):", "test": ["\n assert 'matplotlib' in str(type(candidate()[0]))\n"], "entry_point": "f_4143502", "intent": "do a scatter plot with empty circles", "library": ["matplotlib", "numpy"]} {"task_id": 32063985, "prompt": "def f_32063985(soup):\n\treturn ", "suffix": "", "canonical_solution": "soup.find('div', id='main-content').decompose()", "test_start": "\nfrom bs4 import BeautifulSoup\n\ndef check(candidate):", "test": ["\n markup = \"This is not div
This is div 1
This is div 2
\"\n soup = BeautifulSoup(markup,\"html.parser\")\n candidate(soup)\n assert str(soup) == 'This is not div
This is div 1
'\n"], "entry_point": "f_32063985", "intent": "remove a div from `soup` with a id `main-content` using beautifulsoup", "library": ["bs4"]} {"task_id": 27975069, "prompt": "def f_27975069(df):\n\treturn ", "suffix": "", "canonical_solution": "df[df['ids'].str.contains('ball')]", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n f = pd.DataFrame([[\"ball1\", 1, 2], [\"hall\", 5, 4]], columns = ['ids', 'x', 'y'])\n f1 = candidate(f)\n assert f1['x'][0] == 1\n assert f1['y'][0] == 2\n"], "entry_point": "f_27975069", "intent": "filter rows of datafram `df` containing key word `ball` in column `ids`", "library": ["pandas"]} {"task_id": 20461165, "prompt": "def f_20461165(df):\n\treturn ", "suffix": "", "canonical_solution": "df.reset_index(level=0, inplace=True)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[384, 593], [781, 123]], columns = ['gi', 'ptt_loc'])\n candidate(df)\n assert df['index'][0] == 0\n assert df['index'][1] == 1\n"], "entry_point": "f_20461165", "intent": "convert index at level 0 into a column in dataframe `df`", "library": ["pandas"]} {"task_id": 20461165, "prompt": "def f_20461165(df):\n\t", "suffix": "\n\treturn ", "canonical_solution": "df['index1'] = df.index", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[384, 593], [781, 123]], columns = ['gi', 'ptt_loc'])\n candidate(df)\n assert df['index1'][0] == 0\n assert df['index1'][1] == 1\n"], "entry_point": "f_20461165", "intent": "Add indexes in a data frame `df` to a column `index1`", "library": ["pandas"]} {"task_id": 20461165, "prompt": "def f_20461165(df):\n\treturn ", "suffix": "", "canonical_solution": "df.reset_index(level=['tick', 'obs'])", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([['2016-09-13', 'C', 2, 0.0139], ['2016-07-17', 'A', 2, 0.5577]], columns = ['tick', 'tag', 'obs', 'val'])\n df = df.set_index(['tick', 'tag', 'obs'])\n df = candidate(df)\n assert df['tick']['C'] == '2016-09-13'\n"], "entry_point": "f_20461165", "intent": "convert pandas index in a dataframe `df` to columns", "library": ["pandas"]} {"task_id": 4685571, "prompt": "def f_4685571(b):\n\treturn ", "suffix": "", "canonical_solution": "[x[::-1] for x in b]", "test_start": "\ndef check(candidate):", "test": ["\n b = [('spam',0), ('eggs',1)]\n b1 = candidate(b)\n assert b1 == [(0, 'spam'), (1, 'eggs')]\n"], "entry_point": "f_4685571", "intent": "Get reverse of list items from list 'b' using extended slicing", "library": []} {"task_id": 17960441, "prompt": "def f_17960441(a, b):\n\treturn ", "suffix": "", "canonical_solution": "np.array([zip(x, y) for x, y in zip(a, b)])", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a = np.array([[9, 8], [7, 6]])\n b = np.array([[7, 1], [5, 2]])\n c = candidate(a, b)\n expected = [(9, 7), (8, 1)]\n ctr = 0\n for i in c[0]:\n assert i == expected[ctr]\n ctr += 1\n"], "entry_point": "f_17960441", "intent": "join each element in array `a` with element at the same index in array `b` as a tuple", "library": ["numpy"]} {"task_id": 17960441, "prompt": "def f_17960441(a, b):\n\treturn ", "suffix": "", "canonical_solution": "np.array(list(zip(a.ravel(),b.ravel())), dtype=('i4,i4')).reshape(a.shape)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a = np.array([[9, 8], [7, 6]])\n b = np.array([[7, 1], [5, 2]])\n c = candidate(a, b)\n e = np.array([[(9, 7), (8, 1)], [(7, 5), (6, 2)]], dtype=[('f0', '= 99) & (df['closing_price'] <= 101)]", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([67, 68, 69, 70, 99, 100, 101, 102], columns = ['closing_price'])\n assert candidate(df).shape[0] == 3\n"], "entry_point": "f_31617845", "intent": "select rows in a dataframe `df` column 'closing_price' between two values 99 and 101", "library": ["pandas"]} {"task_id": 25698710, "prompt": "def f_25698710(df):\n\treturn ", "suffix": "", "canonical_solution": "df.replace({'\\n': '
'}, regex=True)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame(['klm\\npqr', 'wxy\\njkl'], columns = ['val'])\n expected = pd.DataFrame(['klm
pqr', 'wxy
jkl'], columns = ['val'])\n assert pd.DataFrame.equals(candidate(df), expected)\n"], "entry_point": "f_25698710", "intent": "replace all occurences of newlines `\\n` with `
` in dataframe `df`", "library": ["pandas"]} {"task_id": 25698710, "prompt": "def f_25698710(df):\n\treturn ", "suffix": "", "canonical_solution": "df.replace({'\\n': '
'}, regex=True)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame(['klm\\npqr', 'wxy\\njkl'], columns = ['val'])\n expected = pd.DataFrame(['klm
pqr', 'wxy
jkl'], columns = ['val'])\n assert pd.DataFrame.equals(candidate(df), expected)\n"], "entry_point": "f_25698710", "intent": "replace all occurrences of a string `\\n` by string `
` in a pandas data frame `df`", "library": ["pandas"]} {"task_id": 41923858, "prompt": "def f_41923858(word):\n\treturn ", "suffix": "", "canonical_solution": "[(x + y) for x, y in zip(word, word[1:])]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('abcdef') == ['ab', 'bc', 'cd', 'de', 'ef']\n", "\n assert candidate([\"hello\", \"world\", \"!\"]) == [\"helloworld\", \"world!\"]\n"], "entry_point": "f_41923858", "intent": "create a list containing each two adjacent letters in string `word` as its elements", "library": []} {"task_id": 41923858, "prompt": "def f_41923858(word):\n\treturn ", "suffix": "", "canonical_solution": "list(map(lambda x, y: x + y, word[:-1], word[1:]))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('abcdef') == ['ab', 'bc', 'cd', 'de', 'ef']\n"], "entry_point": "f_41923858", "intent": "Get a list of pairs from a string `word` using lambda function", "library": []} {"task_id": 9760588, "prompt": "def f_9760588(myString):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('(https?://[^\\\\s]+)', myString)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(\"This is a link http://www.google.com\") == [\"http://www.google.com\"]\n", "\n assert candidate(\"Please refer to the website: http://www.google.com\") == [\"http://www.google.com\"]\n"], "entry_point": "f_9760588", "intent": "extract a url from a string `myString`", "library": ["re"]} {"task_id": 9760588, "prompt": "def f_9760588(myString):\n\treturn ", "suffix": "", "canonical_solution": "re.search('(?Phttps?://[^\\\\s]+)', myString).group('url')", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(\"This is a link http://www.google.com\") == \"http://www.google.com\"\n", "\n assert candidate(\"Please refer to the website: http://www.google.com\") == \"http://www.google.com\"\n"], "entry_point": "f_9760588", "intent": "extract a url from a string `myString`", "library": ["re"]} {"task_id": 5843518, "prompt": "def f_5843518(mystring):\n\treturn ", "suffix": "", "canonical_solution": "re.sub('[^A-Za-z0-9]+', '', mystring)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate('Special $#! characters spaces 888323') == 'Specialcharactersspaces888323'\n"], "entry_point": "f_5843518", "intent": "remove all special characters, punctuation and spaces from a string `mystring` using regex", "library": ["re"]} {"task_id": 36674519, "prompt": "def f_36674519():\n\treturn ", "suffix": "", "canonical_solution": "pd.date_range('2016-01-01', freq='WOM-2FRI', periods=13)", "test_start": "\nimport pandas as pd\nimport datetime\n\ndef check(candidate):", "test": ["\n actual = candidate() \n expected = [[2016, 1, 8], [2016, 2, 12],\n [2016, 3, 11], [2016, 4, 8],\n [2016, 5, 13], [2016, 6, 10],\n [2016, 7, 8], [2016, 8, 12],\n [2016, 9, 9], [2016, 10, 14],\n [2016, 11, 11], [2016, 12, 9],\n [2017, 1, 13]]\n for i in range(0, len(expected)):\n d = datetime.date(expected[i][0], expected[i][1], expected[i][2])\n assert d == actual[i].date()\n"], "entry_point": "f_36674519", "intent": "create a DatetimeIndex containing 13 periods of the second friday of each month starting from date '2016-01-01'", "library": ["datetime", "pandas"]} {"task_id": 508657, "prompt": "def f_508657():\n\t", "suffix": "\n\treturn matrix", "canonical_solution": "matrix = [['a', 'b'], ['c', 'd'], ['e', 'f']]", "test_start": "\ndef check(candidate):", "test": ["\n matrix = candidate()\n assert len(matrix) == 3\n assert all([len(row)==2 for row in matrix])\n"], "entry_point": "f_508657", "intent": "Create multidimensional array `matrix` with 3 rows and 2 columns in python", "library": []} {"task_id": 1007481, "prompt": "def f_1007481(mystring):\n\treturn ", "suffix": "", "canonical_solution": "mystring.replace(' ', '_')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(' ') == '_'\n", "\n assert candidate(' _ ') == '___'\n", "\n assert candidate('') == ''\n", "\n assert candidate('123123') == '123123'\n", "\n assert candidate('\\_ ') == '\\__'\n"], "entry_point": "f_1007481", "intent": "replace spaces with underscore in string `mystring`", "library": []} {"task_id": 1249786, "prompt": "def f_1249786(my_string):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\" \"\"\".join(my_string.split())", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('hello world ') == 'hello world'\n", "\n assert candidate('') == ''\n", "\n assert candidate(' ') == ''\n", "\n assert candidate(' hello') == 'hello'\n", "\n assert candidate(' h e l l o ') == 'h e l l o'\n"], "entry_point": "f_1249786", "intent": "split string `my_string` on white spaces", "library": []} {"task_id": 4444923, "prompt": "def f_4444923(filename):\n\treturn ", "suffix": "", "canonical_solution": "os.path.splitext(filename)[0]", "test_start": "\nimport os\n\ndef check(candidate):", "test": ["\n assert candidate('/Users/test/hello.txt') == '/Users/test/hello'\n", "\n assert candidate('hello.txt') == 'hello'\n", "\n assert candidate('hello') == 'hello'\n", "\n assert candidate('.gitignore') == '.gitignore'\n"], "entry_point": "f_4444923", "intent": "get filename without extension from file `filename`", "library": ["os"]} {"task_id": 13728486, "prompt": "def f_13728486(l):\n\treturn ", "suffix": "", "canonical_solution": "[sum(l[:i]) for i, _ in enumerate(l)]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3]) == [0,1,3]\n", "\n assert candidate([]) == []\n", "\n assert candidate([1]) == [0]\n"], "entry_point": "f_13728486", "intent": "get a list containing the sum of each element `i` in list `l` plus the previous elements", "library": []} {"task_id": 9743134, "prompt": "def f_9743134():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"Docs/src/Scripts/temp\"\"\".replace('/', '/\\x00/').split('\\x00')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == ['Docs/', '/src/', '/Scripts/', '/temp']\n", "\n assert candidate() != ['Docs', 'src', 'Scripts', 'temp']\n"], "entry_point": "f_9743134", "intent": "split a string `Docs/src/Scripts/temp` by `/` keeping `/` in the result", "library": []} {"task_id": 20546419, "prompt": "def f_20546419(r):\n\treturn ", "suffix": "", "canonical_solution": "np.random.shuffle(np.transpose(r))", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a1 = np.array([[ 1, 20], [ 2, 30]])\n candidate(a1)\n assert np.array_equal(a1, np.array([[ 1, 20],[ 2, 30]])) or np.array_equal(a1, np.array([[ 20, 1], [ 30, 2]]))\n", "\n a2 = np.array([[ 1], [ 2]])\n candidate(a2) \n assert np.array_equal(a2,np.array([[ 1], [ 2]]) )\n", "\n a3 = np.array([[ 1,2,3]])\n candidate(a3)\n assert np.array_equal(a3,np.array([[ 1,2,3]])) or np.array_equal(a3,np.array([[ 2,1,3]])) or np.array_equal(a3,np.array([[ 1,3,2]])) or np.array_equal(a3,np.array([[3,2,1]])) or np.array_equal(a3,np.array([[3,1,2]])) or np.array_equal(a3,np.array([[2,3,1]])) \n", "\n a4 = np.zeros(shape=(5,2))\n candidate(a4)\n assert np.array_equal(a4, np.zeros(shape=(5,2)))\n"], "entry_point": "f_20546419", "intent": "shuffle columns of an numpy array 'r'", "library": ["numpy"]} {"task_id": 32675861, "prompt": "def f_32675861(df):\n\t", "suffix": "\n\treturn df", "canonical_solution": "df['D'] = df['B']", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df_1 = pd.DataFrame({'A': [1,2,3], 'B': ['a', 'b', 'c']})\n candidate(df_1)\n assert (df_1['D'] == df_1['B']).all()\n", "\n df_2 = pd.DataFrame({'A': [1,2,3], 'B': [1, 'A', 'B']})\n candidate(df_2)\n assert (df_2['D'] == df_2['B']).all()\n", "\n df_3 = pd.DataFrame({'B': [1]})\n candidate(df_3)\n assert df_3['D'][0] == 1\n", "\n df_4 = pd.DataFrame({'B': []})\n candidate(df_4)\n assert len(df_4['D']) == 0\n"], "entry_point": "f_32675861", "intent": "copy all values in a column 'B' to a new column 'D' in a pandas data frame 'df'", "library": ["pandas"]} {"task_id": 14227561, "prompt": "def f_14227561(data):\n\treturn ", "suffix": "", "canonical_solution": "list(data['A']['B'].values())[0]['maindata'][0]['Info']", "test_start": "\nimport json\n\ndef check(candidate):", "test": ["\n s1 = '{\"A\":{\"B\":{\"unknown\":{\"1\":\"F\",\"maindata\":[{\"Info\":\"TEXT\"}]}}}}'\n data = json.loads(s1)\n assert candidate(data) == 'TEXT'\n", "\n s2 = '{\"A\":{\"B\":{\"sample1\":{\"1\":\"F\",\"maindata\":[{\"Info\":\"TEXT!\"}]}}}}'\n data = json.loads(s2)\n assert candidate(data) == 'TEXT!'\n", "\n s3 = '{\"A\":{\"B\":{\"sample_weird_un\":{\"1\":\"F\",\"maindata\":[{\"Info\":\"!\"}]}}}}'\n data = json.loads(s3)\n assert candidate(data) == '!'\n", "\n s4 = '{\"A\":{\"B\":{\"sample_weird_un\":{\"1\":\"F\",\"maindata\":[{\"Info\":\"\"}]}}}}'\n data = json.loads(s4)\n assert candidate(data) == ''\n"], "entry_point": "f_14227561", "intent": "find a value within nested json 'data' where the key inside another key 'B' is unknown.", "library": ["json"]} {"task_id": 14858916, "prompt": "def f_14858916(string, predicate):\n\treturn ", "suffix": "", "canonical_solution": "all(predicate(x) for x in string)", "test_start": "\ndef check(candidate):", "test": ["\n def predicate(x):\n if x == 'a':\n return True\n else:\n return False\n assert candidate('aab', predicate) == False\n", "\n def predicate(x):\n if x == 'a':\n return True\n else:\n return False\n assert candidate('aa', predicate) == True\n", "\n def predicate(x):\n if x == 'a':\n return True\n else:\n return False\n assert candidate('', predicate) == True\n", "\n def predicate(x):\n if x.islower():\n return True\n else:\n return False\n assert candidate('abc', predicate) == True\n", "\n def predicate(x):\n if x.islower():\n return True\n else:\n return False\n assert candidate('Ab', predicate) == False\n", "\n def predicate(x):\n if x.islower():\n return True\n else:\n return False\n assert candidate('ABCD', predicate) == False\n"], "entry_point": "f_14858916", "intent": "check characters of string `string` are true predication of function `predicate`", "library": []} {"task_id": 574236, "prompt": "def f_574236():\n\treturn ", "suffix": "", "canonical_solution": "os.statvfs('/').f_files - os.statvfs('/').f_ffree", "test_start": "\nimport os \n\ndef check(candidate):", "test": ["\n assert candidate() == (os.statvfs('/').f_files - os.statvfs('/').f_ffree)\n"], "entry_point": "f_574236", "intent": "determine number of files on a drive with python", "library": ["os"]} {"task_id": 7011291, "prompt": "def f_7011291(cursor):\n\treturn ", "suffix": "", "canonical_solution": "cursor.fetchone()[0]", "test_start": "\nimport sqlite3\n\ndef check(candidate):", "test": ["\n conn = sqlite3.connect('main')\n cursor = conn.cursor()\n cursor.execute(\"CREATE TABLE student (name VARCHAR(10))\")\n cursor.execute(\"INSERT INTO student VALUES('abc')\")\n cursor.execute(\"SELECT * FROM student\")\n assert candidate(cursor) == 'abc'\n"], "entry_point": "f_7011291", "intent": "how to get a single result from a SQLite query from `cursor`", "library": ["sqlite3"]} {"task_id": 6378889, "prompt": "def f_6378889(user_input):\n\t", "suffix": "\n\treturn user_list", "canonical_solution": "user_list = [int(number) for number in user_input.split(',')]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('0') == [0]\n", "\n assert candidate('12') == [12]\n", "\n assert candidate('12,33,223') == [12, 33, 223]\n"], "entry_point": "f_6378889", "intent": "convert string `user_input` into a list of integers `user_list`", "library": []} {"task_id": 6378889, "prompt": "def f_6378889(user):\n\treturn ", "suffix": "", "canonical_solution": "[int(s) for s in user.split(',')]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('0') == [0]\n", "\n assert candidate('12') == [12]\n", "\n assert candidate('12,33,223') == [12, 33, 223]\n"], "entry_point": "f_6378889", "intent": "Get a list of integers by splitting a string `user` with comma", "library": []} {"task_id": 5212870, "prompt": "def f_5212870(list):\n\treturn ", "suffix": "", "canonical_solution": "sorted(list, key=lambda x: (x[0], -x[1]))", "test_start": "\ndef check(candidate):", "test": ["\n list = [(9, 0), (9, 1), (9, -1), (8, 5), (4, 5)]\n assert candidate(list) == [(4, 5), (8, 5), (9, 1), (9, 0), (9, -1)]\n"], "entry_point": "f_5212870", "intent": "Sorting a Python list `list` by the first item ascending and last item descending", "library": []} {"task_id": 403421, "prompt": "def f_403421(ut, cmpfun):\n\t", "suffix": "\n\treturn ut", "canonical_solution": "ut.sort(key=cmpfun, reverse=True)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([], lambda x: x) == []\n", "\n assert candidate(['a', 'b', 'c'], lambda x: x) == ['c', 'b', 'a']\n", "\n assert candidate([2, 1, 3], lambda x: -x) == [1, 2, 3]\n"], "entry_point": "f_403421", "intent": "sort a list of objects `ut`, based on a function `cmpfun` in descending order", "library": []} {"task_id": 403421, "prompt": "def f_403421(ut):\n\t", "suffix": "\n\treturn ut", "canonical_solution": "ut.sort(key=lambda x: x.count, reverse=True)", "test_start": "\nclass Tag: \n def __init__(self, name, count): \n self.name = name \n self.count = count \n\n def __str__(self):\n return f\"[{self.name}]-[{self.count}]\"\n\ndef check(candidate):", "test": ["\n result = candidate([Tag(\"red\", 1), Tag(\"blue\", 22), Tag(\"black\", 0)])\n assert (result[0].name == \"blue\") and (result[0].count == 22)\n assert (result[1].name == \"red\") and (result[1].count == 1)\n assert (result[2].name == \"black\") and (result[2].count == 0)\n"], "entry_point": "f_403421", "intent": "reverse list `ut` based on the `count` attribute of each object", "library": []} {"task_id": 3944876, "prompt": "def f_3944876(i):\n\treturn ", "suffix": "", "canonical_solution": "'ME' + str(i)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(100) == \"ME100\"\n", "\n assert candidate(0.22) == \"ME0.22\"\n", "\n assert candidate(\"text\") == \"MEtext\"\n"], "entry_point": "f_3944876", "intent": "cast an int `i` to a string and concat to string 'ME'", "library": []} {"task_id": 40903174, "prompt": "def f_40903174(df):\n\treturn ", "suffix": "", "canonical_solution": "df.sort_values(['System_num', 'Dis'])", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df1 = pd.DataFrame([[6, 1, 1], [5, 1, 1], [4, 1, 1], [3, 2, 1], [2, 2, 1], [1, 2, 1]], columns = ['Dis', 'System_num', 'Energy'])\n df_ans1 = pd.DataFrame([[4, 1, 1], [5, 1, 1], [6, 1, 1], [1, 2, 1], [2, 2, 1], [3, 2, 1]], columns = ['Dis', 'System_num', 'Energy'])\n assert (df_ans1.equals(candidate(df1).reset_index(drop = True))) == True\n", "\n df2 = pd.DataFrame([[6, 3, 1], [5, 2, 1], [4, 1, 1]], columns = ['Dis', 'System_num', 'Energy'])\n df_ans2 = pd.DataFrame([[4, 1, 1], [5, 2, 1], [6, 3, 1]], columns = ['Dis', 'System_num', 'Energy'])\n assert (df_ans2.equals(candidate(df2).reset_index(drop = True))) == True\n", "\n df3 = pd.DataFrame([[1, 3, 1], [3, 3, 1], [2, 3, 1], [6, 1, 1], [4, 1, 1], [5, 2, 1], [3, 2, 1]], columns = ['Dis', 'System_num', 'Energy'])\n df_ans3 = pd.DataFrame([[4, 1,1], [6, 1, 1], [3, 2, 1], [5, 2, 1], [1, 3, 1], [2, 3, 1], [3, 3, 1]], columns = ['Dis', 'System_num', 'Energy'])\n assert (df_ans3.equals(candidate(df3).reset_index(drop = True))) == True \n", "\n df4 = pd.DataFrame([[1, 2, 3], [1, 2, 3], [4, 1, 3]], columns = ['Dis', 'System_num', 'Energy'])\n df_ans4 = pd.DataFrame([[1, 2, 3], [1, 2, 3], [4, 1, 3]])\n assert (df_ans4.equals(candidate(df4).reset_index(drop = True))) == False\n"], "entry_point": "f_40903174", "intent": "Sorting data in Pandas DataFrame `df` with columns 'System_num' and 'Dis'", "library": ["pandas"]} {"task_id": 4454298, "prompt": "def f_4454298(infile, outfile):\n\t", "suffix": "\n\treturn ", "canonical_solution": "open(outfile, 'w').write('#test firstline\\n' + open(infile).read())", "test_start": "\nimport filecmp\n\ndef check(candidate): ", "test": ["\n open('test1.txt', 'w').write('test1')\n candidate('test1.txt', 'test1_out.txt')\n open('test1_ans.txt', 'w').write('#test firstline\\ntest1')\n assert filecmp.cmp('test1_out.txt', 'test1_ans.txt') == True\n", "\n open('test2.txt', 'w').write('\\ntest2\\n')\n candidate('test2.txt', 'test2_out.txt')\n open('test2_ans.txt', 'w').write('#test firstline\\n\\ntest2\\n')\n assert filecmp.cmp('test2_out.txt', 'test2_ans.txt') == True\n", "\n open('test3.txt', 'w').write(' \\n \\n')\n candidate('test3.txt', 'test3_out.txt')\n open('test3_ans.txt', 'w').write('#test firstline\\n \\n \\n')\n assert filecmp.cmp('test3_out.txt', 'test3_ans.txt') == True\n", "\n open('test4.txt', 'w').write('hello')\n candidate('test4.txt', 'test4_out.txt')\n open('test4_ans.txt', 'w').write('hello')\n assert filecmp.cmp('test4_out.txt', 'test4_ans.txt') == False\n"], "entry_point": "f_4454298", "intent": "prepend the line '#test firstline\\n' to the contents of file 'infile' and save as the file 'outfile'", "library": ["filecmp"]} {"task_id": 19729928, "prompt": "def f_19729928(l):\n\t", "suffix": "\n\treturn l", "canonical_solution": "l.sort(key=lambda t: len(t[1]), reverse=True)", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate([(\"a\", [1]), (\"b\", [1,2]), (\"c\", [1,2,3])]) == [(\"c\", [1,2,3]), (\"b\", [1,2]), (\"a\", [1])]\n", "\n assert candidate([(\"a\", [1]), (\"b\", [2]), (\"c\", [1,2,3])]) == [(\"c\", [1,2,3]), (\"a\", [1]), (\"b\", [2])]\n", "\n assert candidate([(\"a\", [1]), (\"b\", [2]), (\"c\", [3])]) == [(\"a\", [1]), (\"b\", [2]), (\"c\", [3])]\n"], "entry_point": "f_19729928", "intent": "sort a list `l` by length of value in tuple", "library": []} {"task_id": 31371879, "prompt": "def f_31371879(s):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('\\\\b(\\\\w+)d\\\\b', s)", "test_start": "\nimport re\n\ndef check(candidate): ", "test": ["\n assert candidate(\"this is good\") == [\"goo\"]\n", "\n assert candidate(\"this is interesting\") == []\n", "\n assert candidate(\"good bad dd\") == [\"goo\", \"ba\", \"d\"]\n"], "entry_point": "f_31371879", "intent": "split string `s` by words that ends with 'd'", "library": ["re"]} {"task_id": 9012008, "prompt": "def f_9012008():\n\treturn ", "suffix": "", "canonical_solution": "bool(re.search('ba[rzd]', 'foobarrrr'))", "test_start": "\nimport re\n\ndef check(candidate): ", "test": ["\n assert candidate() == True\n"], "entry_point": "f_9012008", "intent": "return `True` if string `foobarrrr` contains regex `ba[rzd]`", "library": ["re"]} {"task_id": 7961363, "prompt": "def f_7961363(t):\n\treturn ", "suffix": "", "canonical_solution": "list(set(t))", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate([1,2,3]) == [1,2,3]\n", "\n assert candidate([1,1,1,1,1,1,1,1,1,1]) == [1] \n", "\n assert candidate([1,2,2,2,2,2,3,3,3,3,3]) == [1,2,3]\n", "\n assert (candidate([1, '1']) == [1, '1']) or (candidate([1, '1']) == ['1', 1])\n", "\n assert candidate([1.0, 1]) == [1.0] \n", "\n assert candidate([]) == [] \n", "\n assert candidate([None]) == [None] \n"], "entry_point": "f_7961363", "intent": "Removing duplicates in list `t`", "library": []} {"task_id": 7961363, "prompt": "def f_7961363(source_list):\n\treturn ", "suffix": "", "canonical_solution": "list(set(source_list))", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate([1,2,3]) == [1,2,3]\n", "\n assert candidate([1,1,1,1,1,1,1,1,1,1]) == [1] \n", "\n assert candidate([1,2,2,2,2,2,3,3,3,3,3]) == [1,2,3]\n", "\n assert (candidate([1, '1']) == [1, '1']) or (candidate([1, '1']) == ['1', 1])\n", "\n assert candidate([1.0, 1]) == [1.0] \n", "\n assert candidate([]) == [] \n", "\n assert candidate([None]) == [None] \n"], "entry_point": "f_7961363", "intent": "Removing duplicates in list `source_list`", "library": []} {"task_id": 7961363, "prompt": "def f_7961363():\n\treturn ", "suffix": "", "canonical_solution": "list(OrderedDict.fromkeys('abracadabra'))", "test_start": "\nfrom collections import OrderedDict\n\ndef check(candidate):", "test": ["\n assert candidate() == ['a', 'b', 'r', 'c', 'd']\n"], "entry_point": "f_7961363", "intent": "Removing duplicates in list `abracadabra`", "library": ["collections"]} {"task_id": 5183533, "prompt": "def f_5183533(a):\n\treturn ", "suffix": "", "canonical_solution": "numpy.array(a).reshape(-1).tolist()", "test_start": "\nimport numpy\n\ndef check(candidate):", "test": ["\n assert candidate([[1,2,3],[4,5,6]]) == [1,2,3,4,5,6]\n", "\n assert candidate(['a', 'aa', 'abc']) == ['a', 'aa', 'abc']\n"], "entry_point": "f_5183533", "intent": "Convert array `a` into a list", "library": ["numpy"]} {"task_id": 5183533, "prompt": "def f_5183533(a):\n\treturn ", "suffix": "", "canonical_solution": "numpy.array(a)[0].tolist()", "test_start": "\nimport numpy\n\ndef check(candidate):", "test": ["\n assert candidate([[1,2,3],[4,5,6]]) == [1,2,3]\n", "\n assert candidate(['a', 'aa', 'abc']) == 'a'\n"], "entry_point": "f_5183533", "intent": "Convert the first row of numpy matrix `a` to a list", "library": ["numpy"]} {"task_id": 5999747, "prompt": "def f_5999747(soup):\n\treturn ", "suffix": "", "canonical_solution": "soup.find(text='Address:').findNext('td').contents[0]", "test_start": "\nfrom bs4 import BeautifulSoup\n\ndef check(candidate):", "test": ["\n assert candidate(BeautifulSoup(\"Address:My home address\")) == \"My home address\"\n", "\n assert candidate(BeautifulSoup(\"Address:This is my home addressNot my home address\")) == \"This is my home address\"\n", "\n assert candidate(BeautifulSoup(\"Address:My home address
  • My home address in a list
  • \")) == \"My home address\"\n"], "entry_point": "f_5999747", "intent": "In `soup`, get the content of the sibling of the `td` tag with text content `Address:`", "library": ["bs4"]} {"task_id": 4284648, "prompt": "def f_4284648(l):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\" \"\"\".join([('%d@%d' % t) for t in l])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([(1, 2), (3, 4)]) == \"1@2 3@4\"\n", "\n assert candidate([(10, 11), (12, 13)]) == \"10@11 12@13\"\n", "\n assert candidate([(10.2, 11.4), (12.14, 13.13)]) == \"10@11 12@13\"\n"], "entry_point": "f_4284648", "intent": "convert elements of each tuple in list `l` into a string separated by character `@`", "library": []} {"task_id": 4284648, "prompt": "def f_4284648(l):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\" \"\"\".join([('%d@%d' % (t[0], t[1])) for t in l])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([(1, 2), (3, 4)]) == \"1@2 3@4\"\n", "\n assert candidate([(10, 11), (12, 13)]) == \"10@11 12@13\"\n", "\n assert candidate([(10.2, 11.4), (12.14, 13.13)]) == \"10@11 12@13\"\n"], "entry_point": "f_4284648", "intent": "convert each tuple in list `l` to a string with '@' separating the tuples' elements", "library": []} {"task_id": 29696641, "prompt": "def f_29696641(teststr):\n\treturn ", "suffix": "", "canonical_solution": "[i for i in teststr if re.search('\\\\d+[xX]', i)]", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(['1 FirstString', '2x Sec String', '3rd String', 'x forString', '5X fifth']) == ['2x Sec String', '5X fifth']\n", "\n assert candidate(['1x', '2', '3X', '4x random', '5X random']) == ['1x', '3X', '4x random', '5X random']\n", "\n assert candidate(['1x', '2', '3X', '4xrandom', '5Xrandom']) == ['1x', '3X', '4xrandom', '5Xrandom']\n"], "entry_point": "f_29696641", "intent": "Get all matches with regex pattern `\\\\d+[xX]` in list of string `teststr`", "library": ["re"]} {"task_id": 15315452, "prompt": "def f_15315452(df):\n\treturn ", "suffix": "", "canonical_solution": "df['A'][(df['B'] > 50) & (df['C'] == 900)]", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame({'A': [7, 7, 4, 4, 7, 7, 3, 9, 6, 3], 'B': [20, 80, 90, 30, 80, 60, 80, 40, 40 ,10], 'C': [300, 700, 100, 900, 200, 800, 900, 100, 100, 600]})\n assert candidate(df).to_dict() == {6: 3}\n", "\n df1 = pd.DataFrame({'A': [9, 9, 5, 8, 7, 9, 2, 2, 5, 7], 'B': [40, 70, 70, 80, 50, 30, 80, 80, 80, 70], 'C': [300, 700, 900, 900, 200, 900, 700, 400, 300, 800]})\n assert candidate(df1).to_dict() == {2: 5, 3: 8}\n", "\n df2 = pd.DataFrame({'A': [3, 4, 5, 6], 'B': [-10, 50, 20, 10], 'C': [900, 800, 900, 900]})\n assert candidate(df2).to_dict() == {}\n"], "entry_point": "f_15315452", "intent": "select values from column 'A' for which corresponding values in column 'B' will be greater than 50, and in column 'C' - equal 900 in dataframe `df`", "library": ["pandas"]} {"task_id": 4642501, "prompt": "def f_4642501(o):\n\treturn ", "suffix": "", "canonical_solution": "sorted(o.items())", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n assert candidate({1:\"abc\", 5:\"klm\", 2:\"pqr\"}) == [(1, \"abc\"), (2, \"pqr\"), (5, \"klm\")]\n", "\n assert candidate({4.221:\"uwv\", -1.009:\"pow\"}) == [(-1.009, 'pow'), (4.221, 'uwv')]\n", "\n assert candidate({\"as2q\":\"piqr\", \"#wwq\":\"say\", \"Rwc\":\"koala\", \"35\":\"kangaroo\"}) == [('#wwq', 'say'), ('35', 'kangaroo'), ('Rwc', 'koala'), ('as2q', 'piqr')]\n"], "entry_point": "f_4642501", "intent": "Sort dictionary `o` in ascending order based on its keys and items", "library": ["pandas"]} {"task_id": 4642501, "prompt": "def f_4642501(d):\n\treturn ", "suffix": "", "canonical_solution": "sorted(d)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({1:\"abc\", 5:\"klm\", 2:\"pqr\"}) == [1, 2, 5]\n", "\n assert candidate({4.221:\"uwv\", -1.009:\"pow\"}) == [-1.009, 4.221]\n", "\n assert candidate({\"as2q\":\"piqr\", \"#wwq\":\"say\", \"Rwc\":\"koala\", \"35\":\"kangaroo\"}) == ['#wwq', '35', 'Rwc', 'as2q']\n"], "entry_point": "f_4642501", "intent": "get sorted list of keys of dict `d`", "library": []} {"task_id": 4642501, "prompt": "def f_4642501(d):\n\treturn ", "suffix": "", "canonical_solution": "sorted(d.items())", "test_start": "\ndef check(candidate):", "test": ["\n d = {'a': [1, 2, 3], 'c': ['one', 'two'], 'b': ['blah', 'bhasdf', 'asdf'], 'd': ['asdf', 'wer', 'asdf', 'zxcv']}\n assert candidate(d) == [('a', [1, 2, 3]), ('b', ['blah', 'bhasdf', 'asdf']), ('c', ['one', 'two']), ('d', ['asdf', 'wer', 'asdf', 'zxcv'])]\n"], "entry_point": "f_4642501", "intent": "sort dictionaries `d` by keys", "library": []} {"task_id": 642154, "prompt": "def f_642154():\n\treturn ", "suffix": "", "canonical_solution": "int('1')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 1\n", "\n assert candidate() + 1 == 2\n"], "entry_point": "f_642154", "intent": "convert string \"1\" into integer", "library": []} {"task_id": 642154, "prompt": "def f_642154(T1):\n\treturn ", "suffix": "", "canonical_solution": "[list(map(int, x)) for x in T1]", "test_start": "\ndef check(candidate):", "test": ["\n T1 = (('13', '17', '18', '21', '32'), ('07', '11', '13', '14', '28'), ('01', '05', '06', '08', '15', '16'))\n assert candidate(T1) == [[13, 17, 18, 21, 32], [7, 11, 13, 14, 28], [1, 5, 6, 8, 15, 16]]\n"], "entry_point": "f_642154", "intent": "convert items in `T1` to integers", "library": []} {"task_id": 3777301, "prompt": "def f_3777301():\n\t", "suffix": "\n\treturn ", "canonical_solution": "subprocess.call(['./test.sh'])", "test_start": "\nimport subprocess\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n subprocess.call = Mock()\n try:\n candidate()\n except:\n assert False\n"], "entry_point": "f_3777301", "intent": "call a shell script `./test.sh` using subprocess", "library": ["subprocess"]} {"task_id": 3777301, "prompt": "def f_3777301():\n\t", "suffix": "\n\treturn ", "canonical_solution": "subprocess.call(['notepad'])", "test_start": "\nimport subprocess\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n subprocess.call = Mock()\n try:\n candidate()\n except:\n assert False\n"], "entry_point": "f_3777301", "intent": "call a shell script `notepad` using subprocess", "library": ["subprocess"]} {"task_id": 7946798, "prompt": "def f_7946798(l1, l2):\n\treturn ", "suffix": "", "canonical_solution": "[val for pair in zip(l1, l2) for val in pair]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3], [10,20,30]) == [1,10,2,20,3,30]\n", "\n assert candidate([1,2,3], ['c','b','a']) == [1,'c',2,'b',3,'a']\n", "\n assert candidate([1,2,3], ['c','b']) == [1,'c',2,'b']\n"], "entry_point": "f_7946798", "intent": "combine lists `l1` and `l2` by alternating their elements", "library": []} {"task_id": 8908287, "prompt": "def f_8908287():\n\treturn ", "suffix": "", "canonical_solution": "base64.b64encode(b'data to be encoded')", "test_start": "\nimport base64\n\ndef check(candidate):", "test": ["\n assert candidate() == b'ZGF0YSB0byBiZSBlbmNvZGVk'\n"], "entry_point": "f_8908287", "intent": "encode string 'data to be encoded'", "library": ["base64"]} {"task_id": 8908287, "prompt": "def f_8908287():\n\treturn ", "suffix": "", "canonical_solution": "'data to be encoded'.encode('ascii')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == b'data to be encoded'\n"], "entry_point": "f_8908287", "intent": "encode a string `data to be encoded` to `ascii` encoding", "library": []} {"task_id": 7856296, "prompt": "def f_7856296():\n\treturn ", "suffix": "", "canonical_solution": "list(csv.reader(open('text.txt', 'r'), delimiter='\\t'))", "test_start": "\nimport csv \n\ndef check(candidate):", "test": ["\n with open('text.txt', 'w', newline='') as csvfile:\n spamwriter = csv.writer(csvfile, delimiter='\t')\n spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])\n spamwriter.writerow(['hello', 'world', '!'])\n\n assert candidate() == [['Spam', 'Lovely Spam', 'Wonderful Spam'], ['hello', 'world', '!']]\n"], "entry_point": "f_7856296", "intent": "parse tab-delimited CSV file 'text.txt' into a list", "library": ["csv"]} {"task_id": 9035479, "prompt": "def f_9035479(my_object, my_str):\n\treturn ", "suffix": "", "canonical_solution": "getattr(my_object, my_str)", "test_start": "\ndef check(candidate):", "test": ["\n class Student:\n id = 9\n name = \"abc\"\n grade = 97.08\n\n s = Student()\n \n assert candidate(s, \"name\") == \"abc\"\n", "\n class Student:\n id = 9\n name = \"abc\"\n grade = 97.08\n\n s = Student()\n \n assert (candidate(s, \"grade\") - 97.08) < 1e-6\n", "\n class Student:\n id = 9\n name = \"abc\"\n grade = 97.08\n\n s = Student()\n \n assert (candidate(s, \"grade\") - 97.07) > 1e-6\n", "\n class Student:\n id = 9\n name = \"abc\"\n grade = 97.08\n\n s = Student()\n \n assert candidate(s, \"id\") == 9\n"], "entry_point": "f_9035479", "intent": "Get attribute `my_str` of object `my_object`", "library": []} {"task_id": 5558418, "prompt": "def f_5558418(LD):\n\treturn ", "suffix": "", "canonical_solution": "dict(zip(LD[0], zip(*[list(d.values()) for d in LD])))", "test_start": "\nimport collections\n\ndef check(candidate):", "test": ["\n employees = [{'name' : 'apple', 'id': 60}, {'name' : 'orange', 'id': 65}]\n exp_result = {'name': ('apple', 'orange'), 'id': (60, 65)}\n actual_result = candidate(employees)\n for key in actual_result:\n assert collections.Counter(list(exp_result[key])) == collections.Counter(list(actual_result[key]))\n"], "entry_point": "f_5558418", "intent": "group a list of dicts `LD` into one dict by key", "library": ["collections"]} {"task_id": 638048, "prompt": "def f_638048(list_of_pairs):\n\treturn ", "suffix": "", "canonical_solution": "sum([pair[0] for pair in list_of_pairs])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([(5, 9), (-1, -2), (4, 2)]) == 8\n"], "entry_point": "f_638048", "intent": "sum the first value in each tuple in a list of tuples `list_of_pairs` in python", "library": []} {"task_id": 14950260, "prompt": "def f_14950260():\n\treturn ", "suffix": "", "canonical_solution": "ast.literal_eval(\"{'code1':1,'code2':1}\")", "test_start": "\nimport ast\n\ndef check(candidate):", "test": ["\n d = candidate()\n exp_result = {'code1' : 1, 'code2': 1}\n for key in d:\n if key not in exp_result:\n assert False\n else:\n assert d[key] == exp_result[key]\n"], "entry_point": "f_14950260", "intent": "convert unicode string u\"{'code1':1,'code2':1}\" into dictionary", "library": ["ast"]} {"task_id": 11416772, "prompt": "def f_11416772(mystring):\n\treturn ", "suffix": "", "canonical_solution": "[word for word in mystring.split() if word.startswith('$')]", "test_start": "\ndef check(candidate):", "test": ["\n str = \"$abc def $efg $hij klm $\"\n exp_result = ['$abc', '$efg', '$hij', '$']\n assert sorted(candidate(str)) == sorted(exp_result)\n"], "entry_point": "f_11416772", "intent": "find all words in a string `mystring` that start with the `$` sign", "library": []} {"task_id": 11331982, "prompt": "def f_11331982(text):\n\t", "suffix": "\n\treturn text", "canonical_solution": "text = re.sub('^https?:\\\\/\\\\/.*[\\\\r\\\\n]*', '', text, flags=re.MULTILINE)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(\"https://www.wikipedia.org/ click at\") == \"\"\n"], "entry_point": "f_11331982", "intent": "remove any url within string `text`", "library": ["re"]} {"task_id": 34945274, "prompt": "def f_34945274(A):\n\treturn ", "suffix": "", "canonical_solution": "np.where(np.in1d(A, [1, 3, 4]).reshape(A.shape), A, 0)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n A = np.array([[6, 8, 1, 3, 4], [-1, 0, 3, 5, 1]])\n B = np.array([[0, 0, 1, 3, 4], [0, 0, 3, 0, 1]])\n assert np.array_equal(candidate(A), B)\n"], "entry_point": "f_34945274", "intent": "replace all elements in array `A` that are not present in array `[1, 3, 4]` with zeros", "library": ["numpy"]} {"task_id": 15819980, "prompt": "def f_15819980(a):\n\treturn ", "suffix": "", "canonical_solution": "np.mean(a, axis=1)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n A = np.array([[6, 8, 1, 3, 4], [-1, 0, 3, 5, 1]])\n B = np.array([4.4, 1.6])\n assert np.array_equal(candidate(A), B)\n"], "entry_point": "f_15819980", "intent": "calculate mean across dimension in a 2d array `a`", "library": ["numpy"]} {"task_id": 19894365, "prompt": "def f_19894365():\n\treturn ", "suffix": "", "canonical_solution": "subprocess.call(['/usr/bin/Rscript', '--vanilla', '/pathto/MyrScript.r'])", "test_start": "\nfrom unittest.mock import Mock\nimport subprocess\n\ndef check(candidate):", "test": ["\n subprocess.call = Mock(return_value = 0)\n assert candidate() == 0\n"], "entry_point": "f_19894365", "intent": "running r script '/pathto/MyrScript.r' from python", "library": ["subprocess"]} {"task_id": 19894365, "prompt": "def f_19894365():\n\treturn ", "suffix": "", "canonical_solution": "subprocess.call('/usr/bin/Rscript --vanilla /pathto/MyrScript.r', shell=True)", "test_start": "\nfrom unittest.mock import Mock\nimport subprocess\n\ndef check(candidate):", "test": ["\n subprocess.call = Mock(return_value = 0)\n assert candidate() == 0\n"], "entry_point": "f_19894365", "intent": "run r script '/usr/bin/Rscript --vanilla /pathto/MyrScript.r'", "library": ["subprocess"]} {"task_id": 33058590, "prompt": "def f_33058590(df):\n\treturn ", "suffix": "", "canonical_solution": "df.fillna(df.mean(axis=0))", "test_start": "\nimport pandas as pd\nimport numpy as np\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[1,2,3],[4,5,6],[7.0,np.nan,9.0]], columns=[\"c1\",\"c2\",\"c3\"]) \n res = pd.DataFrame([[1,2,3],[4,5,6],[7.0,3.5,9.0]], columns=[\"c1\",\"c2\",\"c3\"])\n assert candidate(df).equals(res)\n"], "entry_point": "f_33058590", "intent": "replacing nan in the dataframe `df` with row average", "library": ["numpy", "pandas"]} {"task_id": 12400256, "prompt": "def f_12400256():\n\treturn ", "suffix": "", "canonical_solution": "time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1347517370))", "test_start": "\nimport time\n\ndef check(candidate):", "test": ["\n assert candidate() == \"2012-09-13 06:22:50\"\n"], "entry_point": "f_12400256", "intent": "Convert unix timestamp '1347517370' to formatted string '%Y-%m-%d %H:%M:%S'", "library": ["time"]} {"task_id": 23359886, "prompt": "def f_23359886(a):\n\treturn ", "suffix": "", "canonical_solution": "a[np.where((a[:, (0)] == 0) * (a[:, (1)] == 1))]", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a = np.array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11], [12, 13, 14]])\n res = np.array([[0, 1, 2]])\n assert np.array_equal(candidate(a), res)\n"], "entry_point": "f_23359886", "intent": "selecting rows in Numpy ndarray 'a', where the value in the first column is 0 and value in the second column is 1", "library": ["numpy"]} {"task_id": 4383082, "prompt": "def f_4383082(words):\n\treturn ", "suffix": "", "canonical_solution": "re.split(' +', words)", "test_start": "\nimport regex as re\n\ndef check(candidate):", "test": ["\n s = \"hello world sample text\"\n res = [\"hello\", \"world\", \"sample\", \"text\"]\n assert candidate(s) == res\n"], "entry_point": "f_4383082", "intent": "separate words delimited by one or more spaces into a list", "library": ["regex"]} {"task_id": 14637696, "prompt": "def f_14637696(words):\n\treturn ", "suffix": "", "canonical_solution": "len(max(words, key=len))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([\"hello\", \"world\", \"sample\", \"text\", \"superballer\"]) == 11\n"], "entry_point": "f_14637696", "intent": "length of longest element in list `words`", "library": []} {"task_id": 3933478, "prompt": "def f_3933478(result):\n\treturn ", "suffix": "", "canonical_solution": "result[0]['from_user']", "test_start": "\ndef check(candidate):", "test": ["\n Contents = [{\"hi\": 7, \"bye\": 4, \"from_user\": 0}, {1: 2, 3: 4, 5: 6}]\n assert candidate(Contents) == 0\n"], "entry_point": "f_3933478", "intent": "get the value associated with unicode key 'from_user' of first dictionary in list `result`", "library": []} {"task_id": 39112645, "prompt": "def f_39112645():\n\treturn ", "suffix": "", "canonical_solution": "[line.split() for line in open('File.txt')]", "test_start": "\ndef check(candidate):", "test": ["\n with open('File.txt','w') as fw:\n fw.write(\"hi hello cat dog\")\n assert candidate() == [['hi', 'hello', 'cat', 'dog']]\n"], "entry_point": "f_39112645", "intent": "Retrieve each line from a file 'File.txt' as a list", "library": []} {"task_id": 1031851, "prompt": "def f_1031851(a):\n\treturn ", "suffix": "", "canonical_solution": "dict((v, k) for k, v in a.items())", "test_start": "\ndef check(candidate):", "test": ["\n a = {\"one\": 1, \"two\": 2}\n assert candidate(a) == {1: \"one\", 2: \"two\"}\n"], "entry_point": "f_1031851", "intent": "swap keys with values in a dictionary `a`", "library": []} {"task_id": 8577137, "prompt": "def f_8577137():\n\treturn ", "suffix": "", "canonical_solution": "open('path/to/FILE_NAME.ext', 'w')", "test_start": "\nimport os\n\ndef check(candidate):", "test": ["\n path1 = os.path.join(\"\", \"path\")\n os.mkdir(path1)\n path2 = os.path.join(\"path\", \"to\")\n os.mkdir(path2)\n candidate()\n assert os.path.exists('path/to/FILE_NAME.ext')\n"], "entry_point": "f_8577137", "intent": "Open a file `path/to/FILE_NAME.ext` in write mode", "library": ["os"]} {"task_id": 17926273, "prompt": "def f_17926273(df):\n\treturn ", "suffix": "", "canonical_solution": "df.groupby(['col1', 'col2'])['col3'].nunique().reset_index()", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n data = [[1, 1, 1], [1, 1, 1], [1, 1, 2], [1, 2, 3], [1, 2, 3], [1, 2, 3], \n [2, 1, 1], [2, 1, 2], [2, 1, 3], [2, 2, 3], [2, 2, 3], [2, 2, 3]]\n expected = [[1, 1, 2], [1, 2, 1], [2, 1, 3], [2, 2, 1]]\n df = pd.DataFrame(data, columns = ['col1', 'col2', 'col3'])\n expected_df = pd.DataFrame(expected, columns = ['col1', 'col2', 'col3'])\n df1 = candidate(df)\n assert pd.DataFrame.equals(expected_df, df1)\n"], "entry_point": "f_17926273", "intent": "count distinct values in a column 'col3' of a pandas dataframe `df` group by objects in 'col1' and 'col2'", "library": ["pandas"]} {"task_id": 3735814, "prompt": "def f_3735814(dict1):\n\treturn ", "suffix": "", "canonical_solution": "any(key.startswith('EMP$$') for key in dict1)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'EMP$$': 1, 'EMP$$112': 4}) == True\n", "\n assert candidate({'EMP$$': 1, 'EM$$112': 4}) == True\n", "\n assert candidate({'EMP$33': 0}) == False\n"], "entry_point": "f_3735814", "intent": "Check if any key in the dictionary `dict1` starts with the string `EMP$$`", "library": []} {"task_id": 3735814, "prompt": "def f_3735814(dict1):\n\treturn ", "suffix": "", "canonical_solution": "[value for key, value in list(dict1.items()) if key.startswith('EMP$$')]", "test_start": "\ndef check(candidate):", "test": ["\n assert sorted(candidate({'EMP$$': 1, 'EMP$$112': 4})) == [1, 4]\n", "\n assert sorted(candidate({'EMP$$': 1, 'EM$$112': 4})) == [1]\n", "\n assert sorted(candidate({'EMP$33': 0})) == []\n"], "entry_point": "f_3735814", "intent": "create list of values from dictionary `dict1` that have a key that starts with 'EMP$$'", "library": []} {"task_id": 26097916, "prompt": "def f_26097916(sf):\n\t", "suffix": "\n\treturn df", "canonical_solution": "df = pd.DataFrame({'email': sf.index, 'list': sf.values})", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n dict = {'email1': [1.0, 5.0, 7.0], 'email2': [4.2, 3.6, -0.9]}\n sf = pd.Series(dict)\n k = [['email1', [1.0, 5.0, 7.0]], ['email2', [4.2, 3.6, -0.9]]]\n df1 = pd.DataFrame(k, columns=['email', 'list'])\n df2 = candidate(sf)\n assert pd.DataFrame.equals(df1, df2)\n"], "entry_point": "f_26097916", "intent": "convert a pandas series `sf` into a pandas dataframe `df` with columns `email` and `list`", "library": ["pandas"]} {"task_id": 4048964, "prompt": "def f_4048964(list):\n\treturn ", "suffix": "", "canonical_solution": "'\\t'.join(map(str, list))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['hello', 'world', '!']) == 'hello\\tworld\\t!'\n", "\n assert candidate([]) == \"\"\n", "\n assert candidate([\"mconala\"]) == \"mconala\"\n", "\n assert candidate([\"MCoNaLa\"]) == \"MCoNaLa\"\n"], "entry_point": "f_4048964", "intent": "concatenate elements of list `list` by tabs `\t`", "library": []} {"task_id": 3182716, "prompt": "def f_3182716():\n\treturn ", "suffix": "", "canonical_solution": "'\\xd0\\xbf\\xd1\\x80\\xd0\\xb8'.encode('raw_unicode_escape')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == b'\\xd0\\xbf\\xd1\\x80\\xd0\\xb8'\n"], "entry_point": "f_3182716", "intent": "print unicode string '\\xd0\\xbf\\xd1\\x80\\xd0\\xb8' with utf-8", "library": []} {"task_id": 3182716, "prompt": "def f_3182716():\n\treturn ", "suffix": "", "canonical_solution": "'Sopet\\xc3\\xb3n'.encode('latin-1').decode('utf-8')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == \"Sopet\u00f3n\"\n"], "entry_point": "f_3182716", "intent": "Encode a latin character in string `Sopet\\xc3\\xb3n` properly", "library": []} {"task_id": 35622945, "prompt": "def f_35622945(s):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('n(?<=[^n]n)n+(?=[^n])(?i)', s)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate(\"ncnnnne\") == ['nnnn']\n", "\n assert candidate(\"nn\") == []\n", "\n assert candidate(\"ask\") == []\n"], "entry_point": "f_35622945", "intent": "regex, find \"n\"s only in the middle of string `s`", "library": ["re"]} {"task_id": 5306756, "prompt": "def f_5306756():\n\treturn ", "suffix": "", "canonical_solution": "'{0:.0f}%'.format(1.0 / 3 * 100)", "test_start": "\ndef check(candidate):", "test": ["\n assert(candidate() == \"33%\")\n"], "entry_point": "f_5306756", "intent": "display the float `1/3*100` as a percentage", "library": []} {"task_id": 2878084, "prompt": "def f_2878084(mylist):\n\t", "suffix": "\n\treturn mylist", "canonical_solution": "mylist.sort(key=lambda x: x['title'])", "test_start": "\ndef check(candidate):", "test": ["\n input = [\n {'title':'New York Times', 'title_url':'New_York_Times','id':4}, \n {'title':'USA Today','title_url':'USA_Today','id':6}, \n {'title':'Apple News','title_url':'Apple_News','id':2}\n ]\n res = [\n {'title': 'Apple News', 'title_url': 'Apple_News', 'id': 2}, \n {'title': 'New York Times', 'title_url': 'New_York_Times', 'id': 4},\n {'title': 'USA Today', 'title_url': 'USA_Today', 'id': 6}\n ]\n assert candidate(input) == res\n"], "entry_point": "f_2878084", "intent": "sort a list of dictionary `mylist` by the key `title`", "library": []} {"task_id": 2878084, "prompt": "def f_2878084(l):\n\t", "suffix": "\n\treturn l", "canonical_solution": "l.sort(key=lambda x: x['title'])", "test_start": "\ndef check(candidate):", "test": ["\n input = [\n {'title':'New York Times', 'title_url':'New_York_Times','id':4}, \n {'title':'USA Today','title_url':'USA_Today','id':6}, \n {'title':'Apple News','title_url':'Apple_News','id':2}\n ]\n res = [\n {'title': 'Apple News', 'title_url': 'Apple_News', 'id': 2}, \n {'title': 'New York Times', 'title_url': 'New_York_Times', 'id': 4},\n {'title': 'USA Today', 'title_url': 'USA_Today', 'id': 6}\n ]\n assert candidate(input) == res\n"], "entry_point": "f_2878084", "intent": "sort a list `l` of dicts by dict value 'title'", "library": []} {"task_id": 2878084, "prompt": "def f_2878084(l):\n\t", "suffix": "\n\treturn l", "canonical_solution": "l.sort(key=lambda x: (x['title'], x['title_url'], x['id']))", "test_start": "\ndef check(candidate):", "test": ["\n input = [\n {'title':'New York Times', 'title_url':'New_York_Times','id':4}, \n {'title':'USA Today','title_url':'USA_Today','id':6}, \n {'title':'Apple News','title_url':'Apple_News','id':2}\n ]\n res = [\n {'title': 'Apple News', 'title_url': 'Apple_News', 'id': 2}, \n {'title': 'New York Times', 'title_url': 'New_York_Times', 'id': 4},\n {'title': 'USA Today', 'title_url': 'USA_Today', 'id': 6}\n ]\n assert candidate(input) == res\n"], "entry_point": "f_2878084", "intent": "sort a list of dictionaries by the value of keys 'title', 'title_url', 'id' in ascending order.", "library": []} {"task_id": 9323159, "prompt": "def f_9323159(l1, l2):\n\treturn ", "suffix": "", "canonical_solution": "heapq.nlargest(10, range(len(l1)), key=lambda i: abs(l1[i] - l2[i]))", "test_start": "\nimport heapq\n\ndef check(candidate):", "test": ["\n l1 = [99, 86, 90, 70, 86, 95, 56, 98, 80, 81]\n l2 = [21, 11, 21, 1, 26, 40, 4, 50, 34, 37]\n res = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(l1, l2) == res\n"], "entry_point": "f_9323159", "intent": "find 10 largest differences between each respective elements of list `l1` and list `l2`", "library": ["heapq"]} {"task_id": 29877663, "prompt": "def f_29877663(soup):\n\treturn ", "suffix": "", "canonical_solution": "soup.find_all('span', {'class': 'starGryB sp'})", "test_start": "\nimport bs4\n\ndef check(candidate):", "test": ["\n html = '''4.1\n 2.9\n 2.9\n 22'''\n soup = bs4.BeautifulSoup(html, features=\"html5lib\")\n res = '''[2.9]'''\n assert(str(candidate(soup)) == res)\n"], "entry_point": "f_29877663", "intent": "BeautifulSoup find all 'span' elements in HTML string `soup` with class of 'starGryB sp'", "library": ["bs4"]} {"task_id": 24189150, "prompt": "def f_24189150(df, engine):\n\t", "suffix": "\n\treturn ", "canonical_solution": "df.to_sql('test', engine)", "test_start": "\nimport pandas as pd\nfrom sqlalchemy import create_engine\n\ndef check(candidate):", "test": ["\n engine = create_engine('sqlite://', echo=False)\n df = pd.DataFrame({'name' : ['User 1', 'User 2', 'User 3']})\n candidate(df, engine)\n result = pd.read_sql('SELECT name FROM test', engine)\n assert result.equals(df)\n"], "entry_point": "f_24189150", "intent": "write records in dataframe `df` to table 'test' in schema 'a_schema' with `engine`", "library": ["pandas", "sqlalchemy"]} {"task_id": 30766151, "prompt": "def f_30766151(s):\n\treturn ", "suffix": "", "canonical_solution": "re.sub('[^(){}[\\]]', '', s)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(\"(a(vdwvndw){}]\") == \"((){}]\"\n", "\n assert candidate(\"12345\") == \"\"\n"], "entry_point": "f_30766151", "intent": "Extract brackets from string `s`", "library": ["re"]} {"task_id": 1143379, "prompt": "def f_1143379(L):\n\treturn ", "suffix": "", "canonical_solution": "list(dict((x[0], x) for x in L).values())", "test_start": "\ndef check(candidate):", "test": ["\n L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]\n res = [['14', '22', 46], ['2', '5', 6], ['7', '12', 33]]\n assert(candidate(L) == res)\n", "\n assert candidate([\"a\", \"aa\", \"abc\", \"bac\"]) == [\"abc\", \"bac\"]\n"], "entry_point": "f_1143379", "intent": "remove duplicate elements from list 'L'", "library": []} {"task_id": 12330522, "prompt": "def f_12330522(file):\n\treturn ", "suffix": "", "canonical_solution": "[line.rstrip('\\n') for line in file]", "test_start": "\ndef check(candidate):", "test": ["\n res = ['1', '2', '3']\n f = open(\"myfile.txt\", \"a\")\n f.write(\"1\\n2\\n3\")\n f.close()\n f = open(\"myfile.txt\", \"r\")\n assert candidate(f) == res\n"], "entry_point": "f_12330522", "intent": "read a file `file` without newlines", "library": []} {"task_id": 364621, "prompt": "def f_364621(testlist):\n\treturn ", "suffix": "", "canonical_solution": "[i for (i, x) in enumerate(testlist) if (x == 1)]", "test_start": "\ndef check(candidate):", "test": ["\n testlist = [1,2,3,5,3,1,2,1,6]\n assert candidate(testlist) == [0, 5, 7]\n", "\n testlist = [0, -1]\n assert candidate(testlist) == []\n"], "entry_point": "f_364621", "intent": "get the position of item 1 in `testlist`", "library": []} {"task_id": 364621, "prompt": "def f_364621(testlist):\n\treturn ", "suffix": "", "canonical_solution": "[i for (i, x) in enumerate(testlist) if (x == 1)]", "test_start": "\ndef check(candidate):", "test": ["\n testlist = [1,2,3,5,3,1,2,1,6]\n assert candidate(testlist) == [0, 5, 7]\n", "\n testlist = [0, -1]\n assert candidate(testlist) == []\n"], "entry_point": "f_364621", "intent": "get the position of item 1 in `testlist`", "library": []} {"task_id": 364621, "prompt": "def f_364621(testlist, element):\n\treturn ", "suffix": "", "canonical_solution": "testlist.index(element)", "test_start": "\ndef check(candidate):", "test": ["\n testlist = [1,2,3,5,3,1,2,1,6]\n assert candidate(testlist, 1) == 0\n", "\n testlist = [1,2,3,5,3,1,2,1,6]\n try:\n candidate(testlist, 14)\n except:\n assert True\n"], "entry_point": "f_364621", "intent": "get the position of item `element` in list `testlist`", "library": []} {"task_id": 13145368, "prompt": "def f_13145368(lis):\n\treturn ", "suffix": "", "canonical_solution": "max(lis, key=lambda item: item[1])[0]", "test_start": "\ndef check(candidate):", "test": ["\n lis = [(101, 153), (255, 827), (361, 961)]\n assert candidate(lis) == 361\n"], "entry_point": "f_13145368", "intent": "find the first element of the tuple with the maximum second element in a list of tuples `lis`", "library": []} {"task_id": 13145368, "prompt": "def f_13145368(lis):\n\treturn ", "suffix": "", "canonical_solution": "max(lis, key=itemgetter(1))[0]", "test_start": "\nfrom operator import itemgetter \n\ndef check(candidate):", "test": ["\n lis = [(101, 153), (255, 827), (361, 961)]\n assert candidate(lis) == 361\n"], "entry_point": "f_13145368", "intent": "get the item at index 0 from the tuple that has maximum value at index 1 in list `lis`", "library": ["operator"]} {"task_id": 2689189, "prompt": "def f_2689189():\n\t", "suffix": "\n\treturn ", "canonical_solution": "time.sleep(1)", "test_start": "\nimport time\n\ndef check(candidate):", "test": ["\n t1 = time.time()\n candidate()\n t2 = time.time()\n assert t2 - t1 > 1\n"], "entry_point": "f_2689189", "intent": "Make a delay of 1 second", "library": ["time"]} {"task_id": 12485244, "prompt": "def f_12485244(L):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\", \"\"\".join('(' + ', '.join(i) + ')' for i in L)", "test_start": "\ndef check(candidate):", "test": ["\n L = [(\"abc\", \"def\"), (\"hij\", \"klm\")]\n assert candidate(L) == '(abc, def), (hij, klm)'\n"], "entry_point": "f_12485244", "intent": "convert list of tuples `L` to a string", "library": []} {"task_id": 755857, "prompt": "def f_755857():\n\t", "suffix": "\n\treturn b", "canonical_solution": "b = models.CharField(max_length=7, default='0000000', editable=False)", "test_start": "\nfrom django.db import models\n\ndef check(candidate):", "test": ["\n assert candidate().get_default() == '0000000'\n"], "entry_point": "f_755857", "intent": "Django set default value of field `b` equal to '0000000'", "library": ["django"]} {"task_id": 16193578, "prompt": "def f_16193578(list5):\n\treturn ", "suffix": "", "canonical_solution": "sorted(list5, key = lambda x: (degrees(x), x))", "test_start": "\nfrom math import degrees\n\ndef check(candidate):", "test": ["\n list5 = [4, 1, 2, 3, 9, 5]\n assert candidate(list5) == [1, 2, 3, 4, 5, 9]\n"], "entry_point": "f_16193578", "intent": "Sort lis `list5` in ascending order based on the degrees value of its elements", "library": ["math"]} {"task_id": 16041405, "prompt": "def f_16041405(l):\n\treturn ", "suffix": "", "canonical_solution": "(n for n in l)", "test_start": "\ndef check(candidate):", "test": ["\n generator = candidate([1,2,3,5])\n assert str(type(generator)) == \"\"\n assert [x for x in generator] == [1, 2, 3, 5]\n"], "entry_point": "f_16041405", "intent": "convert a list `l` into a generator object", "library": []} {"task_id": 18837607, "prompt": "def f_18837607(oldlist, removelist):\n\treturn ", "suffix": "", "canonical_solution": "[v for i, v in enumerate(oldlist) if i not in removelist]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([\"asdf\",\"ghjk\",\"qwer\",\"tyui\"], [1,3]) == ['asdf', 'qwer']\n", "\n assert candidate([1,2,3,4,5], [0,4]) == [2,3,4]\n"], "entry_point": "f_18837607", "intent": "remove elements from list `oldlist` that have an index number mentioned in list `removelist`", "library": []} {"task_id": 4710067, "prompt": "def f_4710067():\n\treturn ", "suffix": "", "canonical_solution": "open('yourfile.txt', 'w')", "test_start": "\ndef check(candidate):", "test": ["\n fw = candidate()\n assert fw.name == \"yourfile.txt\"\n assert fw.mode == 'w'\n"], "entry_point": "f_4710067", "intent": "Open a file `yourfile.txt` in write mode", "library": []} {"task_id": 7373219, "prompt": "def f_7373219(obj, attr):\n\treturn ", "suffix": "", "canonical_solution": "getattr(obj, attr)", "test_start": "\ndef check(candidate):", "test": ["\n class Student:\n student_id = \"\"\n student_name = \"\"\n\n def __init__(self, student_id=101, student_name=\"Adam\"):\n self.student_id = student_id\n self.student_name = student_name\n\n student = Student()\n\n assert(candidate(student, 'student_name') == \"Adam\")\n assert(candidate(student, 'student_id') == 101)\n", "\n class Student:\n student_id = \"\"\n student_name = \"\"\n\n def __init__(self, student_id=101, student_name=\"Adam\"):\n self.student_id = student_id\n self.student_name = student_name\n\n student = Student()\n\n try:\n value = candidate(student, 'student_none')\n except: \n assert True\n"], "entry_point": "f_7373219", "intent": "get attribute 'attr' from object `obj`", "library": []} {"task_id": 8171751, "prompt": "def f_8171751():\n\treturn ", "suffix": "", "canonical_solution": "reduce(lambda a, b: a + b, (('aa',), ('bb',), ('cc',)))", "test_start": "\nfrom functools import reduce\n\ndef check(candidate):", "test": ["\n assert candidate() == ('aa', 'bb', 'cc')\n"], "entry_point": "f_8171751", "intent": "convert tuple of tuples `(('aa',), ('bb',), ('cc',))` to tuple", "library": ["functools"]} {"task_id": 8171751, "prompt": "def f_8171751():\n\treturn ", "suffix": "", "canonical_solution": "list(map(lambda a: a[0], (('aa',), ('bb',), ('cc',))))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == ['aa', 'bb', 'cc']\n"], "entry_point": "f_8171751", "intent": "convert tuple of tuples `(('aa',), ('bb',), ('cc',))` to list in one line", "library": []} {"task_id": 28986489, "prompt": "def f_28986489(df):\n\t", "suffix": "\n\treturn df", "canonical_solution": "df['range'].replace(',', '-', inplace=True)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame({'range' : [\",\", \"(50,290)\", \",,,\"]})\n res = pd.DataFrame({'range' : [\"-\", \"(50,290)\", \",,,\"]})\n assert candidate(df).equals(res)\n"], "entry_point": "f_28986489", "intent": "replace a characters in a column of a dataframe `df`", "library": ["pandas"]} {"task_id": 19339, "prompt": "def f_19339():\n\treturn ", "suffix": "", "canonical_solution": "zip(*[('a', 1), ('b', 2), ('c', 3), ('d', 4)])", "test_start": "\ndef check(candidate):", "test": ["\n assert [a for a in candidate()] == [('a', 'b', 'c', 'd'), (1, 2, 3, 4)]\n"], "entry_point": "f_19339", "intent": "unzip the list `[('a', 1), ('b', 2), ('c', 3), ('d', 4)]`", "library": []} {"task_id": 19339, "prompt": "def f_19339(original):\n\treturn ", "suffix": "", "canonical_solution": "([a for (a, b) in original], [b for (a, b) in original])", "test_start": "\ndef check(candidate):", "test": ["\n original = [('a', 1), ('b', 2), ('c', 3), ('d', 4)]\n assert candidate(original) == (['a', 'b', 'c', 'd'], [1, 2, 3, 4])\n", "\n original2 = [([], 1), ([], 2), (5, 3), (6, 4)]\n assert candidate(original2) == ([[], [], 5, 6], [1, 2, 3, 4])\n"], "entry_point": "f_19339", "intent": "unzip list `original`", "library": []} {"task_id": 19339, "prompt": "def f_19339(original):\n\treturn ", "suffix": "", "canonical_solution": "((a for (a, b) in original), (b for (a, b) in original))", "test_start": "\ndef check(candidate):", "test": ["\n original = [('a', 1), ('b', 2), ('c', 3), ('d', 4)]\n result = candidate(original)\n assert [a for gen in result for a in gen] == ['a','b','c','d',1,2,3,4]\n", "\n original2 = [([], 1), ([], 2), (5, 3), (6, 4)]\n result2 = candidate(original2)\n assert [a for gen in result2 for a in gen] == [[], [], 5, 6, 1, 2, 3, 4]\n"], "entry_point": "f_19339", "intent": "unzip list `original` and return a generator", "library": []} {"task_id": 19339, "prompt": "def f_19339():\n\treturn ", "suffix": "", "canonical_solution": "zip(*[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e',)])", "test_start": "\ndef check(candidate):", "test": ["\n assert list(candidate()) == [('a', 'b', 'c', 'd', 'e')]\n"], "entry_point": "f_19339", "intent": "unzip list `[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', )]`", "library": []} {"task_id": 19339, "prompt": "def f_19339():\n\treturn ", "suffix": "", "canonical_solution": "list(zip_longest(('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e',)))", "test_start": "\nfrom itertools import zip_longest\n\ndef check(candidate):", "test": ["\n assert(candidate() == [('a', 'b', 'c', 'd', 'e'), (1, 2, 3, 4, None)])\n"], "entry_point": "f_19339", "intent": "unzip list `[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', )]` and fill empty results with None", "library": ["itertools"]} {"task_id": 1960516, "prompt": "def f_1960516():\n\treturn ", "suffix": "", "canonical_solution": "json.dumps('3.9')", "test_start": "\nimport json\n\ndef check(candidate):", "test": ["\n data = candidate()\n assert json.loads(data) == '3.9'\n"], "entry_point": "f_1960516", "intent": "encode `Decimal('3.9')` to a JSON string", "library": ["json"]} {"task_id": 1024847, "prompt": "def f_1024847(d):\n\t", "suffix": "\n\treturn d", "canonical_solution": "d['mynewkey'] = 'mynewvalue'", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'key': 'value'}) == {'key': 'value', 'mynewkey': 'mynewvalue'}\n"], "entry_point": "f_1024847", "intent": "Add key \"mynewkey\" to dictionary `d` with value \"mynewvalue\"", "library": []} {"task_id": 1024847, "prompt": "def f_1024847(data):\n\t", "suffix": "\n\treturn data", "canonical_solution": "data.update({'a': 1, })", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'key': 'value'}) == {'key': 'value', 'a': 1}\n", "\n assert candidate({'key': 'value', 'a' : 2}) == {'key': 'value', 'a': 1}\n"], "entry_point": "f_1024847", "intent": "Add key 'a' to dictionary `data` with value 1", "library": []} {"task_id": 1024847, "prompt": "def f_1024847(data):\n\t", "suffix": "\n\treturn data", "canonical_solution": "data.update(dict(a=1))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'key': 'value'}) == {'key': 'value', 'a': 1}\n", "\n assert candidate({'key': 'value', 'a' : 2}) == {'key': 'value', 'a': 1}\n"], "entry_point": "f_1024847", "intent": "Add key 'a' to dictionary `data` with value 1", "library": []} {"task_id": 1024847, "prompt": "def f_1024847(data):\n\t", "suffix": "\n\treturn data", "canonical_solution": "data.update(a=1)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'key': 'value'}) == {'key': 'value', 'a': 1}\n", "\n assert candidate({'key': 'value', 'a' : 2}) == {'key': 'value', 'a': 1}\n"], "entry_point": "f_1024847", "intent": "Add key 'a' to dictionary `data` with value 1", "library": []} {"task_id": 35837346, "prompt": "def f_35837346(matrix):\n\treturn ", "suffix": "", "canonical_solution": "max([max(i) for i in matrix])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[1,2,3],[4,5,6],[7,8,9]]) == 9\n", "\n assert candidate([[1.3,2.8],[4.2,10],[7.9,8.1,5]]) == 10\n"], "entry_point": "f_35837346", "intent": "find maximal value in matrix `matrix`", "library": []} {"task_id": 20457038, "prompt": "def f_20457038(answer):\n\t", "suffix": "\n\treturn answer", "canonical_solution": "answer = str(round(answer, 2))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(2.34351) == \"2.34\"\n", "\n assert candidate(99.375) == \"99.38\"\n", "\n assert candidate(4.1) == \"4.1\"\n", "\n assert candidate(3) == \"3\"\n"], "entry_point": "f_20457038", "intent": "Round number `answer` to 2 precision after the decimal point", "library": []} {"task_id": 2890896, "prompt": "def f_2890896(s):\n\t", "suffix": "\n\treturn ip", "canonical_solution": "ip = re.findall('[0-9]+(?:\\\\.[0-9]+){3}', s)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(\"Current IP CheckCurrent IP Address: 165.91.15.131\") == [\"165.91.15.131\"]\n", "\n assert candidate(\"Current IP CheckCurrent IP Address: 165.91.15.131 and this is not a IP Address: 165.91.15\") == [\"165.91.15.131\"]\n", "\n assert candidate(\"Current IP CheckCurrent IP Address: 192.168.1.1 & this is another IP address: 192.168.1.2\") == [\"192.168.1.1\", \"192.168.1.2\"]\n"], "entry_point": "f_2890896", "intent": "extract ip address `ip` from an html string `s`", "library": ["re"]} {"task_id": 29836836, "prompt": "def f_29836836(df):\n\treturn ", "suffix": "", "canonical_solution": "df.groupby('A').filter(lambda x: len(x) > 1)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n assert candidate(pd.DataFrame([[1, 2], [1, 4], [5, 6]], columns=['A', 'B'])).equals(pd.DataFrame([[1, 2], [1, 4]], columns=['A', 'B'])) is True\n", "\n assert candidate(pd.DataFrame([[1, 2], [1, 4], [1, 6]], columns=['A', 'B'])).equals(pd.DataFrame([[1, 2], [1, 4], [1, 6]], columns=['A', 'B'])) is True\n"], "entry_point": "f_29836836", "intent": "filter dataframe `df` by values in column `A` that appear more than once", "library": ["pandas"]} {"task_id": 2545397, "prompt": "def f_2545397(myfile):\n\treturn ", "suffix": "", "canonical_solution": "[x for x in myfile if x != '']", "test_start": "\ndef check(candidate):", "test": ["\n with open('./tmp.txt', 'w') as fw: \n for s in [\"hello\", \"world\", \"!!!\"]:\n fw.write(f\"{s}\\n\")\n\n with open('./tmp.txt', 'r') as myfile:\n lines = candidate(myfile)\n assert isinstance(lines, list)\n assert len(lines) == 3\n assert lines[0].strip() == \"hello\"\n"], "entry_point": "f_2545397", "intent": "append each line in file `myfile` into a list", "library": []} {"task_id": 2545397, "prompt": "def f_2545397():\n\t", "suffix": "\n\treturn lst", "canonical_solution": "lst = list(map(int, open('filename.txt').readlines()))", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n with open('./filename.txt', 'w') as fw: \n for s in [\"1\", \"2\", \"100\"]:\n fw.write(f\"{s}\\n\")\n\n assert candidate() == [1, 2, 100]\n"], "entry_point": "f_2545397", "intent": "Get a list of integers `lst` from a file `filename.txt`", "library": ["pandas"]} {"task_id": 35420052, "prompt": "def f_35420052(plt, mappable, ax3):\n\t", "suffix": "\n\treturn plt", "canonical_solution": "plt.colorbar(mappable=mappable, cax=ax3)", "test_start": "\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom obspy.core.trace import Trace\nfrom obspy.imaging.spectrogram import spectrogram\n\ndef check(candidate):", "test": ["\n spl1 = Trace(data=np.arange(0, 10))\n fig = plt.figure()\n ax1 = fig.add_axes([0.1, 0.75, 0.7, 0.2]) #[left bottom width height]\n ax2 = fig.add_axes([0.1, 0.1, 0.7, 0.60], sharex=ax1)\n ax3 = fig.add_axes([0.83, 0.1, 0.03, 0.6])\n\n #make time vector\n t = np.arange(spl1.stats.npts) / spl1.stats.sampling_rate\n\n #plot waveform (top subfigure) \n ax1.plot(t, spl1.data, 'k')\n\n #plot spectrogram (bottom subfigure)\n spl2 = spl1\n fig = spl2.spectrogram(show=False, axes=ax2, wlen=10)\n mappable = ax2.images[0]\n candidate(plt, mappable, ax3)\n \n im=ax2.images\n assert im[-1].colorbar is not None\n"], "entry_point": "f_35420052", "intent": "add color bar with image `mappable` to plot `plt`", "library": ["matplotlib", "numpy", "obspy"]} {"task_id": 29903025, "prompt": "def f_29903025(df):\n\treturn ", "suffix": "", "canonical_solution": "Counter(' '.join(df['text']).split()).most_common(100)", "test_start": "\nimport pandas as pd\nfrom collections import Counter\n \ndef check(candidate):", "test": ["\n df = pd.DataFrame({\"text\": [\n 'Python is a high-level, general-purpose programming language.', \n 'Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically-typed and garbage-collected.'\n ]})\n assert candidate(df) == [('Python', 2),('is', 2),('a', 1),('high-level,', 1),('general-purpose', 1),\n ('programming', 1),('language.', 1),('Its', 1),('design', 1),('philosophy', 1),('emphasizes', 1),\n ('code', 1),('readability', 1),('with', 1), ('the', 1),('use', 1),('of', 1),('significant', 1),\n ('indentation.', 1),('dynamically-typed', 1),('and', 1),('garbage-collected.', 1)]\n"], "entry_point": "f_29903025", "intent": "count most frequent 100 words in column 'text' of dataframe `df`", "library": ["collections", "pandas"]} {"task_id": 7378180, "prompt": "def f_7378180():\n\treturn ", "suffix": "", "canonical_solution": "list(itertools.combinations((1, 2, 3), 2))", "test_start": "\nimport itertools\n\ndef check(candidate):", "test": ["\n assert candidate() == [(1, 2), (1, 3), (2, 3)]\n"], "entry_point": "f_7378180", "intent": "generate all 2-element subsets of tuple `(1, 2, 3)`", "library": ["itertools"]} {"task_id": 4530069, "prompt": "def f_4530069():\n\treturn ", "suffix": "", "canonical_solution": "datetime.now(pytz.utc)", "test_start": "\nimport pytz\nimport time\nfrom datetime import datetime, timezone\n\ndef check(candidate):", "test": ["\n assert (candidate() - datetime(1970, 1, 1).replace(tzinfo=timezone.utc)).total_seconds() - time.time() <= 1\n"], "entry_point": "f_4530069", "intent": "get a value of datetime.today() in the UTC time zone", "library": ["datetime", "pytz", "time"]} {"task_id": 4842956, "prompt": "def f_4842956(list1):\n\t", "suffix": "\n\treturn list2", "canonical_solution": "list2 = [x for x in list1 if x != []]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[\"a\"], [], [\"b\"]]) == [[\"a\"], [\"b\"]]\n", "\n assert candidate([[], [1,2,3], [], [\"b\"]]) == [[1,2,3], [\"b\"]]\n"], "entry_point": "f_4842956", "intent": "Get a new list `list2`by removing empty list from a list of lists `list1`", "library": []} {"task_id": 4842956, "prompt": "def f_4842956(list1):\n\t", "suffix": "\n\treturn list2", "canonical_solution": "list2 = [x for x in list1 if x]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([[\"a\"], [], [\"b\"]]) == [[\"a\"], [\"b\"]]\n", "\n assert candidate([[], [1,2,3], [], [\"b\"]]) == [[1,2,3], [\"b\"]]\n"], "entry_point": "f_4842956", "intent": "Create `list2` to contain the lists from list `list1` excluding the empty lists from `list1`", "library": []} {"task_id": 9262278, "prompt": "def f_9262278(data):\n\treturn ", "suffix": "", "canonical_solution": "HttpResponse(data, content_type='application/json')", "test_start": "\nimport os\nimport json\nfrom django.http import HttpResponse\nfrom django.conf import settings\nif not settings.configured:\n settings.configure(DEBUG=True)\n\ndef check(candidate):", "test": ["\n if settings.DEBUG:\n assert candidate(json.dumps({\"Sample-Key\": \"Sample-Value\"})).content == b'{\"Sample-Key\": \"Sample-Value\"}'\n", "\n if settings.DEBUG:\n assert candidate(json.dumps({\"Sample-Key\": \"Sample-Value\"}))['content-type'] == 'application/json'\n"], "entry_point": "f_9262278", "intent": "Django response with JSON `data`", "library": ["django", "json", "os"]} {"task_id": 17284947, "prompt": "def f_17284947(example_str):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('(.*?)\\\\[.*?\\\\]', example_str)", "test_start": "\nimport re \n\ndef check(candidate): ", "test": ["\n list_elems = candidate(\"Josie Smith [3996 COLLEGE AVENUE, SOMETOWN, MD 21003]Mugsy Dog Smith [2560 OAK ST, GLENMEADE, WI 14098]\")\n assert \"\".join(list_elems).strip() == 'Josie Smith Mugsy Dog Smith'\n"], "entry_point": "f_17284947", "intent": "get all text that is not enclosed within square brackets in string `example_str`", "library": ["re"]} {"task_id": 17284947, "prompt": "def f_17284947(example_str):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('(.*?)(?:\\\\[.*?\\\\]|$)', example_str)", "test_start": "\nimport re \n\ndef check(candidate): ", "test": ["\n list_elems = candidate(\"Josie Smith [3996 COLLEGE AVENUE, SOMETOWN, MD 21003]Mugsy Dog Smith [2560 OAK ST, GLENMEADE, WI 14098]\")\n assert \"\".join(list_elems).strip() == 'Josie Smith Mugsy Dog Smith'\n"], "entry_point": "f_17284947", "intent": "Use a regex to get all text in a string `example_str` that is not surrounded by square brackets", "library": ["re"]} {"task_id": 14182339, "prompt": "def f_14182339():\n\treturn ", "suffix": "", "canonical_solution": "re.findall('\\\\(.+?\\\\)|\\\\w', '(zyx)bc')", "test_start": "\nimport re \n\ndef check(candidate): ", "test": ["\n assert candidate() == ['(zyx)', 'b', 'c']\n"], "entry_point": "f_14182339", "intent": "get whatever is between parentheses as a single match, and any char outside as an individual match in string '(zyx)bc'", "library": ["re"]} {"task_id": 14182339, "prompt": "def f_14182339():\n\treturn ", "suffix": "", "canonical_solution": "re.findall('\\\\((.*?)\\\\)|(\\\\w)', '(zyx)bc')", "test_start": "\nimport re \n\ndef check(candidate): ", "test": ["\n assert candidate() == [('zyx', ''), ('', 'b'), ('', 'c')]\n"], "entry_point": "f_14182339", "intent": "match regex '\\\\((.*?)\\\\)|(\\\\w)' with string '(zyx)bc'", "library": ["re"]} {"task_id": 14182339, "prompt": "def f_14182339():\n\treturn ", "suffix": "", "canonical_solution": "re.findall('\\\\(.*?\\\\)|\\\\w', '(zyx)bc')", "test_start": "\nimport re \n\ndef check(candidate): ", "test": ["\n assert candidate() == ['(zyx)', 'b', 'c']\n"], "entry_point": "f_14182339", "intent": "match multiple regex patterns with the alternation operator `|` in a string `(zyx)bc`", "library": ["re"]} {"task_id": 7126916, "prompt": "def f_7126916(elements):\n\t", "suffix": "\n\treturn elements", "canonical_solution": "elements = ['%{0}%'.format(element) for element in elements]", "test_start": "\ndef check(candidate): ", "test": ["\n elements = ['abc', 'def', 'ijk', 'mno']\n assert candidate(elements) == ['%abc%', '%def%', '%ijk%', '%mno%']\n", "\n elements = [1, 2, 3, 4, 500]\n assert candidate(elements) == ['%1%', '%2%', '%3%', '%4%', '%500%']\n"], "entry_point": "f_7126916", "intent": "formate each string cin list `elements` into pattern '%{0}%'", "library": []} {"task_id": 3595685, "prompt": "def f_3595685():\n\treturn ", "suffix": "", "canonical_solution": "subprocess.Popen(['background-process', 'arguments'])", "test_start": "\nimport subprocess\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n subprocess.Popen = Mock(return_value = 0)\n assert candidate() == 0\n"], "entry_point": "f_3595685", "intent": "Open a background process 'background-process' with arguments 'arguments'", "library": ["subprocess"]} {"task_id": 18453566, "prompt": "def f_18453566(mydict, mykeys):\n\treturn ", "suffix": "", "canonical_solution": "[mydict[x] for x in mykeys]", "test_start": "\ndef check(candidate):", "test": ["\n mydict = {'one': 1, 'two': 2, 'three': 3}\n mykeys = ['three', 'one']\n assert candidate(mydict, mykeys) == [3, 1]\n", "\n mydict = {'one': 1.0, 'two': 2.0, 'three': 3.0}\n mykeys = ['one']\n assert candidate(mydict, mykeys) == [1.0]\n"], "entry_point": "f_18453566", "intent": "get list of values from dictionary 'mydict' w.r.t. list of keys 'mykeys'", "library": []} {"task_id": 12692135, "prompt": "def f_12692135():\n\treturn ", "suffix": "", "canonical_solution": "dict([('Name', 'Joe'), ('Age', 22)])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == {'Name': 'Joe', 'Age': 22}\n"], "entry_point": "f_12692135", "intent": "convert list `[('Name', 'Joe'), ('Age', 22)]` into a dictionary", "library": []} {"task_id": 14401047, "prompt": "def f_14401047(data):\n\treturn ", "suffix": "", "canonical_solution": "data.mean(axis=1).reshape(data.shape[0], -1)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n data = np.array([[1, 2, 3, 4, 4, 3, 7, 1], [6, 2, 3, 4, 3, 4, 4, 1]])\n expected_res = np.array([[3.125], [3.375]])\n assert np.array_equal(candidate(data), expected_res)\n"], "entry_point": "f_14401047", "intent": "average each two columns of array `data`", "library": ["numpy"]} {"task_id": 18886596, "prompt": "def f_18886596(s):\n\treturn ", "suffix": "", "canonical_solution": "s.replace('\"', '\\\"')", "test_start": "\ndef check(candidate):", "test": ["\n s = 'This sentence has some \"quotes\" in it'\n assert candidate(s) == 'This sentence has some \\\"quotes\\\" in it'\n"], "entry_point": "f_18886596", "intent": "double backslash escape all double quotes in string `s`", "library": []} {"task_id": 5932059, "prompt": "def f_5932059(s):\n\treturn ", "suffix": "", "canonical_solution": "re.split('(\\\\W+)', s)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n s = \"this is a\\nsentence\"\n assert candidate(s) == ['this', ' ', 'is', ' ', 'a', '\\n', 'sentence']\n"], "entry_point": "f_5932059", "intent": "split a string `s` into a list of words and whitespace", "library": ["re"]} {"task_id": 9938130, "prompt": "def f_9938130(df):\n\treturn ", "suffix": "", "canonical_solution": "df.plot(kind='barh', stacked=True)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n data = [[1, 3], [2, 5], [4, 8]]\n df = pd.DataFrame(data, columns = ['a', 'b'])\n assert str(candidate(df)).split('(')[0] == 'AxesSubplot'\n"], "entry_point": "f_9938130", "intent": "plotting stacked barplots on a panda data frame `df`", "library": ["pandas"]} {"task_id": 35945473, "prompt": "def f_35945473(myDictionary):\n\treturn ", "suffix": "", "canonical_solution": "{i[1]: i[0] for i in list(myDictionary.items())}", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'a' : 'b', 'c' : 'd'}) == {'b': 'a', 'd': 'c'}\n"], "entry_point": "f_35945473", "intent": "reverse the keys and values in a dictionary `myDictionary`", "library": []} {"task_id": 30729735, "prompt": "def f_30729735(myList):\n\treturn ", "suffix": "", "canonical_solution": "[i for i, j in enumerate(myList) if 'how' in j.lower() or 'what' in j.lower()]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['abc', 'how', 'what', 'def']) == [1, 2]\n"], "entry_point": "f_30729735", "intent": "finding the index of elements containing substring 'how' and 'what' in a list of strings 'myList'.", "library": []} {"task_id": 1303243, "prompt": "def f_1303243(obj):\n\treturn ", "suffix": "", "canonical_solution": "isinstance(obj, str)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('python3') == True\n", "\n assert candidate(1.23) == False\n"], "entry_point": "f_1303243", "intent": "check if object `obj` is a string", "library": []} {"task_id": 1303243, "prompt": "def f_1303243(o):\n\treturn ", "suffix": "", "canonical_solution": "isinstance(o, str)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"hello\") == True\n", "\n assert candidate(123) == False\n", "\n assert candidate([]) == False\n", "\n assert candidate({\"aa\", \"v\"}) == False\n", "\n assert candidate(\"123\") == True\n"], "entry_point": "f_1303243", "intent": "check if object `o` is a string", "library": []} {"task_id": 1303243, "prompt": "def f_1303243(o):\n\treturn ", "suffix": "", "canonical_solution": "(type(o) is str)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"hello\") == True\n", "\n assert candidate(123) == False\n", "\n assert candidate([]) == False\n", "\n assert candidate({\"aa\", \"v\"}) == False\n", "\n assert candidate(\"123\") == True\n"], "entry_point": "f_1303243", "intent": "check if object `o` is a string", "library": []} {"task_id": 1303243, "prompt": "def f_1303243(obj_to_test):\n\treturn ", "suffix": "", "canonical_solution": "isinstance(obj_to_test, str)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"hello\") == True\n", "\n assert candidate(123) == False\n", "\n assert candidate([]) == False\n", "\n assert candidate({\"aa\", \"v\"}) == False\n", "\n assert candidate(\"123\") == True\n"], "entry_point": "f_1303243", "intent": "check if `obj_to_test` is a string", "library": []} {"task_id": 8177079, "prompt": "def f_8177079(list1, list2):\n\t", "suffix": "\n\treturn ", "canonical_solution": "list2.extend(list1)", "test_start": "\ndef check(candidate):", "test": ["\n a, b = [1, 2, 3], [4, 5, 6]\n candidate(a, b)\n assert b == [4, 5, 6, 1, 2, 3]\n", "\n a, c = [1, 2, 3], [7, 8, 9]\n candidate(a, c)\n assert c == [7, 8, 9, 1, 2, 3] \n", "\n b = [4, 5, 6, 1, 2, 3]\n c = [7, 8, 9, 1, 2, 3] \n candidate(b, c)\n assert c == [7, 8, 9, 1, 2, 3, 4, 5, 6, 1, 2, 3]\n"], "entry_point": "f_8177079", "intent": "append list `list1` to `list2`", "library": []} {"task_id": 8177079, "prompt": "def f_8177079(mylog, list1):\n\t", "suffix": "\n\treturn ", "canonical_solution": "list1.extend(mylog)", "test_start": "\ndef check(candidate):", "test": ["\n a, b = [1, 2, 3], [4, 5, 6]\n candidate(a, b)\n assert b == [4, 5, 6, 1, 2, 3]\n", "\n a, c = [1, 2, 3], [7, 8, 9]\n candidate(a, c)\n assert c == [7, 8, 9, 1, 2, 3] \n", "\n b = [4, 5, 6, 1, 2, 3]\n c = [7, 8, 9, 1, 2, 3] \n candidate(b, c)\n assert c == [7, 8, 9, 1, 2, 3, 4, 5, 6, 1, 2, 3]\n"], "entry_point": "f_8177079", "intent": "append list `mylog` to `list1`", "library": []} {"task_id": 8177079, "prompt": "def f_8177079(a, c):\n\t", "suffix": "\n\treturn ", "canonical_solution": "c.extend(a)", "test_start": "\ndef check(candidate):", "test": ["\n a, b = [1, 2, 3], [4, 5, 6]\n candidate(a, b)\n assert b == [4, 5, 6, 1, 2, 3]\n", "\n a, c = [1, 2, 3], [7, 8, 9]\n candidate(a, c)\n assert c == [7, 8, 9, 1, 2, 3] \n", "\n b = [4, 5, 6, 1, 2, 3]\n c = [7, 8, 9, 1, 2, 3] \n candidate(b, c)\n assert c == [7, 8, 9, 1, 2, 3, 4, 5, 6, 1, 2, 3]\n"], "entry_point": "f_8177079", "intent": "append list `a` to `c`", "library": []} {"task_id": 8177079, "prompt": "def f_8177079(mylog, list1):\n\t", "suffix": "\n\treturn ", "canonical_solution": "for line in mylog:\n\t list1.append(line)", "test_start": "\ndef check(candidate):", "test": ["\n a, b = [1, 2, 3], [4, 5, 6]\n candidate(a, b)\n assert b == [4, 5, 6, 1, 2, 3]\n", "\n a, c = [1, 2, 3], [7, 8, 9]\n candidate(a, c)\n assert c == [7, 8, 9, 1, 2, 3] \n", "\n b = [4, 5, 6, 1, 2, 3]\n c = [7, 8, 9, 1, 2, 3] \n candidate(b, c)\n assert c == [7, 8, 9, 1, 2, 3, 4, 5, 6, 1, 2, 3]\n"], "entry_point": "f_8177079", "intent": "append items in list `mylog` to `list1`", "library": []} {"task_id": 4126227, "prompt": "def f_4126227(a, b):\n\t", "suffix": "\n\treturn ", "canonical_solution": "b.append((a[0][0], a[0][2]))", "test_start": "\ndef check(candidate):", "test": ["\n a = [(1,2,3),(4,5,6)]\n b = [(0,0)]\n candidate(a, b)\n assert(b == [(0, 0), (1, 3)])\n"], "entry_point": "f_4126227", "intent": "append a tuple of elements from list `a` with indexes '[0][0] [0][2]' to list `b`", "library": []} {"task_id": 34902378, "prompt": "def f_34902378(app):\n\t", "suffix": "\n\treturn ", "canonical_solution": "app.config['SECRET_KEY'] = 'Your_secret_string'", "test_start": "\nfrom flask import Flask\n\ndef check(candidate):", "test": ["\n app = Flask(\"test\")\n candidate(app)\n assert app.config['SECRET_KEY'] == 'Your_secret_string'\n"], "entry_point": "f_34902378", "intent": "Initialize `SECRET_KEY` in flask config with `Your_secret_string `", "library": ["flask"]} {"task_id": 22799300, "prompt": "def f_22799300(out):\n\treturn ", "suffix": "", "canonical_solution": "pd.DataFrame(out.tolist(), columns=['out-1', 'out-2'], index=out.index)", "test_start": "\nimport numpy as np\nimport pandas as pd\nfrom scipy import stats\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame(dict(x=np.random.randn(100), y=np.repeat(list(\"abcd\"), 25)))\n out = df.groupby(\"y\").x.apply(stats.ttest_1samp, 0)\n test = pd.DataFrame(out.tolist())\n test.columns = ['out-1', 'out-2']\n test.index = out.index\n res = candidate(out)\n assert(test.equals(res))\n"], "entry_point": "f_22799300", "intent": "unpack a series of tuples in pandas `out` into a DataFrame with column names 'out-1' and 'out-2'", "library": ["numpy", "pandas", "scipy"]} {"task_id": 1762484, "prompt": "def f_1762484(stocks_list):\n\treturn ", "suffix": "", "canonical_solution": "[x for x in range(len(stocks_list)) if stocks_list[x] == 'MSFT']", "test_start": "\ndef check(candidate):", "test": ["\n stocks_list = ['AAPL', 'MSFT', 'GOOG', 'MSFT', 'MSFT']\n assert(candidate(stocks_list) == [1,3,4])\n", "\n stocks_list = ['AAPL', 'MSXT', 'GOOG', 'MSAT', 'SFT']\n assert(candidate(stocks_list) == [])\n"], "entry_point": "f_1762484", "intent": "find the index of an element 'MSFT' in a list `stocks_list`", "library": []} {"task_id": 3464359, "prompt": "def f_3464359(ax, labels):\n\treturn ", "suffix": "", "canonical_solution": "ax.set_xticklabels(labels, rotation=45)", "test_start": "\nimport matplotlib.pyplot as plt \n\ndef check(candidate):", "test": ["\n fig, ax = plt.subplots()\n ax.plot([1, 2, 3, 4], [1, 4, 2, 3])\n ret = candidate(ax, [f\"#{i}\" for i in range(7)])\n assert [tt.get_rotation() == 45.0 for tt in ret]\n"], "entry_point": "f_3464359", "intent": "rotate the xtick `labels` of matplotlib plot `ax` by `45` degrees to make long labels readable", "library": ["matplotlib"]} {"task_id": 875968, "prompt": "def f_875968(s):\n\treturn ", "suffix": "", "canonical_solution": "re.sub('[^\\\\w]', ' ', s)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n s = \"how much for the maple syrup? $20.99? That's ridiculous!!!\"\n assert candidate(s) == 'how much for the maple syrup 20 99 That s ridiculous '\n"], "entry_point": "f_875968", "intent": "remove symbols from a string `s`", "library": ["re"]} {"task_id": 34750084, "prompt": "def f_34750084(s):\n\treturn ", "suffix": "", "canonical_solution": "re.findall(\"'\\\\\\\\[0-7]{1,3}'\", s)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate(r\"char x = '\\077';\") == [\"'\\\\077'\"]\n"], "entry_point": "f_34750084", "intent": "Find octal characters matches from a string `s` using regex", "library": ["re"]} {"task_id": 13209288, "prompt": "def f_13209288(input):\n\treturn ", "suffix": "", "canonical_solution": "re.split(r'[ ](?=[A-Z]+\\b)', input)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate('HELLO there HOW are YOU') == ['HELLO there', 'HOW are', 'YOU']\n", "\n assert candidate('hELLO there HoW are YOU') == ['hELLO there HoW are', 'YOU']\n", "\n assert candidate('7 is a NUMBER') == ['7 is a', 'NUMBER']\n", "\n assert candidate('NUMBER 7') == ['NUMBER 7']\n"], "entry_point": "f_13209288", "intent": "split string `input` based on occurrences of regex pattern '[ ](?=[A-Z]+\\\\b)'", "library": ["re"]} {"task_id": 13209288, "prompt": "def f_13209288(input):\n\treturn ", "suffix": "", "canonical_solution": "re.split('[ ](?=[A-Z])', input)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate('HELLO there HOW are YOU') == ['HELLO there', 'HOW are', 'YOU']\n", "\n assert candidate('hELLO there HoW are YOU') == ['hELLO there', 'HoW are', 'YOU']\n", "\n assert candidate('7 is a NUMBER') == ['7 is a', 'NUMBER']\n", "\n assert candidate('NUMBER 7') == ['NUMBER 7']\n"], "entry_point": "f_13209288", "intent": "Split string `input` at every space followed by an upper-case letter", "library": ["re"]} {"task_id": 24642040, "prompt": "def f_24642040(url, files, headers, data):\n\treturn ", "suffix": "", "canonical_solution": "requests.post(url, files=files, headers=headers, data=data)", "test_start": "\nimport requests\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n requests.post = Mock()\n try:\n candidate('https://www.google.com', ['a.txt'], {'accept': 'text/json'}, {'name': 'abc'})\n except:\n assert False\n"], "entry_point": "f_24642040", "intent": "send multipart encoded file `files` to url `url` with headers `headers` and metadata `data`", "library": ["requests"]} {"task_id": 4290716, "prompt": "def f_4290716(filename, bytes_):\n\treturn ", "suffix": "", "canonical_solution": "open(filename, 'wb').write(bytes_)", "test_start": "\ndef check(candidate):", "test": ["\n bytes_ = b'68 65 6c 6c 6f'\n candidate(\"tmpfile\", bytes_)\n\n with open(\"tmpfile\", 'rb') as fr:\n assert fr.read() == bytes_\n"], "entry_point": "f_4290716", "intent": "write bytes `bytes_` to a file `filename` in python 3", "library": []} {"task_id": 33078554, "prompt": "def f_33078554(lst, dct):\n\treturn ", "suffix": "", "canonical_solution": "[dct[k] for k in lst]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['c', 'd', 'a', 'b', 'd'], {'a': '3', 'b': '3', 'c': '5', 'd': '3'}) == ['5', '3', '3', '3', '3'] \n", "\n assert candidate(['c', 'd', 'a', 'b', 'd'], {'a': 3, 'b': 3, 'c': 5, 'd': 3}) == [5, 3, 3, 3, 3] \n", "\n assert candidate(['c', 'd', 'a', 'b'], {'a': 3, 'b': 3, 'c': 5, 'd': 3}) == [5, 3, 3, 3]\n"], "entry_point": "f_33078554", "intent": "get a list from a list `lst` with values mapped into a dictionary `dct`", "library": []} {"task_id": 15247628, "prompt": "def f_15247628(x):\n\treturn ", "suffix": "", "canonical_solution": "x['name'][x.duplicated('name')]", "test_start": "\nimport pandas as pd \n\ndef check(candidate): ", "test": ["\n assert candidate(pd.DataFrame([{'name': 'willy', 'age': 10}, {'name': 'wilson', 'age': 11}, {'name': 'zoe', 'age': 10}])).tolist() == [] \n", "\n assert candidate(pd.DataFrame([{'name': 'willy', 'age': 10}, {'name': 'willy', 'age': 11}, {'name': 'zoe', 'age': 10}])).tolist() == ['willy'] \n", "\n assert candidate(pd.DataFrame([{'name': 'willy', 'age': 11}, {'name': 'willy', 'age': 11}, {'name': 'zoe', 'age': 10}])).tolist() == ['willy'] \n", "\n assert candidate(pd.DataFrame([{'name': 'Willy', 'age': 11}, {'name': 'willy', 'age': 11}, {'name': 'zoe', 'age': 10}])).tolist() == []\n"], "entry_point": "f_15247628", "intent": "find duplicate names in column 'name' of the dataframe `x`", "library": ["pandas"]} {"task_id": 783897, "prompt": "def f_783897():\n\treturn ", "suffix": "", "canonical_solution": "round(1.923328437452, 3)", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate() == 1.923\n"], "entry_point": "f_783897", "intent": "truncate float 1.923328437452 to 3 decimal places", "library": []} {"task_id": 22859493, "prompt": "def f_22859493(li):\n\treturn ", "suffix": "", "canonical_solution": "sorted(li, key=lambda x: datetime.strptime(x[1], '%d/%m/%Y'), reverse=True)", "test_start": "\nfrom datetime import datetime\n\ndef check(candidate): ", "test": ["\n assert candidate([['name', '01/03/2012', 'job'], ['name', '02/05/2013', 'job'], ['name', '03/08/2014', 'job']]) == [['name', '03/08/2014', 'job'], ['name', '02/05/2013', 'job'], ['name', '01/03/2012', 'job']] \n", "\n assert candidate([['name', '01/03/2012', 'job'], ['name', '02/05/2012', 'job'], ['name', '03/08/2012', 'job']]) == [['name', '03/08/2012', 'job'], ['name', '02/05/2012', 'job'], ['name', '01/03/2012', 'job']] \n", "\n assert candidate([['name', '01/03/2012', 'job'], ['name', '02/03/2012', 'job'], ['name', '03/03/2012', 'job']]) == [['name', '03/03/2012', 'job'], ['name', '02/03/2012', 'job'], ['name', '01/03/2012', 'job']] \n", "\n assert candidate([['name', '03/03/2012', 'job'], ['name', '03/03/2012', 'job'], ['name', '03/03/2012', 'job']]) == [['name', '03/03/2012', 'job'], ['name', '03/03/2012', 'job'], ['name', '03/03/2012', 'job']] \n"], "entry_point": "f_22859493", "intent": "sort list `li` in descending order based on the date value in second element of each list in list `li`", "library": ["datetime"]} {"task_id": 29394552, "prompt": "def f_29394552(ax):\n\t", "suffix": "\n\treturn ", "canonical_solution": "ax.set_rlabel_position(135)", "test_start": "\nimport matplotlib.pyplot as plt \n\ndef check(candidate): ", "test": ["\n ax = plt.subplot(111, polar=True)\n candidate(ax)\n assert ax.properties()['rlabel_position'] == 135.0\n"], "entry_point": "f_29394552", "intent": "place the radial ticks in plot `ax` at 135 degrees", "library": ["matplotlib"]} {"task_id": 3320406, "prompt": "def f_3320406(my_path):\n\treturn ", "suffix": "", "canonical_solution": "os.path.isabs(my_path)", "test_start": "\nimport os\n\ndef check(candidate): ", "test": ["\n assert candidate('.') == False \n", "\n assert candidate('/') == True \n", "\n assert candidate('/usr') == True\n"], "entry_point": "f_3320406", "intent": "check if path `my_path` is an absolute path", "library": ["os"]} {"task_id": 2212433, "prompt": "def f_2212433(yourdict):\n\treturn ", "suffix": "", "canonical_solution": "len(list(yourdict.keys()))", "test_start": "\ndef check(candidate): ", "test": ["\n assert candidate({'a': 1, 'b': 2, 'c': 3}) == 3 \n", "\n assert candidate({'a': 2, 'c': 3}) == 2\n"], "entry_point": "f_2212433", "intent": "get number of keys in dictionary `yourdict`", "library": []} {"task_id": 2212433, "prompt": "def f_2212433(yourdictfile):\n\treturn ", "suffix": "", "canonical_solution": "len(set(open(yourdictfile).read().split()))", "test_start": "\ndef check(candidate): ", "test": ["\n with open('dict.txt', 'w') as fw:\n for w in [\"apple\", \"banana\", \"tv\", \"apple\", \"phone\"]:\n fw.write(f\"{w}\\n\")\n assert candidate('dict.txt') == 4\n"], "entry_point": "f_2212433", "intent": "count the number of keys in dictionary `yourdictfile`", "library": []} {"task_id": 20067636, "prompt": "def f_20067636(df):\n\treturn ", "suffix": "", "canonical_solution": "df.groupby('id').first()", "test_start": "\nimport pandas as pd \n\ndef check(candidate): ", "test": ["\n df = pd.DataFrame({\n 'id': [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6, 6, 6, 7, 7], \n 'value': ['first', 'second', 'second', 'first', 'second', 'first', 'third', 'fourth', 'fifth', 'second', 'fifth', 'first', 'first', 'second', 'third', 'fourth', 'fifth']\n })\n assert candidate(df).to_dict() == {'value': {1: 'first', 2: 'first', 3: 'first', 4: 'second', 5: 'first', 6: 'first', 7: 'fourth'}}\n"], "entry_point": "f_20067636", "intent": "pandas dataframe `df` get first row of each group by 'id'", "library": ["pandas"]} {"task_id": 40924332, "prompt": "def f_40924332(df):\n\treturn ", "suffix": "", "canonical_solution": "pd.concat([df[0].apply(pd.Series), df[1]], axis=1)", "test_start": "\nimport numpy as np\nimport pandas as pd \n\ndef check(callerFunction):", "test": ["\n assert callerFunction(pd.DataFrame([[[8, 10, 12], 'A'], [[7, 9, 11], 'B']])).equals(pd.DataFrame([[8,10,12,'A'], [7,9,11,'B']], columns=[0,1,2,1]))\n", "\n assert callerFunction(pd.DataFrame([[[8, 10, 12], 'A'], [[7, 11], 'B']])).equals(pd.DataFrame([[8.0,10.0,12.0,'A'], [7.0,11.0,np.nan,'B']], columns=[0,1,2,1]))\n", "\n assert callerFunction(pd.DataFrame([[[8, 10, 12]], [[7, 9, 11], 'B']])).equals(pd.DataFrame([[8,10,12,None], [7,9,11,'B']], columns=[0,1,2,1]))\n"], "entry_point": "f_40924332", "intent": "split a list in first column into multiple columns keeping other columns as well in pandas data frame `df`", "library": ["numpy", "pandas"]} {"task_id": 30759776, "prompt": "def f_30759776(data):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('src=\"js/([^\"]*\\\\bjquery\\\\b[^\"]*)\"', data)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n data = '