{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "MNrSAzxQGJuq" }, "source": [ "# Notebook 1: Collect, augment and publish a GitHub issues dataset\n", "\n", "**Source:** public issues of the `scikit-learn/scikit-learn` repository, via the GitHub REST API\n", "**Published dataset:** https://huggingface.co/datasets/BeNatural/github-scikit-learn-issues-dataset\n", "\n", "**What this notebook does**\n", "1. Explores one API response to see what GitHub returns.\n", "2. Collects 300 issues with the `requests` library, removing pull requests.\n", "3. Builds a structured table and adds two derived fields.\n", "4. Cleans and validates the data.\n", "5. Summarises the data (these figures are used in the dataset card).\n", "6. Saves CSV and Parquet files.\n", "7. Logs in to Hugging Face and pushes the files to the Hub.\n", "8. Checks that the published dataset loads correctly." ], "id": "MNrSAzxQGJuq" }, { "cell_type": "markdown", "metadata": { "id": "ViOkKMuiGJur" }, "source": [ "## 1. Setup" ], "id": "ViOkKMuiGJur" }, { "cell_type": "code", "metadata": { "id": "n9QXTUPcGJur" }, "execution_count": 1, "outputs": [], "source": [ "!pip install -q requests pandas pyarrow huggingface_hub datasets" ], "id": "n9QXTUPcGJur" }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "XAyOTWUsGJus", "outputId": "4db47633-1309-4c46-eeff-44c87d22b960" }, "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Collection date: 2026-11-05\n" ] } ], "source": [ "import time\n", "import datetime\n", "import requests\n", "import pandas as pd\n", "from pathlib import Path\n", "\n", "API_URL = \"https://api.github.com/repos/scikit-learn/scikit-learn/issues\"\n", "TARGET = 300 # number of genuine issues to collect\n", "HF_REPO = \"BeNatural/github-scikit-learn-issues-dataset\"\n", "\n", "collection_date = datetime.date.today()\n", "print(\"Collection date:\", collection_date)" ], "id": "XAyOTWUsGJus" }, { "cell_type": "markdown", "metadata": { "id": "3vShOl8kGJus" }, "source": [ "## 2. Explore one API response\n", "First, one small request to see what GitHub returns. GitHub's issues endpoint returns **both issues and pull requests**. A pull request can be recognised because it has a `pull_request` field." ], "id": "3vShOl8kGJus" }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "8xJ6GA-RGJus", "outputId": "afc5e9db-6e4f-4b5a-f4df-f2911859c285" }, "execution_count": 3, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Status code: 200\n", "Records received: 5\n", "35315 | pull request? True | MNT bump vendored array-api-compat to 1.16\n", "35314 | pull request? True | WIP MNT Add CI job that tests for thread-safety bugs by enab\n", "35313 | pull request? False | Add CI job with threaded parallelism on by default, to catch\n", "35312 | pull request? True | DOC/TST document and test GaussianNB var_smoothing\n", "35311 | pull request? True | PRF Compute KMeans' tolerance without np.var on dense data\n" ] } ], "source": [ "response = requests.get(API_URL, params={\"state\": \"all\", \"per_page\": 5}, timeout=30)\n", "print(\"Status code:\", response.status_code) # 200 means success\n", "response.raise_for_status()\n", "\n", "sample = response.json()\n", "print(\"Records received:\", len(sample))\n", "for item in sample:\n", " print(item[\"number\"], \"| pull request?\", \"pull_request\" in item, \"|\", item[\"title\"][:60])" ], "id": "8xJ6GA-RGJus" }, { "cell_type": "markdown", "metadata": { "id": "hvlJozP-GJus" }, "source": [ "## 3. Collect the issues\n", "- `state=all` returns open and closed issues.\n", "- `sort=created` and `direction=asc` return the **oldest issues first**.\n", "- `per_page=100` is the maximum page size.\n", "- Pull requests are skipped, so only genuine issues are kept.\n", "- A short pause between pages avoids overloading the API.\n", "- Collection stops once 300 issues have been gathered, and the list is trimmed to exactly 300.\n", "\n", "No access token is needed for this small number of requests, because the public API allows it within its rate limits." ], "id": "hvlJozP-GJus" }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "uwOzTrypGJus", "outputId": "a336ad8f-607c-430c-eab4-57f76eeb906e" }, "execution_count": 4, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Page 1: issues collected so far = 47\n", "Page 2: issues collected so far = 79\n", "Page 3: issues collected so far = 110\n", "Page 4: issues collected so far = 155\n", "Page 5: issues collected so far = 183\n", "Page 6: issues collected so far = 224\n", "Page 7: issues collected so far = 266\n", "Page 8: issues collected so far = 318\n", "\n", "FINAL TOTAL: 300\n" ] } ], "source": [ "all_issues = []\n", "page = 1\n", "\n", "while len(all_issues) < TARGET:\n", " response = requests.get(\n", " API_URL,\n", " params={\n", " \"state\": \"all\",\n", " \"per_page\": 100,\n", " \"page\": page,\n", " \"sort\": \"created\",\n", " \"direction\": \"asc\",\n", " },\n", " timeout=30,\n", " )\n", " response.raise_for_status()\n", " records = response.json()\n", "\n", " if not records: # no more pages\n", " break\n", "\n", " for item in records:\n", " if \"pull_request\" not in item: # keep genuine issues only\n", " all_issues.append(item)\n", "\n", " print(f\"Page {page}: issues collected so far = {len(all_issues)}\")\n", " page += 1\n", " time.sleep(0.5)\n", "\n", "all_issues = all_issues[:TARGET]\n", "print(\"\\nFINAL TOTAL:\", len(all_issues))" ], "id": "uwOzTrypGJus" }, { "cell_type": "markdown", "metadata": { "id": "IZSAkeJdGJut" }, "source": [ "GitHub returns many fields for each issue. Here is the list, so we can choose which ones to keep." ], "id": "IZSAkeJdGJut" }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "VWelh0j8GJut", "outputId": "291baeb2-67ea-4be5-957c-9ff3d6c6a98b" }, "execution_count": 5, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "['url', 'repository_url', 'labels_url', 'comments_url', 'events_url', 'html_url', 'id', 'node_id', 'number', 'title', 'user', 'labels', 'state', 'locked', 'assignees', 'milestone', 'comments', 'created_at', 'updated_at', 'closed_at', 'assignee', 'author_association', 'issue_field_values', 'type', 'active_lock_reason', 'sub_issues_summary', 'issue_dependencies_summary', 'body', 'closed_by', 'reactions', 'timeline_url', 'performed_via_github_app', 'state_reason', 'pinned_comment']\n" ] } ], "source": [ "print(list(all_issues[0].keys()))" ], "id": "VWelh0j8GJut" }, { "cell_type": "markdown", "metadata": { "id": "4oC9iMWnGJut" }, "source": [ "## 4. Build the table and add derived fields\n", "Fourteen fields are kept. Two of them are **derived** (calculated by us, not given by GitHub):\n", "- `text_length`: number of characters in the title and body together.\n", "- `time_to_close_hours`: hours between `created_at` and `closed_at` (empty for open issues).\n", "\n", "Text is stripped of leading and trailing spaces, a missing body becomes empty text, and the list of labels is joined into one comma-separated text field." ], "id": "4oC9iMWnGJut" }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 397 }, "id": "lfv3S4LNGJut", "outputId": "b49065d0-f44d-4a5d-ced2-b63a436020f7" }, "execution_count": 6, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Dataset shape: (300, 14)\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ " issue_id issue_number repository \\\n", "0 295764 1 scikit-learn/scikit-learn \n", "1 311965 5 scikit-learn/scikit-learn \n", "2 369933 7 scikit-learn/scikit-learn \n", "3 378489 8 scikit-learn/scikit-learn \n", "4 382343 11 scikit-learn/scikit-learn \n", "\n", " title \\\n", "0 remove Y from fit in OneClassSVM \n", "1 Bayesian regression \n", "2 Return index of support vectors in sparse SVM \n", "3 LARS module broken \n", "4 implement warm restarts for logistic regression \n", "\n", " body state \\\n", "0 closed \n", "1 Add priors on the mean instead of assuming tha... closed \n", "2 Assigned to me closed \n", "3 - the parameter names are different in docstri... closed \n", "4 assigned to me closed \n", "\n", " labels created_at closed_at \\\n", "0 2010-08-31 07:38:16+00:00 2010-08-31 07:43:11+00:00 \n", "1 2010-09-11 11:40:28+00:00 2012-01-06 13:37:31+00:00 \n", "2 Enhancement, Moderate 2010-10-19 08:00:57+00:00 2013-02-02 16:08:16+00:00 \n", "3 2010-10-23 23:04:24+00:00 2010-11-25 11:09:11+00:00 \n", "4 New Feature 2010-10-26 07:28:50+00:00 2014-10-12 15:30:46+00:00 \n", "\n", " comments author html_url \\\n", "0 0 fabianp https://github.com/scikit-learn/scikit-learn/i... \n", "1 11 vmichel https://github.com/scikit-learn/scikit-learn/i... \n", "2 2 fabianp https://github.com/scikit-learn/scikit-learn/i... \n", "3 5 satra https://github.com/scikit-learn/scikit-learn/i... \n", "4 12 fabianp https://github.com/scikit-learn/scikit-learn/i... \n", "\n", " text_length time_to_close_hours \n", "0 33 0.081944 \n", "1 443 11569.950833 \n", "2 60 20096.121944 \n", "3 349 780.079722 \n", "4 62 34736.032222 " ], "text/html": [ "\n", "
| \n", " | issue_id | \n", "issue_number | \n", "repository | \n", "title | \n", "body | \n", "state | \n", "labels | \n", "created_at | \n", "closed_at | \n", "comments | \n", "author | \n", "html_url | \n", "text_length | \n", "time_to_close_hours | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "295764 | \n", "1 | \n", "scikit-learn/scikit-learn | \n", "remove Y from fit in OneClassSVM | \n", "\n", " | closed | \n", "\n", " | 2010-08-31 07:38:16+00:00 | \n", "2010-08-31 07:43:11+00:00 | \n", "0 | \n", "fabianp | \n", "https://github.com/scikit-learn/scikit-learn/i... | \n", "33 | \n", "0.081944 | \n", "
| 1 | \n", "311965 | \n", "5 | \n", "scikit-learn/scikit-learn | \n", "Bayesian regression | \n", "Add priors on the mean instead of assuming tha... | \n", "closed | \n", "\n", " | 2010-09-11 11:40:28+00:00 | \n", "2012-01-06 13:37:31+00:00 | \n", "11 | \n", "vmichel | \n", "https://github.com/scikit-learn/scikit-learn/i... | \n", "443 | \n", "11569.950833 | \n", "
| 2 | \n", "369933 | \n", "7 | \n", "scikit-learn/scikit-learn | \n", "Return index of support vectors in sparse SVM | \n", "Assigned to me | \n", "closed | \n", "Enhancement, Moderate | \n", "2010-10-19 08:00:57+00:00 | \n", "2013-02-02 16:08:16+00:00 | \n", "2 | \n", "fabianp | \n", "https://github.com/scikit-learn/scikit-learn/i... | \n", "60 | \n", "20096.121944 | \n", "
| 3 | \n", "378489 | \n", "8 | \n", "scikit-learn/scikit-learn | \n", "LARS module broken | \n", "- the parameter names are different in docstri... | \n", "closed | \n", "\n", " | 2010-10-23 23:04:24+00:00 | \n", "2010-11-25 11:09:11+00:00 | \n", "5 | \n", "satra | \n", "https://github.com/scikit-learn/scikit-learn/i... | \n", "349 | \n", "780.079722 | \n", "
| 4 | \n", "382343 | \n", "11 | \n", "scikit-learn/scikit-learn | \n", "implement warm restarts for logistic regression | \n", "assigned to me | \n", "closed | \n", "New Feature | \n", "2010-10-26 07:28:50+00:00 | \n", "2014-10-12 15:30:46+00:00 | \n", "12 | \n", "fabianp | \n", "https://github.com/scikit-learn/scikit-learn/i... | \n", "62 | \n", "34736.032222 | \n", "