Corriger les erreurs de notebook

VérifiéSûr

Diagnostique et corrige les erreurs dans les notebooks Jupyter, y compris les bugs de code Python, les violations de schéma JSON et les problèmes de bibliothèque source. Il supprime automatiquement les ID de cellule problématiques et normalise nbformat_minor pour résoudre les échecs nbconvert. Utile lorsque l'exécution d'un notebook échoue en raison d'une logique de code, d'imports manquants ou de métadonnées invalides.

Spar Skills Guide Bot
DeveloppementIntermédiaire
7002/06/2026
Claude CodeCursorCopilotCodex
#fix-notebook#jupyter#debugging#json-schema#nbconvert

Recommandé pour

Notre avis

Cette compétence permet de corriger les erreurs d'exécution des notebooks Jupyter, qu'il s'agisse de bugs de code Python, de violations de schéma JSON ou de problèmes de bibliothèques.

Points forts

  • Analyse précise des traces d'erreur pour identifier la cause racine
  • Correction directe dans les cellules du notebook ou dans le schéma JSON
  • Utilisation de stratégies adaptées (code, schéma, source)
  • Vérification automatique via nbconvert

Limites

  • Ne remplace pas une compréhension approfondie de la logique métier
  • Peut être limité par la complexité des dépendances
  • Les correctifs de bibliothèques source peuvent nécessiter une recompilation
Quand l'utiliser

Utilisez cette compétence lorsqu'un notebook Jupyter ne s'exécute pas en raison d'erreurs Python, de schémas JSON invalides ou de bugs dans une bibliothèque sous-jacente.

Quand l'éviter

Évitez cette compétence pour des problèmes de conception générale ou des notebooks nécessitant une refonte complète de l'architecture.

Analyse de sécurité

Sûr
Score qualité85/100

The skill performs local file modifications (reading/writing .ipynb JSON) and running Jupyter commands for error-fixing. No destructive, exfiltrating, or obfuscated operations are present; it is a legitimate Jupyter maintenance task.

Aucun point d'attention détecté

Exemples

Fix JSON schema error
This notebook fails with 'Additional properties are not allowed ('id' was unexpected)'. Fix the JSON schema by removing cell IDs and setting nbformat_minor to 4.
Correct import error
The first cell in the notebook has an import error: ModuleNotFoundError for 'gwexpy'. Add a cell to install it via pip, or fix the import path.

name: fix_notebook description: ノートブックのエラーを、そのノートブック自体の修正(セル内容・JSONスキーマ)またはソースコードの修正により解決する

Fix Notebook Errors

This skill handles fixing errors encountered during notebook execution, ranging from Python code bugs to Jupyter JSON schema violations.

Instructions

  1. Analyze the Failure:

    • Examine the traceback to determine if the error is in the notebook cell's logic, a JSON schema violation, or the underlying library.
  2. Strategy A: Fix Code Cell (Local):

    • If the usage is wrong, imports are missing, or data paths are incorrect, edit the .ipynb cells.
    • Modify the "source" field of the failing code cell in the notebook JSON.
    • Unit-Safe Assignment: When updating astropy.units objects, prefer series.value[:] = new_data to keep metadata.
  3. Strategy B: Fix JSON Schema:

    • If nbconvert or validators fail with "Additional properties are not allowed ('id' was unexpected)":
    • Remove Cell IDs: Delete the "id" key from all cells in the JSON.
    • Normalize nbformat_minor: Set nbformat_minor to 4 (if nbformat is 4) to prevent auto-adding IDs.
  4. Strategy C: Fix Library Source Code:

    • If the bug is in the gwexpy/ package, trace it to the source file and apply the fix.
  5. Verification:

    • Re-run the notebook using jupyter nbconvert --execute or test_notebooks to confirm it passes.
# Utility for Strategy B
import json
def fix_nb_schema(path):
    with open(path, 'r') as f:
        data = json.load(f)
    for cell in data.get('cells', []):
        cell.pop('id', None)
    if data.get('nbformat') == 4 and data.get('nbformat_minor', 0) >= 5:
        data['nbformat_minor'] = 4
    with open(path, 'w') as f:
        json.dump(data, f, indent=1)
Skills similaires