Skip to content

Ruff inserts "id": null to notebook cells and breaks GitHub notebook viewer #6834

Closed
@harupy

Description

@harupy

Summary

https://github.com/harupy/mlflow/blob/3f1650db853d2c61ac0cdb0035be91b10f131859/examples/h2o/random_forest.ipynb

image

harupy/mlflow@3f1650d: a commit that replicates what ruff does:

Without "id": null, the notebook renders fine:
https://github.com/harupy/mlflow/blob/dab36dc4fd6ac6e442bb78c016e7813ced8c0a21/examples/h2o/random_forest.ipynb

image

How to reproduce

# Notebook without id
> cat a.ipynb
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import os\n",
    "\n",
    "math.pi"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (ruff)",
   "language": "python",
   "name": "ruff"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

# Run ruff
> cargo run -p ruff_cli -- check --fix --no-cache a.ipynb
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/ruff check --fix --no-cache a.ipynb`
Found 1 error (1 fixed, 0 remaining).

# Check
> cat a.ipynb
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "\n",
    "math.pi"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (ruff)",
   "language": "python",
   "name": "ruff"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions