From d1bed9b61b6c5c2514520ff313b633f980d3e8b6 Mon Sep 17 00:00:00 2001 From: Biel Stela Date: Wed, 11 Sep 2024 15:39:56 +0200 Subject: [PATCH] Adds nbstrip to pre-commit --- .pre-commit-config.yaml | 7 ++-- science/notebooks/check_combine_results.ipynb | 36 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9d983358..06290094 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,8 +16,7 @@ repos: - id: ruff-format types_or: [ python, pyi, jupyter ] - # check for private keys and passwords! - - repo: https://github.com/gitleaks/gitleaks - rev: v8.17.0 + - repo: https://github.com/kynan/nbstripout + rev: 0.7.1 hooks: - - id: gitleaks-docker + - id: nbstripout diff --git a/science/notebooks/check_combine_results.ipynb b/science/notebooks/check_combine_results.ipynb index 3fe61ffa..415aadc9 100644 --- a/science/notebooks/check_combine_results.ipynb +++ b/science/notebooks/check_combine_results.ipynb @@ -3,18 +3,17 @@ { "cell_type": "code", "execution_count": null, - "id": "e84373c7-a5e7-47c8-95a3-d2db7ade2e29", + "id": "0", "metadata": {}, "outputs": [], "source": [ - "import polars as pl\n", - "import polars.selectors as cs" + "import polars as pl" ] }, { "cell_type": "code", "execution_count": null, - "id": "750642ad-f9fc-434e-86f8-783cc41d533c", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -25,16 +24,16 @@ { "cell_type": "code", "execution_count": null, - "id": "d5012a5d-ea51-4b01-8ccf-055db2feb3ec", + "id": "2", "metadata": {}, "outputs": [], "source": [ - "schema = {\"cell\":pl.UInt64, \"b\":pl.Float32, \"c\":pl.String}\n", + "schema = {\"cell\": pl.UInt64, \"b\": pl.Float32, \"c\": pl.String}\n", "df = pl.DataFrame(schema=schema)\n", "\n", - "join1 = pl.DataFrame({\"cell\": [1,2,3], \"b\": [9., 9., 9.]}, schema_overrides=schema)\n", - "join2 = pl.DataFrame({\"cell\": [1,2,3], \"c\": [\"a\", \"b\", \"c\"]}, schema_overrides=schema)\n", - "join3 = pl.DataFrame({\"cell\": [4,5,6], \"c\": [\"a\", \"b\", \"c\"]}, schema_overrides=schema)\n", + "join1 = pl.DataFrame({\"cell\": [1, 2, 3], \"b\": [9.0, 9.0, 9.0]}, schema_overrides=schema)\n", + "join2 = pl.DataFrame({\"cell\": [1, 2, 3], \"c\": [\"a\", \"b\", \"c\"]}, schema_overrides=schema)\n", + "join3 = pl.DataFrame({\"cell\": [4, 5, 6], \"c\": [\"a\", \"b\", \"c\"]}, schema_overrides=schema)\n", "\n", "tojoin = [join1, join2, join3]\n", "\n", @@ -46,24 +45,23 @@ { "cell_type": "code", "execution_count": null, - "id": "af677cc8-34c5-4259-84c2-1d90a5bf3040", + "id": "3", "metadata": {}, "outputs": [], "source": [ "import polars as pl\n", "\n", "# Define the initial DataFrame\n", - "df = pl.DataFrame({\n", - " \"cell\": [1, 2, 3, 1, 2, 3, 4, 5, 6],\n", - " \"b\": [9.0, 9.0, 9.0, None, None, None, None, None, None],\n", - " \"c\": [None, None, None, \"a\", \"b\", \"c\", \"a\", \"b\", \"c\"]\n", - "})\n", + "df = pl.DataFrame(\n", + " {\n", + " \"cell\": [1, 2, 3, 1, 2, 3, 4, 5, 6],\n", + " \"b\": [9.0, 9.0, 9.0, None, None, None, None, None, None],\n", + " \"c\": [None, None, None, \"a\", \"b\", \"c\", \"a\", \"b\", \"c\"],\n", + " }\n", + ")\n", "\n", "# Perform the group by and aggregation\n", - "agg_df = df.groupby(\"cell\").agg([\n", - " pl.col(\"b\").max().alias(\"b\"),\n", - " pl.col(\"c\").max().alias(\"c\")\n", - "])\n", + "agg_df = df.groupby(\"cell\").agg([pl.col(\"b\").max().alias(\"b\"), pl.col(\"c\").max().alias(\"c\")])\n", "\n", "# Sort the resulting DataFrame by the 'cell' column\n", "result_df = agg_df.sort(\"cell\")\n",