{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84795,"databundleVersionId":11281725,"sourceType":"competition"}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"papermill":{"default_parameters":{},"duration":22.341371,"end_time":"2024-12-11T03:22:13.479076","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-12-11T03:21:51.137705","version":"2.6.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport zipfile\n\n# !mkdir -p /kaggle/tmp/konwinski-prize-alt\nos.makedirs(\"/tmp/kaggle/tmp/konwinski-prize-alt\", exist_ok=True)\n\n# !unzip -q -o /kaggle/input/konwinski-prize/data.a_zip -d /kaggle/tmp/konwinski-prize-alt/ 2>/dev/null || true\nwith zipfile.ZipFile(\"/kaggle/input/konwinski-prize/data.a_zip\", \"r\") as zip_ref:\n    zip_ref.extractall(\"/tmp/kaggle/tmp/konwinski-prize-alt/\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-08T19:24:40.700287Z","iopub.execute_input":"2025-03-08T19:24:40.700718Z","iopub.status.idle":"2025-03-08T19:24:45.621371Z","shell.execute_reply.started":"2025-03-08T19:24:40.700684Z","shell.execute_reply":"2025-03-08T19:24:45.620437Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import kaggle_evaluation.konwinski_prize_gateway\nk_prize_gateway = kaggle_evaluation.konwinski_prize_gateway.KPrizeGateway()\nk_prize_gateway.unpack_data_paths()\n\nimport polars as pl\ndf = pl.read_parquet('/tmp/kaggle/tmp/konwinski-prize-alt/data/data.parquet')\n\n\"\"\"\n# test usage\nproblem_index = 5\nresults = test_patch(df.row(problem_index, named=True)[\"patch\"], problem_index)\n\"\"\"\n\ndef test_patch(patch: str, problem_index: int) -> None:\n\n    from pathlib import Path\n    print(\"testing\")\n    print(patch)\n\n    # because the utility script messes with the library versions\n    original_pythonpath = os.environ['PYTHONPATH']\n    os.environ['PYTHONPATH'] = \"/kaggle/lib/kagglegym:/kaggle/lib:/kaggle/usr/lib:/kaggle/input/konwinski-prize\"\n\n    results = k_prize_gateway._evaluate_instance(\n        instance = df.row(problem_index, named=True),\n        patch = patch,\n    )\n    \n    os.environ['PYTHONPATH'] = original_pythonpath\n\n    with open(\"patch.txt\", \"w\") as f:\n        f.write(patch)\n\n    from collections import Counter\n    print(\n        problem_index,\n        kaggle_evaluation.konwinski_prize_gateway.is_valid_patch_format(patch),\n        kaggle_evaluation.konwinski_prize_gateway.patch_dry_run_succeeds(\n            Path(\"/kaggle/working/patch.txt\"),\n            Path(f'/tmp/kaggle/tmp/konwinski-prize-alt/data/repos/repo__{df[\"instance_id\"][problem_index]}'),\n        ),\n        Counter(result.unit_test_outcome for result in results[1:])\n    )\n\n    from kaggle_evaluation.konwinski_prize_gateway import UnitTestOutcome\n\n    for result in results[1:]:\n        if result.unit_test_outcome != UnitTestOutcome.PASSED:\n            print(result.test_name)\n            print(result.fail_description)\n\n    return results","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-08T19:24:45.622542Z","iopub.execute_input":"2025-03-08T19:24:45.622799Z","iopub.status.idle":"2025-03-08T19:25:07.37856Z","shell.execute_reply.started":"2025-03-08T19:24:45.622776Z","shell.execute_reply":"2025-03-08T19:25:07.377215Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\nproblem_index = 2\npatch = '''\n--- a/astropy/table/table.py\n+++ b/astropy/table/table.py\n@@ -938,7 +938,7 @@ def _set_column_attribute(self, attr, values):\n                 if value.strip() == \"\":\n                     value = None\n \n-            if value not in (np.ma.masked, None):\n+            if value not in (np.ma.masked, None):\n                 col = self[name]\n                 if attr == \"unit\" and isinstance(col, Quantity):\n                     # Update the Quantity unit in-place\n'''\n\nresults = test_patch(patch, problem_index)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(results[0].test_output[::-1][:2000][::-1])","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\nproblem_index = 2\n\nprint(df['problem_statement'][problem_index])\npatch = df['patch'][problem_index]\nprint(patch)\n\nresults = test_patch(patch, problem_index)","metadata":{"trusted":true,"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}