File size: 241,247 Bytes
835bb8c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
{"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__) == \"<class '_io.TextIOWrapper'>\"\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('(?<!Distillr)\\\\\\\\AcroTray\\\\.exe', 'C:\\\\SomeDir\\\\AcroTray.exe')", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n result = candidate()\n assert result.span() == (10, 23)\n assert result.string == \"C:\\SomeDir\\AcroTray.exe\"\n"], "entry_point": "f_15534223", "intent": "search for string that matches regular expression pattern '(?<!Distillr)\\\\\\\\AcroTray\\\\.exe' in string 'C:\\\\SomeDir\\\\AcroTray.exe'", "library": ["re"]}
{"task_id": 5453026, "prompt": "def f_5453026():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"QH QD JC KD JS\"\"\".split()", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == [\"QH\", \"QD\", \"JC\", \"KD\", \"JS\"]\n"], "entry_point": "f_5453026", "intent": "split string 'QH QD JC KD JS' into a list on white spaces", "library": []}
{"task_id": 18168684, "prompt": "def f_18168684(line):\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 = \"<contact><name>LastName</name><lastName>FirstName</lastName><phone>+90 333 12345</phone></contact>\"\n soup = BeautifulSoup(content)\n assert candidate(soup) == \"LastName\"\n", "\n content = \"<name>hello world!</name>\"\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 = \"<a>This is not div <div>This is div 1</div><div id='main-content'>This is div 2</div></a>\"\n soup = BeautifulSoup(markup,\"html.parser\")\n candidate(soup)\n assert str(soup) == '<a>This is not div <div>This is div 1</div></a>'\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', '<i4'), ('f1', '<i4')])\n assert np.array_equal(c, e)\n"], "entry_point": "f_17960441", "intent": "zip two 2-d arrays `a` and `b`", "library": ["numpy"]}
{"task_id": 438684, "prompt": "def f_438684(list_of_ints):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\",\"\"\".join([str(i) for i in list_of_ints])", "test_start": "\ndef check(candidate):", "test": ["\n list_of_ints = [8, 7, 6]\n assert candidate(list_of_ints) == '8,7,6'\n", "\n list_of_ints = [0, 1, 6]\n assert candidate(list_of_ints) == '0,1,6'\n"], "entry_point": "f_438684", "intent": "convert list `list_of_ints` into a comma separated string", "library": []}
{"task_id": 8519922, "prompt": "def f_8519922(url, DATA, HEADERS_DICT, username, password):\n\treturn ", "suffix": "", "canonical_solution": "requests.post(url, data=DATA, headers=HEADERS_DICT, auth=(username, password))", "test_start": "\nimport requests\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n url='https://www.google.com'\n HEADERS_DICT = {'Accept':'text/json'}\n requests.post = Mock()\n try:\n candidate(url, \"{'name': 'abc'}\", HEADERS_DICT, 'admin', 'admin123')\n except:\n assert False\n"], "entry_point": "f_8519922", "intent": "Send a post request with raw data `DATA` and basic authentication with `username` and `password`", "library": ["requests"]}
{"task_id": 26443308, "prompt": "def f_26443308():\n\treturn ", "suffix": "", "canonical_solution": "'abcd}def}'.rfind('}')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 8\n"], "entry_point": "f_26443308", "intent": "Find last occurrence of character '}' in string \"abcd}def}\"", "library": []}
{"task_id": 22365172, "prompt": "def f_22365172():\n\treturn ", "suffix": "", "canonical_solution": "[item for item in [1, 2, 3]]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == [1,2,3]\n"], "entry_point": "f_22365172", "intent": "Iterate ove list `[1, 2, 3]` using list comprehension", "library": []}
{"task_id": 12300912, "prompt": "def f_12300912(d):\n\treturn ", "suffix": "", "canonical_solution": "[(x['x'], x['y']) for x in d]", "test_start": "\ndef check(candidate):", "test": ["\n data = [{'x': 1, 'y': 10}, {'x': 3, 'y': 15}, {'x': 2, 'y': 1}]\n res = candidate(data)\n assert res == [(1, 10), (3, 15), (2, 1)]\n"], "entry_point": "f_12300912", "intent": "extract all the values with keys 'x' and 'y' from a list of dictionaries `d` to list of tuples", "library": []}
{"task_id": 678236, "prompt": "def f_678236():\n\treturn ", "suffix": "", "canonical_solution": "os.path.splitext(os.path.basename('hemanth.txt'))[0]", "test_start": "\nimport os \n\ndef check(candidate):", "test": ["\n assert candidate() == \"hemanth\"\n"], "entry_point": "f_678236", "intent": "get the filename without the extension from file 'hemanth.txt'", "library": ["os"]}
{"task_id": 7895449, "prompt": "def f_7895449():\n\treturn ", "suffix": "", "canonical_solution": "sum([['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I']], [])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']\n"], "entry_point": "f_7895449", "intent": "create a list containing flattened list `[['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I']]`", "library": []}
{"task_id": 31617845, "prompt": "def f_31617845(df):\n\t", "suffix": "\n\treturn df", "canonical_solution": "df = df[(df['closing_price'] >= 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': '<br>'}, 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<br>pqr', 'wxy<br>jkl'], columns = ['val'])\n assert pd.DataFrame.equals(candidate(df), expected)\n"], "entry_point": "f_25698710", "intent": "replace all occurences of newlines `\\n` with `<br>` in dataframe `df`", "library": ["pandas"]}
{"task_id": 25698710, "prompt": "def f_25698710(df):\n\treturn ", "suffix": "", "canonical_solution": "df.replace({'\\n': '<br>'}, 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<br>pqr', 'wxy<br>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 `<br>` 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('(?P<url>https?://[^\\\\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(\"<td><b>Address:</b></td><td>My home address</td>\")) == \"My home address\"\n", "\n assert candidate(BeautifulSoup(\"<td><b>Address:</b></td><td>This is my home address</td><td>Not my home address</td>\")) == \"This is my home address\"\n", "\n assert candidate(BeautifulSoup(\"<td><b>Address:</b></td><td>My home address<li>My home address in a list</li></td>\")) == \"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 = '''<span class=\"starBig sp\">4.1</span>\n <span class=\"starGryB sp\">2.9</span>\n <span class=\"sp starGryB\">2.9</span>\n <span class=\"sp starBig\">22</span>'''\n soup = bs4.BeautifulSoup(html, features=\"html5lib\")\n res = '''[<span class=\"starGryB sp\">2.9</span>]'''\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)) == \"<class '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(\"<html><head><title>Current IP Check</title></head><body>Current IP Address: 165.91.15.131</body></html>\") == [\"165.91.15.131\"]\n", "\n assert candidate(\"<html><head><title>Current IP Check</title></head><body>Current IP Address: 165.91.15.131 and this is not a IP Address: 165.91.15</body></html>\") == [\"165.91.15.131\"]\n", "\n assert candidate(\"<html><head><title>Current IP Check</title></head><body>Current IP Address: 192.168.1.1 & this is another IP address: 192.168.1.2</body></html>\") == [\"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 = '<script type=\"text/javascript\" src=\"js/jquery-1.9.1.min.js\"/><script type=\"text/javascript\" src=\"js/jquery-migrate-1.2.1.min.js\"/><script type=\"text/javascript\" src=\"js/jquery-ui.min.js\"/><script type=\"text/javascript\" src=\"js/abc_bsub.js\"/><script type=\"text/javascript\" src=\"js/abc_core.js\"/> <script type=\"text/javascript\" src=\"js/abc_explore.js\"/><script type=\"text/javascript\" src=\"js/abc_qaa.js\"/>'\n assert candidate(data) == ['jquery-1.9.1.min.js', 'jquery-migrate-1.2.1.min.js', 'jquery-ui.min.js']\n"], "entry_point": "f_30759776", "intent": "extract attributes 'src=\"js/([^\"]*\\\\bjquery\\\\b[^\"]*)\"' from string `data`", "library": ["re"]}
{"task_id": 25388796, "prompt": "def f_25388796():\n\treturn ", "suffix": "", "canonical_solution": "sum(int(float(item)) for item in [_f for _f in ['', '3.4', '', '', '1.0'] if _f])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 4\n"], "entry_point": "f_25388796", "intent": "Sum integers contained in strings in list `['', '3.4', '', '', '1.0']`", "library": []}
{"task_id": 804995, "prompt": "def f_804995():\n\treturn ", "suffix": "", "canonical_solution": "subprocess.Popen(['c:\\\\Program Files\\\\VMware\\\\VMware Server\\\\vmware-cmd.bat'])", "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_804995", "intent": "Call a subprocess with arguments `c:\\\\Program Files\\\\VMware\\\\VMware Server\\\\vmware-cmd.bat` that may contain spaces", "library": ["subprocess"]}
{"task_id": 26441253, "prompt": "def f_26441253(q):\n\t", "suffix": "\n\treturn q", "canonical_solution": "for n in [1,3,4,2]: q.put((-n, n))", "test_start": "\nfrom queue import PriorityQueue\n\ndef check(candidate):", "test": ["\n q = PriorityQueue()\n q = candidate(q)\n expected = [4, 3, 2, 1]\n for i in range(0, len(expected)):\n assert q.get()[1] == expected[i]\n"], "entry_point": "f_26441253", "intent": "reverse a priority queue `q` in python without using classes", "library": ["queue"]}
{"task_id": 18897261, "prompt": "def f_18897261(df):\n\treturn ", "suffix": "", "canonical_solution": "df['group'].plot(kind='bar', color=['r', 'g', 'b', 'r', 'g', 'b', 'r'])", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([1, 3, 4, 5, 7, 9], columns = ['group'])\n a = candidate(df)\n assert 'AxesSubplot' in str(type(a))\n"], "entry_point": "f_18897261", "intent": "make a barplot of data in column `group` of dataframe `df` colour-coded according to list `color`", "library": ["pandas"]}
{"task_id": 373194, "prompt": "def f_373194(data):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('([a-fA-F\\\\d]{32})', data)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate('6f96cfdfe5ccc627cadf24b41725caa4 gorilla') == ['6f96cfdfe5ccc627cadf24b41725caa4']\n"], "entry_point": "f_373194", "intent": "find all matches of regex pattern '([a-fA-F\\\\d]{32})' in string `data`", "library": ["re"]}
{"task_id": 518021, "prompt": "def f_518021(my_list):\n\treturn ", "suffix": "", "canonical_solution": "len(my_list)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([]) == 0\n", "\n assert candidate([1]) == 1\n", "\n assert candidate([1, 2]) == 2\n"], "entry_point": "f_518021", "intent": "Get the length of list `my_list`", "library": []}
{"task_id": 518021, "prompt": "def f_518021(l):\n\treturn ", "suffix": "", "canonical_solution": "len(l)", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n assert candidate([]) == 0\n", "\n assert candidate(np.array([1])) == 1\n", "\n assert candidate(np.array([1, 2])) == 2\n"], "entry_point": "f_518021", "intent": "Getting the length of array `l`", "library": ["numpy"]}
{"task_id": 518021, "prompt": "def f_518021(s):\n\treturn ", "suffix": "", "canonical_solution": "len(s)", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n assert candidate([]) == 0\n", "\n assert candidate(np.array([1])) == 1\n", "\n assert candidate(np.array([1, 2])) == 2\n"], "entry_point": "f_518021", "intent": "Getting the length of array `s`", "library": ["numpy"]}
{"task_id": 518021, "prompt": "def f_518021(my_tuple):\n\treturn ", "suffix": "", "canonical_solution": "len(my_tuple)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(()) == 0\n", "\n assert candidate(('aa', 'wfseg', '')) == 3\n", "\n assert candidate(('apple',)) == 1\n"], "entry_point": "f_518021", "intent": "Getting the length of `my_tuple`", "library": []}
{"task_id": 518021, "prompt": "def f_518021(my_string):\n\treturn ", "suffix": "", "canonical_solution": "len(my_string)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"sedfgbdjofgljnh\") == 15\n", "\n assert candidate(\" \") == 13\n", "\n assert candidate(\"vsdh4'cdf'\") == 10\n"], "entry_point": "f_518021", "intent": "Getting the length of `my_string`", "library": []}
{"task_id": 40452956, "prompt": "def f_40452956():\n\treturn ", "suffix": "", "canonical_solution": "b'\\\\a'.decode('unicode-escape')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == '\\x07'\n"], "entry_point": "f_40452956", "intent": "remove escape character from string \"\\\\a\"", "library": []}
{"task_id": 8687018, "prompt": "def f_8687018():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"obama\"\"\".replace('a', '%temp%').replace('b', 'a').replace('%temp%', 'b')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 'oabmb'\n"], "entry_point": "f_8687018", "intent": "replace each 'a' with 'b' and each 'b' with 'a' in the string 'obama' in a single pass.", "library": []}
{"task_id": 303200, "prompt": "def f_303200():\n\t", "suffix": "\n\treturn ", "canonical_solution": "shutil.rmtree('/folder_name')", "test_start": "\nimport os\nimport shutil\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n shutil.rmtree = Mock()\n os.walk = Mock(return_value = [])\n candidate()\n assert os.walk('/') == []\n"], "entry_point": "f_303200", "intent": "remove directory tree '/folder_name'", "library": ["os", "shutil"]}
{"task_id": 13740672, "prompt": "def f_13740672(data):\n\t", "suffix": "\n\treturn data", "canonical_solution": "\n def weekday(i):\n if i >=1 and i <= 5: return True\n else: return False\n data['weekday'] = data['my_dt'].apply(lambda x: weekday(x))\n", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n data = pd.DataFrame([1, 2, 3, 4, 5, 6, 7], columns = ['my_dt'])\n data = candidate(data)\n assert data['weekday'][5] == False\n assert data['weekday'][6] == False\n for i in range (0, 5):\n assert data['weekday'][i]\n"], "entry_point": "f_13740672", "intent": "create a new column `weekday` in pandas data frame `data` based on the values in column `my_dt`", "library": ["pandas"]}
{"task_id": 20950650, "prompt": "def f_20950650(x):\n\treturn ", "suffix": "", "canonical_solution": "sorted(x, key=x.get, reverse=True)", "test_start": "\nfrom collections import Counter\n\ndef check(candidate):", "test": ["\n x = Counter({'blue': 1, 'red': 2, 'green': 3})\n assert candidate(x) == ['green', 'red', 'blue']\n", "\n x = Counter({'blue': 1.234, 'red': 1.35, 'green': 1.789})\n assert candidate(x) == ['green', 'red', 'blue']\n", "\n x = Counter({'blue': \"b\", 'red': \"r\", 'green': \"g\"})\n assert candidate(x) == ['red', 'green', 'blue']\n"], "entry_point": "f_20950650", "intent": "reverse sort Counter `x` by values", "library": ["collections"]}
{"task_id": 20950650, "prompt": "def f_20950650(x):\n\treturn ", "suffix": "", "canonical_solution": "sorted(list(x.items()), key=lambda pair: pair[1], reverse=True)", "test_start": "\nfrom collections import Counter\n\ndef check(candidate):", "test": ["\n x = Counter({'blue': 1, 'red': 2, 'green': 3})\n assert candidate(x) == [('green', 3), ('red', 2), ('blue', 1)]\n", "\n x = Counter({'blue': 1.234, 'red': 1.35, 'green': 1.789})\n assert candidate(x) == [('green', 1.789), ('red', 1.35), ('blue', 1.234)]\n", "\n x = Counter({'blue': \"b\", 'red': \"r\", 'green': \"g\"})\n assert candidate(x) == [('red', \"r\"), ('green', \"g\"), ('blue', \"b\")]\n"], "entry_point": "f_20950650", "intent": "reverse sort counter `x` by value", "library": ["collections"]}
{"task_id": 9775297, "prompt": "def f_9775297(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, 3], [4, 5, 6]])\n b = np.array([[9, 8, 7], [6, 5, 4]])\n assert np.array_equal(candidate(a, b), np.array([[1, 2, 3], [4, 5, 6], [9, 8, 7], [6, 5, 4]]))\n", "\n a = np.array([[1, 2.45, 3], [4, 0.55, 612]])\n b = np.array([[988, 8, 7], [6, 512, 4]])\n assert np.array_equal(candidate(a, b), np.array([[1, 2.45, 3], [4, 0.55, 612], [988, 8, 7], [6, 512, 4]]))\n"], "entry_point": "f_9775297", "intent": "append a numpy array 'b' to a numpy array 'a'", "library": ["numpy"]}
{"task_id": 21887754, "prompt": "def f_21887754(a, b):\n\treturn ", "suffix": "", "canonical_solution": "np.concatenate((a, b), axis=0)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a = np.array([[1, 5, 9], [2, 6, 10]])\n b = np.array([[3, 7, 11], [4, 8, 12]])\n assert np.array_equal(candidate(a, b), np.array([[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]))\n", "\n a = np.array([[1, 2.45, 3], [4, 0.55, 612]])\n b = np.array([[988, 8, 7], [6, 512, 4]])\n assert np.array_equal(candidate(a, b), np.array([[1, 2.45, 3], [4, 0.55, 612], [988, 8, 7], [6, 512, 4]]))\n"], "entry_point": "f_21887754", "intent": "numpy concatenate two arrays `a` and `b` along the first axis", "library": ["numpy"]}
{"task_id": 21887754, "prompt": "def f_21887754(a, b):\n\treturn ", "suffix": "", "canonical_solution": "np.concatenate((a, b), axis=1)", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a = np.array([[1, 5, 9], [2, 6, 10]])\n b = np.array([[3, 7, 11], [4, 8, 12]])\n assert np.array_equal(candidate(a, b), np.array([[1, 5, 9, 3, 7, 11], [2, 6, 10, 4, 8, 12]]))\n", "\n a = np.array([[1, 2.45, 3], [4, 0.55, 612]])\n b = np.array([[988, 8, 7], [6, 512, 4]])\n assert np.array_equal(candidate(a, b), np.array([[1, 2.45, 3, 988, 8, 7], [4, 0.55, 612, 6, 512, 4]]))\n"], "entry_point": "f_21887754", "intent": "numpy concatenate two arrays `a` and `b` along the second axis", "library": ["numpy"]}
{"task_id": 21887754, "prompt": "def f_21887754(a, b):\n\treturn ", "suffix": "", "canonical_solution": "np.r_[(a[None, :], b[None, :])]", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a = np.array([[1, 5, 9], [2, 6, 10]])\n b = np.array([[3, 7, 11], [4, 8, 12]])\n assert np.array_equal(candidate(a, b), np.array([[[1, 5, 9], [2, 6, 10]], [[3, 7, 11], [4, 8, 12]]]))\n", "\n a = np.array([[1, 2.45, 3], [4, 0.55, 612]])\n b = np.array([[988, 8, 7], [6, 512, 4]])\n assert np.array_equal(candidate(a, b), np.array([[[1, 2.45, 3], [4, 0.55, 612]], [[988, 8 , 7], [6, 512, 4]]]))\n"], "entry_point": "f_21887754", "intent": "numpy concatenate two arrays `a` and `b` along the first axis", "library": ["numpy"]}
{"task_id": 21887754, "prompt": "def f_21887754(a, b):\n\treturn ", "suffix": "", "canonical_solution": "np.array((a, b))", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n a = np.array([[1, 5, 9], [2, 6, 10]])\n b = np.array([[3, 7, 11], [4, 8, 12]])\n assert np.array_equal(candidate(a, b), np.array([[[1, 5, 9], [2, 6, 10]], [[3, 7, 11], [4, 8, 12]]]))\n", "\n a = np.array([[1, 2.45, 3], [4, 0.55, 612]])\n b = np.array([[988, 8, 7], [6, 512, 4]])\n assert np.array_equal(candidate(a, b), np.array([[[1, 2.45, 3], [4, 0.55, 612]], [[988, 8 , 7], [6, 512, 4]]]))\n"], "entry_point": "f_21887754", "intent": "numpy concatenate two arrays `a` and `b` along the first axis", "library": ["numpy"]}
{"task_id": 2805231, "prompt": "def f_2805231():\n\treturn ", "suffix": "", "canonical_solution": "socket.getaddrinfo('google.com', 80)", "test_start": "\nimport socket\n\ndef check(candidate):", "test": ["\n res = candidate()\n assert all([(add[4][1] == 80) for add in res])\n"], "entry_point": "f_2805231", "intent": "fetch address information for host 'google.com' ion port 80", "library": ["socket"]}
{"task_id": 17552997, "prompt": "def f_17552997(df):\n\treturn ", "suffix": "", "canonical_solution": "df.xs('sat', level='day', drop_level=False)", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df = pd.DataFrame({'year':[2008,2008,2008,2008,2009,2009,2009,2009], \n 'flavour':['strawberry','strawberry','banana','banana',\n 'strawberry','strawberry','banana','banana'],\n 'day':['sat','sun','sat','sun','sat','sun','sat','sun'],\n 'sales':[10,12,22,23,11,13,23,24]})\n df = df.set_index(['year','flavour','day'])\n assert candidate(df).to_dict() == {'sales': {(2008, 'strawberry', 'sat'): 10, (2008, 'banana', 'sat'): 22, (2009, 'strawberry', 'sat'): 11, (2009, 'banana', 'sat'): 23}}\n"], "entry_point": "f_17552997", "intent": "add a column 'day' with value 'sat' to dataframe `df`", "library": ["pandas"]}
{"task_id": 4356842, "prompt": "def f_4356842():\n\treturn ", "suffix": "", "canonical_solution": "HttpResponse('Unauthorized', status=401)", "test_start": "\nfrom django.http import HttpResponse\nfrom django.conf import settings\n\nif not settings.configured:\n settings.configure(DEBUG=True)\n\ndef check(candidate):", "test": ["\n assert candidate().status_code == 401\n"], "entry_point": "f_4356842", "intent": "return a 401 unauthorized in django", "library": ["django"]}
{"task_id": 13598363, "prompt": "def f_13598363():\n\treturn ", "suffix": "", "canonical_solution": "Flask('test', template_folder='wherever')", "test_start": "\nfrom flask import Flask\n\ndef check(candidate):", "test": ["\n __name__ == \"test\"\n assert candidate().template_folder == \"wherever\"\n"], "entry_point": "f_13598363", "intent": "Flask set folder 'wherever' as the default template folder", "library": ["flask"]}
{"task_id": 3398589, "prompt": "def f_3398589(c2):\n\t", "suffix": "\n\treturn c2", "canonical_solution": "c2.sort(key=lambda row: row[2])", "test_start": "\ndef check(candidate):", "test": ["\n c2 = [[14, 25, 46], [1, 22, 53], [7, 8, 9]]\n candidate(c2)\n assert c2[0] == [7,8,9]\n", "\n c2 = [[14.343, 25.24, 46], [1, 22, 53.45], [7, 8.65, 9]]\n candidate(c2)\n assert c2[0] == [7,8.65,9]\n"], "entry_point": "f_3398589", "intent": "sort a list of lists 'c2' such that third row comes first", "library": []}
{"task_id": 3398589, "prompt": "def f_3398589(c2):\n\t", "suffix": "\n\treturn c2", "canonical_solution": "c2.sort(key=lambda row: (row[2], row[1], row[0]))", "test_start": "\ndef check(candidate):", "test": ["\n c2 = [[14, 25, 46], [1, 22, 53], [7, 8, 9]]\n candidate(c2)\n assert c2[0] == [7,8,9]\n", "\n c2 = [[14.343, 25.24, 46], [1, 22, 53.45], [7, 8.65, 9]]\n candidate(c2)\n assert c2[0] == [7,8.65,9]\n"], "entry_point": "f_3398589", "intent": "sort a list of lists 'c2' in reversed row order", "library": []}
{"task_id": 3398589, "prompt": "def f_3398589(c2):\n\t", "suffix": "\n\treturn c2", "canonical_solution": "c2.sort(key=lambda row: (row[2], row[1]))", "test_start": "\ndef check(candidate):", "test": ["\n c2 = [[14, 25, 46], [1, 22, 53], [7, 8, 9]]\n candidate(c2)\n assert c2[0] == [7,8,9]\n", "\n c2 = [[14.343, 25.24, 46], [1, 22, 53.45], [7, 8.65, 9]]\n candidate(c2)\n assert c2[0] == [7,8.65,9]\n"], "entry_point": "f_3398589", "intent": "Sorting a list of lists `c2`, each by the third and second row", "library": []}
{"task_id": 10960463, "prompt": "def f_10960463():\n\treturn ", "suffix": "", "canonical_solution": "matplotlib.rc('font', **{'sans-serif': 'Arial', 'family': 'sans-serif'})", "test_start": "\nimport matplotlib\n\ndef check(candidate):", "test": ["\n try:\n candidate()\n except:\n assert False\n"], "entry_point": "f_10960463", "intent": "set font `Arial` to display non-ascii characters in matplotlib", "library": ["matplotlib"]}
{"task_id": 20576618, "prompt": "def f_20576618(df):\n\treturn ", "suffix": "", "canonical_solution": "df['date'].apply(lambda x: x.toordinal())", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame(\n {\n \"group\": [\"A\", \"A\", \"A\", \"A\", \"A\"],\n \"date\": pd.to_datetime([\"2020-01-02\", \"2020-01-13\", \"2020-02-01\", \"2020-02-23\", \"2020-03-05\"]),\n \"value\": [10, 20, 16, 31, 56],\n }) \n data_series = candidate(df).tolist()\n assert data_series[1] == 737437\n", "\n df = pd.DataFrame(\n {\n \"group\": [\"A\", \"A\", \"A\", \"A\", \"A\"],\n \"date\": pd.to_datetime([\"2020-01-02\", \"2020-01-13\", \"2020-02-01\", \"2020-02-23\", \"2020-03-05\"]),\n \"value\": [10, 20, 16, 31, 56],\n }) \n data_series = candidate(df).tolist()\n assert data_series[1] == 737437\n"], "entry_point": "f_20576618", "intent": "Convert DateTime column 'date' of pandas dataframe 'df' to ordinal", "library": ["pandas"]}
{"task_id": 31793195, "prompt": "def f_31793195(df):\n\treturn ", "suffix": "", "canonical_solution": "df.index.get_loc('bob')", "test_start": "\nimport pandas as pd\nimport numpy as np\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame(data=np.asarray([[1,2,3],[4,5,6],[7,8,9]]), index=['alice', 'bob', 'charlie'])\n index = candidate(df)\n assert index == 1\n"], "entry_point": "f_31793195", "intent": "Get the integer location of a key `bob` in a pandas data frame `df`", "library": ["numpy", "pandas"]}
{"task_id": 10487278, "prompt": "def f_10487278(my_dict):\n\t", "suffix": "\n\treturn my_dict", "canonical_solution": "my_dict.update({'third_key': 1})", "test_start": "\ndef check(candidate):", "test": ["\n my_dict = {'a':1, 'b':2}\n assert candidate(my_dict) == {'a':1, 'b':2, 'third_key': 1}\n", "\n my_dict = {'c':1, 'd':2}\n assert candidate(my_dict) == {'c':1, 'd':2, 'third_key': 1}\n"], "entry_point": "f_10487278", "intent": "add an item with key 'third_key' and value 1 to an dictionary `my_dict`", "library": []}
{"task_id": 10487278, "prompt": "def f_10487278():\n\t", "suffix": "\n\treturn my_list", "canonical_solution": "my_list = []", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == []\n"], "entry_point": "f_10487278", "intent": "declare an array `my_list`", "library": []}
{"task_id": 10487278, "prompt": "def f_10487278(my_list):\n\t", "suffix": "\n\treturn my_list", "canonical_solution": "my_list.append(12)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2]) == [1, 2, 12] \n", "\n assert candidate([5,6]) == [5, 6, 12]\n"], "entry_point": "f_10487278", "intent": "Insert item `12` to a list `my_list`", "library": []}
{"task_id": 10155684, "prompt": "def f_10155684(myList):\n\t", "suffix": "\n\treturn myList", "canonical_solution": "myList.insert(0, 'wuggah')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2]) == ['wuggah', 1, 2]\n", "\n assert candidate([]) == ['wuggah'] \n"], "entry_point": "f_10155684", "intent": "add an entry 'wuggah' at the beginning of list `myList`", "library": []}
{"task_id": 3519125, "prompt": "def f_3519125(hex_str):\n\treturn ", "suffix": "", "canonical_solution": "bytes.fromhex(hex_str.replace('\\\\x', ''))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"\\\\xF3\\\\xBE\\\\x80\\\\x80\") == b'\\xf3\\xbe\\x80\\x80'\n"], "entry_point": "f_3519125", "intent": "convert a hex-string representation `hex_str` to actual bytes", "library": []}
{"task_id": 40144769, "prompt": "def f_40144769(df):\n\treturn ", "suffix": "", "canonical_solution": "df[df.columns[-1]]", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[1, 2, 3],[4,5,6]], columns=[\"a\", \"b\", \"c\"])\n assert candidate(df).tolist() == [3,6]\n", "\n df = pd.DataFrame([[\"Hello\", \"world!\"],[\"Hi\", \"world!\"]], columns=[\"a\", \"b\"])\n assert candidate(df).tolist() == [\"world!\", \"world!\"]\n"], "entry_point": "f_40144769", "intent": "select the last column of dataframe `df`", "library": ["pandas"]}
{"task_id": 30787901, "prompt": "def f_30787901(df):\n\treturn ", "suffix": "", "canonical_solution": "df.loc[df['Letters'] == 'C', 'Letters'].values[0]", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([[\"a\", 1],[\"C\", 6]], columns=[\"Letters\", \"Numbers\"])\n assert candidate(df) == 'C'\n", "\n df = pd.DataFrame([[None, 1],[\"C\", 789]], columns=[\"Letters\", \"Names\"])\n assert candidate(df) == 'C'\n"], "entry_point": "f_30787901", "intent": "get the first value from dataframe `df` where column 'Letters' is equal to 'C'", "library": ["pandas"]}
{"task_id": 18730044, "prompt": "def f_18730044():\n\treturn ", "suffix": "", "canonical_solution": "np.column_stack(([1, 2, 3], [4, 5, 6]))", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n assert np.all(candidate() == np.array([[1, 4], [2, 5], [3, 6]]))\n"], "entry_point": "f_18730044", "intent": "converting two lists `[1, 2, 3]` and `[4, 5, 6]` into a matrix", "library": ["numpy"]}
{"task_id": 402504, "prompt": "def f_402504(i):\n\treturn ", "suffix": "", "canonical_solution": "type(i)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"hello\") is str\n", "\n assert candidate(123) is int\n", "\n assert candidate(\"123\") is str\n", "\n assert candidate(123.4) is float\n"], "entry_point": "f_402504", "intent": "get the type of `i`", "library": []}
{"task_id": 402504, "prompt": "def f_402504(v):\n\treturn ", "suffix": "", "canonical_solution": "type(v)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"hello\") is str\n", "\n assert candidate(123) is int\n", "\n assert candidate(\"123\") is str\n", "\n assert candidate(123.4) is float\n"], "entry_point": "f_402504", "intent": "determine the type of variable `v`", "library": []}
{"task_id": 402504, "prompt": "def f_402504(v):\n\treturn ", "suffix": "", "canonical_solution": "type(v)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"hello\") is str\n", "\n assert candidate(123) is int\n", "\n assert candidate(\"123\") is str\n", "\n assert candidate(123.4) is float\n"], "entry_point": "f_402504", "intent": "determine the type of variable `v`", "library": []}
{"task_id": 402504, "prompt": "def f_402504(variable_name):\n\treturn ", "suffix": "", "canonical_solution": "type(variable_name)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"hello\") is str\n", "\n assert candidate(123) is int\n", "\n assert candidate(\"123\") is str\n", "\n assert candidate(123.4) is float\n"], "entry_point": "f_402504", "intent": "get the type of variable `variable_name`", "library": []}
{"task_id": 2300756, "prompt": "def f_2300756(g):\n\treturn ", "suffix": "", "canonical_solution": "next(itertools.islice(g, 5, 5 + 1))", "test_start": "\nimport itertools\n\ndef check(candidate):", "test": ["\n test = [1, 2, 3, 4, 5, 6, 7]\n assert(candidate(test) == 6)\n"], "entry_point": "f_2300756", "intent": "get the 5th item of a generator `g`", "library": ["itertools"]}
{"task_id": 20056548, "prompt": "def f_20056548(word):\n\treturn ", "suffix": "", "canonical_solution": "'\"{}\"'.format(word)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('Some Random Word') == '\"Some Random Word\"'\n"], "entry_point": "f_20056548", "intent": "return a string `word` with string format", "library": []}
{"task_id": 8546245, "prompt": "def f_8546245(list):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\" \"\"\".join(list)", "test_start": "\ndef check(candidate):", "test": ["\n test = ['hello', 'good', 'morning']\n assert candidate(test) == \"hello good morning\"\n"], "entry_point": "f_8546245", "intent": "join a list of strings `list` using a space ' '", "library": []}
{"task_id": 2276416, "prompt": "def f_2276416():\n\t", "suffix": "\n\treturn y", "canonical_solution": "y = [[] for n in range(2)]", "test_start": "\ndef check(candidate):", "test": ["\n assert(candidate() == [[], []])\n"], "entry_point": "f_2276416", "intent": "create list `y` containing two empty lists", "library": []}
{"task_id": 3925614, "prompt": "def f_3925614(filename):\n\t", "suffix": "\n\treturn data", "canonical_solution": "data = [line.strip() for line in open(filename, 'r')]", "test_start": "\ndef check(candidate):", "test": ["\n file1 = open(\"myfile.txt\", \"w\")\n L = [\"This is Delhi \\n\", \"This is Paris \\n\", \"This is London \\n\"]\n file1.writelines(L)\n file1.close()\n assert candidate('myfile.txt') == ['This is Delhi', 'This is Paris', 'This is London']\n"], "entry_point": "f_3925614", "intent": "read a file `filename` into a list `data`", "library": []}
{"task_id": 22187233, "prompt": "def f_22187233():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"\"\"\".join([char for char in 'it is icy' if char != 'i'])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 't s cy'\n"], "entry_point": "f_22187233", "intent": "delete all occurrences of character 'i' in string 'it is icy'", "library": []}
{"task_id": 22187233, "prompt": "def f_22187233():\n\treturn ", "suffix": "", "canonical_solution": "re.sub('i', '', 'it is icy')", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate() == 't s cy'\n"], "entry_point": "f_22187233", "intent": "delete all instances of a character 'i' in a string 'it is icy'", "library": ["re"]}
{"task_id": 22187233, "prompt": "def f_22187233():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"it is icy\"\"\".replace('i', '')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 't s cy'\n"], "entry_point": "f_22187233", "intent": "delete all characters \"i\" in string \"it is icy\"", "library": []}
{"task_id": 13413590, "prompt": "def f_13413590(df):\n\treturn ", "suffix": "", "canonical_solution": "df.dropna(subset=[1])", "test_start": "\nimport numpy as np\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n data = {0:[3.0, 4.0, 2.0], 1:[2.0, 3.0, np.nan], 2:[np.nan, 3.0, np.nan]}\n df = pd.DataFrame(data)\n d = {0:[3.0, 4.0], 1:[2.0, 3.0], 2:[np.nan, 3.0]}\n res = pd.DataFrame(d)\n assert candidate(df).equals(res)\n"], "entry_point": "f_13413590", "intent": "Drop rows of pandas dataframe `df` having NaN in column at index \"1\"", "library": ["numpy", "pandas"]}
{"task_id": 598398, "prompt": "def f_598398(myList):\n\treturn ", "suffix": "", "canonical_solution": "[x for x in myList if x.n == 30]", "test_start": "\nimport numpy as np\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n class Data: \n def __init__(self, a, n): \n self.a = a\n self.n = n\n \n myList = [Data(i, 10*(i%4)) for i in range(20)]\n assert candidate(myList) == [myList[i] for i in [3, 7, 11, 15, 19]]\n"], "entry_point": "f_598398", "intent": "get elements from list `myList`, that have a field `n` value 30", "library": ["numpy", "pandas"]}
{"task_id": 10351772, "prompt": "def f_10351772(intstringlist):\n\t", "suffix": "\n\treturn nums", "canonical_solution": "nums = [int(x) for x in intstringlist]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['1', '2', '3', '4', '5']) == [1, 2, 3, 4, 5]\n", "\n assert candidate(['001', '200', '3', '4', '5']) == [1, 200, 3, 4, 5]\n"], "entry_point": "f_10351772", "intent": "converting list of strings `intstringlist` to list of integer `nums`", "library": []}
{"task_id": 493386, "prompt": "def f_493386():\n\treturn ", "suffix": "", "canonical_solution": "sys.stdout.write('.')", "test_start": "\nimport sys\n\ndef check(candidate):", "test": ["\n assert candidate() == 1\n"], "entry_point": "f_493386", "intent": "print \".\" without newline", "library": ["sys"]}
{"task_id": 6569528, "prompt": "def f_6569528():\n\treturn ", "suffix": "", "canonical_solution": "int(round(2.52 * 100))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 252\n"], "entry_point": "f_6569528", "intent": "round off the float that is the product of `2.52 * 100` and convert it to an int", "library": []}
{"task_id": 3964681, "prompt": "def f_3964681():\n\t", "suffix": "\n\treturn files", "canonical_solution": "\n\tos.chdir('/mydir')\n\tfiles = [] \n\tfor file in glob.glob('*.txt'):\n\t\tfiles.append(file)\n", "test_start": "\nimport os\nimport glob\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n samples = ['abc.txt']\n os.chdir = Mock()\n glob.glob = Mock(return_value = samples)\n assert candidate() == samples\n"], "entry_point": "f_3964681", "intent": "Find all files `files` in directory '/mydir' with extension '.txt'", "library": ["glob", "os"]}
{"task_id": 3964681, "prompt": "def f_3964681():\n\treturn ", "suffix": "", "canonical_solution": "[file for file in os.listdir('/mydir') if file.endswith('.txt')]", "test_start": "\nimport os\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n samples = ['abc.txt', 'f.csv']\n os.listdir = Mock(return_value = samples)\n assert candidate() == ['abc.txt']\n"], "entry_point": "f_3964681", "intent": "Find all files in directory \"/mydir\" with extension \".txt\"", "library": ["os"]}
{"task_id": 3964681, "prompt": "def f_3964681():\n\treturn ", "suffix": "", "canonical_solution": "[file for (root, dirs, files) in os.walk('/mydir') for file in files if file.endswith('.txt')]", "test_start": "\nimport os\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n name = '/mydir'\n samples = [(name, [], ['abc.txt', 'f.csv'])]\n os.walk = Mock(return_value = samples)\n assert candidate() == ['abc.txt']\n"], "entry_point": "f_3964681", "intent": "Find all files in directory \"/mydir\" with extension \".txt\"", "library": ["os"]}
{"task_id": 20865487, "prompt": "def f_20865487(df):\n\treturn ", "suffix": "", "canonical_solution": "df.plot(legend=False)", "test_start": "\nimport os \nimport pandas as pd\n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([1, 2, 3, 4, 5], columns = ['Vals'])\n res = candidate(df)\n assert 'AxesSubplot' in str(type(res))\n assert res.legend_ is None\n"], "entry_point": "f_20865487", "intent": "plot dataframe `df` without a legend", "library": ["os", "pandas"]}
{"task_id": 13368659, "prompt": "def f_13368659():\n\treturn ", "suffix": "", "canonical_solution": "['192.168.%d.%d'%(i, j) for i in range(256) for j in range(256)]", "test_start": "\ndef check(candidate):", "test": ["\n addrs = candidate()\n assert len(addrs) == 256*256\n assert addrs == [f'192.168.{i}.{j}' for i in range(256) for j in range(256)]\n"], "entry_point": "f_13368659", "intent": "loop through the IP address range \"192.168.x.x\"", "library": []}
{"task_id": 4065737, "prompt": "def f_4065737(x):\n\treturn ", "suffix": "", "canonical_solution": "sum(1 << i for i, b in enumerate(x) if b)", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([1,2,3]) == 7\n", "\n assert candidate([1,2,None,3,None]) == 11\n"], "entry_point": "f_4065737", "intent": "Sum the corresponding decimal values for binary values of each boolean element in list `x`", "library": []}
{"task_id": 8691311, "prompt": "def f_8691311(line1, line2, line3, target):\n\t", "suffix": "\n\treturn ", "canonical_solution": "target.write('%r\\n%r\\n%r\\n' % (line1, line2, line3))", "test_start": "\ndef check(candidate):", "test": ["\n file_name = 'abc.txt'\n lines = ['fgh', 'ijk', 'mnop']\n f = open(file_name, 'a')\n candidate(lines[0], lines[1], lines[2], f)\n f.close()\n with open(file_name, 'r') as f:\n f_lines = f.readlines()\n for i in range (0, len(lines)):\n assert lines[i] in f_lines[i]\n"], "entry_point": "f_8691311", "intent": "write multiple strings `line1`, `line2` and `line3` in one line in a file `target`", "library": []}
{"task_id": 10632111, "prompt": "def f_10632111(data):\n\treturn ", "suffix": "", "canonical_solution": "[y for x in data for y in (x if isinstance(x, list) else [x])]", "test_start": "\ndef check(candidate):", "test": ["\n data = [[1, 2], [3]]\n assert candidate(data) == [1, 2, 3]\n", "\n data = [[1, 2], [3], []]\n assert candidate(data) == [1, 2, 3]\n", "\n data = [1,2,3]\n assert candidate(data) == [1, 2, 3]\n"], "entry_point": "f_10632111", "intent": "Convert list of lists `data` into a flat list", "library": []}
{"task_id": 15392730, "prompt": "def f_15392730():\n\treturn ", "suffix": "", "canonical_solution": "'foo\\nbar'.encode('unicode_escape')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == b'foo\\\\nbar'\n"], "entry_point": "f_15392730", "intent": "Print new line character as `\\n` in a string `foo\\nbar`", "library": []}
{"task_id": 1010961, "prompt": "def f_1010961(s):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"\"\"\".join(s.rsplit(',', 1))", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('abc, def, klm') == 'abc, def klm'\n"], "entry_point": "f_1010961", "intent": "remove last comma character ',' in string `s`", "library": []}
{"task_id": 23855976, "prompt": "def f_23855976(x):\n\treturn ", "suffix": "", "canonical_solution": "(x[1:] + x[:-1]) / 2", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n x = np.array([ 1230., 1230., 1227., 1235., 1217., 1153., 1170.])\n xm = np.array([1230. , 1228.5, 1231. , 1226. , 1185. , 1161.5])\n assert np.array_equal(candidate(x), xm)\n"], "entry_point": "f_23855976", "intent": "calculate the mean of each element in array `x` with the element previous to it", "library": ["numpy"]}
{"task_id": 23855976, "prompt": "def f_23855976(x):\n\treturn ", "suffix": "", "canonical_solution": "x[:-1] + (x[1:] - x[:-1]) / 2", "test_start": "\nimport numpy as np\n\ndef check(candidate):", "test": ["\n x = np.array([ 1230., 1230., 1227., 1235., 1217., 1153., 1170.])\n xm = np.array([1230. , 1228.5, 1231. , 1226. , 1185. , 1161.5])\n assert np.array_equal(candidate(x), xm)\n"], "entry_point": "f_23855976", "intent": "get an array of the mean of each two consecutive values in numpy array `x`", "library": ["numpy"]}
{"task_id": 6375343, "prompt": "def f_6375343():\n\t", "suffix": "\n\treturn arr", "canonical_solution": "arr = numpy.fromiter(codecs.open('new.txt', encoding='utf-8'), dtype='<U2')", "test_start": "\nimport numpy\nimport codecs\nimport numpy as np\n\ndef check(candidate):", "test": ["\n with open ('new.txt', 'a', encoding='utf-8') as f:\n f.write('\u091f')\n f.write('\u091c')\n arr = candidate()\n assert arr[0] == '\u091f\u091c'\n"], "entry_point": "f_6375343", "intent": "load data containing `utf-8` from file `new.txt` into numpy array `arr`", "library": ["codecs", "numpy"]}
{"task_id": 1547733, "prompt": "def f_1547733(l):\n\t", "suffix": "\n\treturn l", "canonical_solution": "l = sorted(l, key=itemgetter('time'), reverse=True)", "test_start": "\nfrom operator import itemgetter\n\ndef check(candidate):", "test": ["\n l = [ {'time':33}, {'time':11}, {'time':66} ]\n assert candidate(l) == [{'time':66}, {'time':33}, {'time':11}]\n"], "entry_point": "f_1547733", "intent": "reverse sort list of dicts `l` by value for key `time`", "library": ["operator"]}
{"task_id": 1547733, "prompt": "def f_1547733(l):\n\t", "suffix": "\n\treturn l", "canonical_solution": "l = sorted(l, key=lambda a: a['time'], reverse=True)", "test_start": "\ndef check(candidate):", "test": ["\n l = [ {'time':33}, {'time':11}, {'time':66} ]\n assert candidate(l) == [{'time':66}, {'time':33}, {'time':11}]\n"], "entry_point": "f_1547733", "intent": "Sort a list of dictionary `l` based on key `time` in descending order", "library": []}
{"task_id": 37080612, "prompt": "def f_37080612(df):\n\treturn ", "suffix": "", "canonical_solution": "df.loc[df[0].str.contains('(Hel|Just)')]", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n df = pd.DataFrame([['Hello', 'World'], ['Just', 'Wanted'], ['To', 'Say'], ['I\\'m', 'Tired']])\n df1 = candidate(df)\n assert df1[0][0] == 'Hello'\n assert df1[0][1] == 'Just'\n"], "entry_point": "f_37080612", "intent": "get rows of dataframe `df` that match regex '(Hel|Just)'", "library": ["pandas"]}
{"task_id": 14716342, "prompt": "def f_14716342(your_string):\n\treturn ", "suffix": "", "canonical_solution": "re.search('\\\\[(.*)\\\\]', your_string).group(1)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n assert candidate('[uranus]') == 'uranus'\n", "\n assert candidate('hello[world] !') == 'world'\n"], "entry_point": "f_14716342", "intent": "find the string in `your_string` between two special characters \"[\" and \"]\"", "library": ["re"]}
{"task_id": 18684076, "prompt": "def f_18684076():\n\treturn ", "suffix": "", "canonical_solution": "[d.strftime('%Y%m%d') for d in pandas.date_range('20130226', '20130302')]", "test_start": "\nimport pandas \n\ndef check(candidate):", "test": ["\n assert candidate() == ['20130226', '20130227', '20130228', '20130301', '20130302']\n"], "entry_point": "f_18684076", "intent": "create a list of date string in 'yyyymmdd' format with Python Pandas from '20130226' to '20130302'", "library": ["pandas"]}
{"task_id": 1666700, "prompt": "def f_1666700():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"The big brown fox is brown\"\"\".count('brown')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 2\n"], "entry_point": "f_1666700", "intent": "count number of times string 'brown' occurred in string 'The big brown fox is brown'", "library": []}
{"task_id": 18979111, "prompt": "def f_18979111(request_body):\n\treturn ", "suffix": "", "canonical_solution": "json.loads(request_body)", "test_start": "\nimport json \n\ndef check(candidate):", "test": ["\n x = \"\"\"{\n \"Name\": \"Jennifer Smith\",\n \"Contact Number\": 7867567898,\n \"Email\": \"jen123@gmail.com\",\n \"Hobbies\":[\"Reading\", \"Sketching\", \"Horse Riding\"]\n }\"\"\"\n assert candidate(x) == {'Hobbies': ['Reading', 'Sketching', 'Horse Riding'], 'Name': 'Jennifer Smith', 'Email': 'jen123@gmail.com', 'Contact Number': 7867567898}\n"], "entry_point": "f_18979111", "intent": "decode json string `request_body` to python dict", "library": ["json"]}
{"task_id": 7243750, "prompt": "def f_7243750(url, file_name):\n\treturn ", "suffix": "", "canonical_solution": "urllib.request.urlretrieve(url, file_name)", "test_start": "\nimport urllib \n\ndef check(candidate):", "test": ["\n file_name = 'g.html'\n candidate('https://asia.nikkei.com/Business/Tech/Semiconductors/U.S.-chip-tool-maker-Synopsys-expands-in-Vietnam-amid-China-tech-war', file_name)\n with open (file_name, 'r') as f:\n lines = f.readlines()\n if len(lines) == 0: assert False\n else: assert True\n"], "entry_point": "f_7243750", "intent": "download the file from url `url` and save it under file `file_name`", "library": ["urllib"]}
{"task_id": 743806, "prompt": "def f_743806(text):\n\treturn ", "suffix": "", "canonical_solution": "text.split()", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('The quick brown fox') == ['The', 'quick', 'brown', 'fox']\n", "\n assert candidate('hello!') == ['hello!']\n", "\n assert candidate('hello world !') == ['hello', 'world', '!']\n"], "entry_point": "f_743806", "intent": "split string `text` by space", "library": []}
{"task_id": 743806, "prompt": "def f_743806(text):\n\treturn ", "suffix": "", "canonical_solution": "text.split(',')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('The quick brown fox') == ['The quick brown fox']\n", "\n assert candidate('The,quick,brown,fox') == ['The', 'quick', 'brown', 'fox']\n"], "entry_point": "f_743806", "intent": "split string `text` by \",\"", "library": []}
{"task_id": 743806, "prompt": "def f_743806(line):\n\treturn ", "suffix": "", "canonical_solution": "line.split()", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('The quick brown fox') == ['The', 'quick', 'brown', 'fox']\n"], "entry_point": "f_743806", "intent": "Split string `line` into a list by whitespace", "library": []}
{"task_id": 35044115, "prompt": "def f_35044115(s):\n\treturn ", "suffix": "", "canonical_solution": "[re.sub('(?<!\\\\d)\\\\.(?!\\\\d)', ' ', i) for i in s]", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate('h.j.k') == ['h', ' ', 'j', ' ', 'k']\n"], "entry_point": "f_35044115", "intent": "replace dot characters '.' associated with ascii letters in list `s` with space ' '", "library": ["re"]}
{"task_id": 38388799, "prompt": "def f_38388799(list_of_strings):\n\treturn ", "suffix": "", "canonical_solution": "sorted(list_of_strings, key=lambda s: s.split(',')[1])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(['parrot, medicine', 'abott, kangaroo', 'sriracha, coriander', 'phone, bottle']) == ['phone, bottle', 'sriracha, coriander', 'abott, kangaroo', 'parrot, medicine']\n", "\n assert candidate(['abott, kangaroo', 'parrot, medicine', 'sriracha, coriander', 'phone, bottle']) == ['phone, bottle', 'sriracha, coriander', 'abott, kangaroo', 'parrot, medicine']\n"], "entry_point": "f_38388799", "intent": "sort list `list_of_strings` based on second index of each string `s`", "library": []}
{"task_id": 37004138, "prompt": "def f_37004138(lst):\n\treturn ", "suffix": "", "canonical_solution": "[element for element in lst if isinstance(element, int)]", "test_start": "\ndef check(candidate):", "test": ["\n lst = [1, \"hello\", \"string\", 2, 4.46]\n assert candidate(lst) == [1, 2]\n", "\n lst = [\"hello\", \"string\"]\n assert candidate(lst) == []\n"], "entry_point": "f_37004138", "intent": "eliminate non-integer items from list `lst`", "library": []}
{"task_id": 37004138, "prompt": "def f_37004138(lst):\n\treturn ", "suffix": "", "canonical_solution": "[element for element in lst if not isinstance(element, str)]", "test_start": "\ndef check(candidate):", "test": ["\n lst = [1, \"hello\", \"string\", 2, 4.46]\n assert candidate(lst) == [1, 2, 4.46]\n", "\n lst = [\"hello\", \"string\"]\n assert candidate(lst) == []\n"], "entry_point": "f_37004138", "intent": "get all the elements except strings from the list 'lst'.", "library": []}
{"task_id": 72899, "prompt": "def f_72899(list_to_be_sorted):\n\treturn ", "suffix": "", "canonical_solution": "sorted(list_to_be_sorted, key=lambda k: k['name'])", "test_start": "\ndef check(candidate):", "test": ["\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Bart', 'age': 10}, {'name': 'Homer', 'age': 39}]\n", "\n list_to_be_sorted = [{'name': 'ABCD'}, {'name': 'AABCD'}]\n assert candidate(list_to_be_sorted) == [{'name': 'AABCD'}, {'name': 'ABCD'}]\n"], "entry_point": "f_72899", "intent": "Sort a list of dictionaries `list_to_be_sorted` by the value of the dictionary key `name`", "library": []}
{"task_id": 72899, "prompt": "def f_72899(l):\n\treturn ", "suffix": "", "canonical_solution": "sorted(l, key=itemgetter('name'), reverse=True)", "test_start": "\nfrom operator import itemgetter\n\ndef check(candidate):", "test": ["\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n", "\n list_to_be_sorted = [{'name': 'ABCD'}, {'name': 'AABCD'}]\n assert candidate(list_to_be_sorted) == [{'name': 'ABCD'}, {'name': 'AABCD'}]\n"], "entry_point": "f_72899", "intent": "sort a list of dictionaries `l` by values in key `name` in descending order", "library": ["operator"]}
{"task_id": 72899, "prompt": "def f_72899(list_of_dicts):\n\t", "suffix": "\n\treturn list_of_dicts", "canonical_solution": "list_of_dicts.sort(key=operator.itemgetter('name'))", "test_start": "\nimport operator\n\ndef check(candidate):", "test": ["\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Bart', 'age': 10}, {'name': 'Homer', 'age': 39}]\n", "\n list_to_be_sorted = [{'name': 'ABCD'}, {'name': 'AABCD'}]\n assert candidate(list_to_be_sorted) == [{'name': 'AABCD'}, {'name': 'ABCD'}]\n"], "entry_point": "f_72899", "intent": "sort a list of dictionaries `list_of_dicts` by `name` values of the dictionary", "library": ["operator"]}
{"task_id": 72899, "prompt": "def f_72899(list_of_dicts):\n\t", "suffix": "\n\treturn list_of_dicts", "canonical_solution": "list_of_dicts.sort(key=operator.itemgetter('age'))", "test_start": "\nimport operator\n\ndef check(candidate):", "test": ["\n list_to_be_sorted = [{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]\n assert candidate(list_to_be_sorted) == [{'name': 'Bart', 'age': 10}, {'name': 'Homer', 'age': 39}]\n", "\n list_to_be_sorted = [{'name': 'ABCD', 'age': 10}, {'name': 'AABCD', 'age': 9}]\n assert candidate(list_to_be_sorted) == [{'name': 'AABCD', 'age': 9}, {'name': 'ABCD', 'age': 10}]\n"], "entry_point": "f_72899", "intent": "sort a list of dictionaries `list_of_dicts` by `age` values of the dictionary", "library": ["operator"]}
{"task_id": 36402748, "prompt": "def f_36402748(df):\n\treturn ", "suffix": "", "canonical_solution": "df.groupby('prots').sum().sort_values('scores', ascending=False)", "test_start": "\nimport pandas as pd \n\ndef check(candidate):", "test": ["\n COLUMN_NAMES = [\"chemicals\", \"prots\", \"scores\"]\n data = [[\"chemical1\", \"prot1\", 100],[\"chemical2\", \"prot2\", 50],[\"chemical3\", \"prot1\", 120]]\n df = pd.DataFrame(data, columns = COLUMN_NAMES)\n assert candidate(df).to_dict() == {'scores': {'prot1': 220, 'prot2': 50}}\n"], "entry_point": "f_36402748", "intent": "sort a Dataframe `df` by the total ocurrences in a column 'scores' group by 'prots'", "library": ["pandas"]}
{"task_id": 29881993, "prompt": "def f_29881993(trans):\n\treturn ", "suffix": "", "canonical_solution": "\"\"\",\"\"\".join(trans['category'])", "test_start": "\ndef check(candidate):", "test": ["\n trans = {'category':[\"hello\", \"world\",\"test\"], 'dummy_key':[\"dummy_val\"]}\n assert candidate(trans) == \"hello,world,test\"\n"], "entry_point": "f_29881993", "intent": "join together with \",\" elements inside a list indexed with 'category' within a dictionary `trans`", "library": []}
{"task_id": 34158494, "prompt": "def f_34158494():\n\treturn ", "suffix": "", "canonical_solution": "\"\"\"\"\"\".join(['A', 'B', 'C', 'D'])", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate() == 'ABCD'\n"], "entry_point": "f_34158494", "intent": "concatenate array of strings `['A', 'B', 'C', 'D']` into a string", "library": []}
{"task_id": 12666897, "prompt": "def f_12666897(sents):\n\treturn ", "suffix": "", "canonical_solution": "[x for x in sents if not x.startswith('@$\\t') and not x.startswith('#')]", "test_start": "\ndef check(candidate):", "test": ["\n sents = [\"@$\tabcd\", \"#453923\", \"abcd\", \"hello\", \"1\"]\n assert candidate(sents) == [\"abcd\", \"hello\", \"1\"]\n", "\n sents = [\"@$\tabcd\", \"@$t453923\", \"abcd\", \"hello\", \"1\"]\n assert candidate(sents) == [\"@$t453923\", \"abcd\", \"hello\", \"1\"]\n", "\n sents = [\"#tabcd\", \"##453923\", \"abcd\", \"hello\", \"1\"]\n assert candidate(sents) == [\"abcd\", \"hello\", \"1\"] \n"], "entry_point": "f_12666897", "intent": "Remove all strings from a list a strings `sents` where the values starts with `@$\\t` or `#`", "library": []}
{"task_id": 5944630, "prompt": "def f_5944630(list):\n\t", "suffix": "\n\treturn list", "canonical_solution": "list.sort(key=lambda item: (item['points'], item['time']))", "test_start": "\ndef check(candidate):", "test": ["\n list = [\n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':50,'time': '0:03:00'},\n {'name':'TEST','points':20,'time': '0:03:00'}\n ]\n assert candidate(list) == [\n {'name':'TEST','points':20,'time': '0:03:00'}, \n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':50,'time': '0:03:00'}\n ]\n", "\n list = [\n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':30,'time': '0:03:00'},\n {'name':'TEST','points':30,'time': '0:01:01'}\n ]\n assert candidate(list) == [\n {'name':'TEST','points':30,'time': '0:01:01'},\n {'name':'JOHN', 'points' : 30, 'time' : '0:02:2'},\n {'name':'KARL','points':30,'time': '0:03:00'}\n ]\n"], "entry_point": "f_5944630", "intent": "sort a list of dictionary `list` first by key `points` and then by `time`", "library": []}
{"task_id": 7852855, "prompt": "def f_7852855():\n\treturn ", "suffix": "", "canonical_solution": "datetime.datetime(1970, 1, 1).second", "test_start": "\nimport time\nimport datetime\n\ndef check(candidate):", "test": ["\n assert candidate() == 0\n"], "entry_point": "f_7852855", "intent": "convert datetime object `(1970, 1, 1)` to seconds", "library": ["datetime", "time"]}
{"task_id": 2763750, "prompt": "def f_2763750():\n\treturn ", "suffix": "", "canonical_solution": "re.sub('(\\\\_a)?\\\\.([^\\\\.]*)$', '_suff.\\\\2', 'long.file.name.jpg')", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate() == 'long.file.name_suff.jpg'\n"], "entry_point": "f_2763750", "intent": "insert `_suff` before the file extension in `long.file.name.jpg` or replace `_a` with `suff` if it precedes the extension.", "library": ["re"]}
{"task_id": 6420361, "prompt": "def f_6420361(module):\n\t", "suffix": "\n\treturn ", "canonical_solution": "imp.reload(module)", "test_start": "\nimport imp\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n imp.reload = Mock()\n try:\n candidate('ads')\n assert True\n except:\n assert False\n"], "entry_point": "f_6420361", "intent": "reload a module `module`", "library": ["imp"]}
{"task_id": 19546911, "prompt": "def f_19546911(number):\n\treturn ", "suffix": "", "canonical_solution": "struct.unpack('H', struct.pack('h', number))", "test_start": "\nimport struct \n\ndef check(candidate):", "test": ["\n assert candidate(3) == (3,)\n"], "entry_point": "f_19546911", "intent": "Convert integer `number` into an unassigned integer", "library": ["struct"]}
{"task_id": 9746522, "prompt": "def f_9746522(numlist):\n\t", "suffix": "\n\treturn numlist", "canonical_solution": "numlist = [float(x) for x in numlist]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate([3, 4]) == [3.0, 4.0]\n"], "entry_point": "f_9746522", "intent": "convert int values in list `numlist` to float", "library": []}
{"task_id": 20107570, "prompt": "def f_20107570(df, filename):\n\t", "suffix": "\n\treturn ", "canonical_solution": "df.to_csv(filename, index=False)", "test_start": "\nimport pandas as pd\n\ndef check(candidate):", "test": ["\n file_name = 'a.csv'\n df = pd.DataFrame([1, 2, 3], columns = ['Vals'])\n candidate(df, file_name)\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert len(lines) == 4\n"], "entry_point": "f_20107570", "intent": "write dataframe `df`, excluding index, to a csv file `filename`", "library": ["pandas"]}
{"task_id": 8740353, "prompt": "def f_8740353(unescaped):\n\t", "suffix": "\n\treturn json_data", "canonical_solution": "json_data = json.loads(unescaped)", "test_start": "\nimport json \n\ndef check(candidate):", "test": ["\n x = \"\"\"{\n \"Name\": \"Jennifer Smith\",\n \"Contact Number\": 7867567898,\n \"Email\": \"jen123@gmail.com\",\n \"Hobbies\":[\"Reading\", \"Sketching\", \"Horse Riding\"]\n }\"\"\"\n assert candidate(x) == {'Hobbies': ['Reading', 'Sketching', 'Horse Riding'], 'Name': 'Jennifer Smith', 'Email': 'jen123@gmail.com', 'Contact Number': 7867567898}\n"], "entry_point": "f_8740353", "intent": "convert a urllib unquoted string `unescaped` to a json data `json_data`", "library": ["json"]}
{"task_id": 5891453, "prompt": "def f_5891453():\n\treturn ", "suffix": "", "canonical_solution": "[chr(i) for i in range(127)]", "test_start": "\ndef check(candidate):", "test": ["\n chars = candidate()\n assert len(chars) == 127\n assert chars == [chr(i) for i in range(127)]\n"], "entry_point": "f_5891453", "intent": "Create a list containing all ascii characters as its elements", "library": []}
{"task_id": 18367007, "prompt": "def f_18367007(newFileBytes, newFile):\n\t", "suffix": "\n\treturn ", "canonical_solution": "newFile.write(struct.pack('5B', *newFileBytes))", "test_start": "\nimport struct \n\ndef check(candidate):", "test": ["\n newFileBytes = [123, 3, 123, 100, 99]\n file_name = 'f.txt'\n newFile = open(file_name, 'wb')\n candidate(newFileBytes, newFile)\n newFile.close()\n with open (file_name, 'rb') as f:\n lines = f.readlines()\n assert lines == [b'{\u0003{dc']\n"], "entry_point": "f_18367007", "intent": "write `newFileBytes` to a binary file `newFile`", "library": ["struct"]}
{"task_id": 21805490, "prompt": "def f_21805490(string):\n\treturn ", "suffix": "", "canonical_solution": "re.sub('^[A-Z0-9]*(?![a-z])', '', string)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate(\"AASKH317298DIUANFProgramming is fun\") == \"Programming is fun\"\n"], "entry_point": "f_21805490", "intent": "python regex - check for a capital letter with a following lowercase in string `string`", "library": ["re"]}
{"task_id": 16125229, "prompt": "def f_16125229(dict):\n\treturn ", "suffix": "", "canonical_solution": "list(dict.keys())[-1]", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate({'t': 1, 'r': 2}) == 'r'\n", "\n assert candidate({'c': 1, 'b': 2, 'a': 1}) == 'a'\n"], "entry_point": "f_16125229", "intent": "get the last key of dictionary `dict`", "library": []}
{"task_id": 6159900, "prompt": "def f_6159900(f):\n\treturn ", "suffix": "", "canonical_solution": "print('hi there', file=f)", "test_start": "\ndef check(candidate):", "test": ["\n file_name = 'a.txt'\n f = open(file_name, 'w')\n candidate(f)\n f.close()\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert lines[0] == 'hi there\\n'\n"], "entry_point": "f_6159900", "intent": "write line \"hi there\" to file `f`", "library": []}
{"task_id": 6159900, "prompt": "def f_6159900(myfile):\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\tf = open(myfile, 'w')\n\tf.write(\"hi there\\n\")\n\tf.close()\n", "test_start": "\ndef check(candidate):", "test": ["\n file_name = 'myfile'\n candidate(file_name)\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert lines[0] == 'hi there\\n'\n"], "entry_point": "f_6159900", "intent": "write line \"hi there\" to file `myfile`", "library": []}
{"task_id": 6159900, "prompt": "def f_6159900():\n\t", "suffix": "\n\treturn ", "canonical_solution": "\n\twith open('somefile.txt', 'a') as the_file: \n\t\tthe_file.write('Hello\\n')\n", "test_start": "\ndef check(candidate):", "test": ["\n file_name = 'somefile.txt'\n candidate()\n with open (file_name, 'r') as f:\n lines = f.readlines()\n assert lines[0] == 'Hello\\n'\n"], "entry_point": "f_6159900", "intent": "write line \"Hello\" to file `somefile.txt`", "library": []}
{"task_id": 19527279, "prompt": "def f_19527279(s):\n\treturn ", "suffix": "", "canonical_solution": "s.encode('iso-8859-15')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate('table') == b'table'\n", "\n assert candidate('hello world!') == b'hello world!'\n"], "entry_point": "f_19527279", "intent": "convert unicode string `s` to ascii", "library": []}
{"task_id": 356483, "prompt": "def f_356483(text):\n\treturn ", "suffix": "", "canonical_solution": "re.findall('Test([0-9.]*[0-9]+)', text)", "test_start": "\nimport re \n\ndef check(candidate):", "test": ["\n assert candidate('Test0.9ssd') == ['0.9']\n", "\n assert candidate('Test0.0 ..2ssd') == ['0.0']\n"], "entry_point": "f_356483", "intent": "Find all numbers and dots from a string `text` using regex", "library": ["re"]}
{"task_id": 38081866, "prompt": "def f_38081866():\n\treturn ", "suffix": "", "canonical_solution": "os.system('powershell.exe', 'script.ps1')", "test_start": "\nimport os\nfrom unittest.mock import Mock\n\ndef check(candidate):", "test": ["\n os.system = Mock()\n try:\n candidate()\n assert True\n except:\n assert False\n"], "entry_point": "f_38081866", "intent": "execute script 'script.ps1' using 'powershell.exe' shell", "library": ["os"]}
{"task_id": 7349646, "prompt": "def f_7349646(b):\n\t", "suffix": "\n\treturn b", "canonical_solution": "b.sort(key=lambda x: x[2])", "test_start": "\ndef check(candidate):", "test": ["\n b = [(1,2,3), (4,5,6), (7,8,0)]\n assert candidate(b) == [(7,8,0), (1,2,3), (4,5,6)]\n", "\n b = [(1,2,'a'), (4,5,'c'), (7,8,'A')]\n assert candidate(b) == [(7,8,'A'), (1,2,'a'), (4,5,'c')]\n"], "entry_point": "f_7349646", "intent": "Sort a list of tuples `b` by third item in the tuple", "library": []}
{"task_id": 10607688, "prompt": "def f_10607688():\n\treturn ", "suffix": "", "canonical_solution": "datetime.datetime.now()", "test_start": "\nimport datetime\n\ndef check(candidate):", "test": ["\n y = candidate()\n assert y.year >= 2022\n"], "entry_point": "f_10607688", "intent": "create a datetime with the current date & time", "library": ["datetime"]}
{"task_id": 30843103, "prompt": "def f_30843103(lst):\n\treturn ", "suffix": "", "canonical_solution": "next(i for i, x in enumerate(lst) if not isinstance(x, bool) and x == 1)", "test_start": "\ndef check(candidate):", "test": ["\n lst = [True, False, 1, 3]\n assert candidate(lst) == 2\n"], "entry_point": "f_30843103", "intent": "get the index of an integer `1` from a list `lst` if the list also contains boolean items", "library": []}
{"task_id": 4918425, "prompt": "def f_4918425(a):\n\t", "suffix": "\n\treturn a", "canonical_solution": "a[:] = [(x - 13) for x in a]", "test_start": "\ndef check(candidate):", "test": ["\n a = [14, 15]\n candidate(a)\n assert a == [1, 2]\n", "\n a = [float(x) for x in range(13, 20)]\n candidate(a)\n assert a == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]\n"], "entry_point": "f_4918425", "intent": "subtract 13 from every number in a list `a`", "library": []}
{"task_id": 17794266, "prompt": "def f_17794266(x):\n\treturn ", "suffix": "", "canonical_solution": "max(x.min(), x.max(), key=abs)", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n x = np.matrix([[1, 1], [2, -3]])\n assert candidate(x) == -3\n"], "entry_point": "f_17794266", "intent": "get the highest element in absolute value in a numpy matrix `x`", "library": ["numpy"]}
{"task_id": 30551576, "prompt": "def f_30551576(s):\n\treturn ", "suffix": "", "canonical_solution": "re.findall(r'\"(http.*?)\"', s, re.MULTILINE | re.DOTALL)", "test_start": "\nimport re\n\ndef check(candidate):", "test": ["\n s = (\n ' [irrelevant javascript code here]'\n ' sources:[{file:\"http://url.com/folder1/v.html\",label:\"label1\"},'\n ' {file:\"http://url.com/folder2/v.html\",label:\"label2\"},'\n ' {file:\"http://url.com/folder3/v.html\",label:\"label3\"}],'\n ' [irrelevant javascript code here]'\n )\n assert candidate(s) == ['http://url.com/folder1/v.html', 'http://url.com/folder2/v.html', 'http://url.com/folder3/v.html']\n", "\n s = (\n ' [irrelevant javascript code here]'\n ' [irrelevant python code here]'\n )\n assert candidate(s) == []\n"], "entry_point": "f_30551576", "intent": "Get all urls within text `s`", "library": ["re"]}
{"task_id": 113534, "prompt": "def f_113534(mystring):\n\treturn ", "suffix": "", "canonical_solution": "mystring.replace(' ', '! !').split('!')", "test_start": "\ndef check(candidate):", "test": ["\n assert candidate(\"This is the string I want to split\") == ['This',' ','is',' ','the',' ','string',' ','I',' ','want',' ','to',' ','split']\n"], "entry_point": "f_113534", "intent": "split a string `mystring` considering the spaces ' '", "library": []}
{"task_id": 5838735, "prompt": "def f_5838735(path):\n\treturn ", "suffix": "", "canonical_solution": "open(path, 'r')", "test_start": "\ndef check(candidate):", "test": ["\n with open('tmp.txt', 'w') as fw: fw.write('hello world!')\n f = candidate('tmp.txt')\n assert f.name == 'tmp.txt'\n assert f.mode == 'r'\n"], "entry_point": "f_5838735", "intent": "open file `path` with mode 'r'", "library": []}
{"task_id": 36003967, "prompt": "def f_36003967(data):\n\treturn ", "suffix": "", "canonical_solution": "[[sum(item) for item in zip(*items)] for items in zip(*data)]", "test_start": "\ndef check(candidate):", "test": ["\n data = [[[5, 10, 30, 24, 100], [1, 9, 25, 49, 81]],\n [[15, 10, 10, 16, 70], [10, 1, 25, 11, 19]],\n [[34, 20, 10, 10, 30], [9, 20, 25, 30, 80]]]\n assert candidate(data) == [[54, 40, 50, 50, 200], [20, 30, 75, 90, 180]]\n"], "entry_point": "f_36003967", "intent": "sum elements at the same index in list `data`", "library": []}
{"task_id": 7635237, "prompt": "def f_7635237(a):\n\treturn ", "suffix": "", "canonical_solution": "a[:, (np.newaxis)]", "test_start": "\nimport numpy as np \n\ndef check(candidate):", "test": ["\n data = np.array([[[5, 10, 30, 24, 100], [1, 9, 25, 49, 81]],\n [[15, 10, 10, 16, 70], [10, 1, 25, 11, 19]],\n [[34, 20, 10, 10, 30], [9, 20, 25, 30, 80]]])\n assert candidate(data).tolist() == [[[[ 5, 10, 30, 24, 100],\n [ 1, 9, 25, 49, 81]]],\n [[[ 15, 10, 10, 16, 70],\n [ 10, 1, 25, 11, 19]]],\n [[[ 34, 20, 10, 10, 30],\n [ 9, 20, 25, 30, 80]]]]\n"], "entry_point": "f_7635237", "intent": "add a new axis to array `a`", "library": ["numpy"]}
|