This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
tsai is a state-of-the-art deep learning library for time series and sequential data, built on top of PyTorch and fastai. It supports classification, regression, forecasting, and imputation tasks.
The source of truth for tsai is nbs/*.ipynb. Files in tsai/ that carry an # AUTOGENERATED! DO NOT EDIT! header are produced from notebooks by nbdev-export — never edit those by hand; they'll be overwritten on the next export. A handful of files in tsai/ are hand-written sources with no AUTOGENERATED header (e.g. tsai/imports.py, tsai/__init__.py) — edit those directly.
- Prefer the
NotebookEdittool (it requiresReadfirst). - For large notebooks where
Readexceeds the token limit, fall back to Python JSON manipulation: load withjson.load, modify the target cell'ssourcearray, write back withjson.dump. Always clearoutputsand resetexecution_count = Noneon edited code cells. - After editing notebooks, run
nbdev-exportto regeneratetsai/*.py, thennbdev-cleanto strip metadata before committing.
nbdev-test is how you actually run a notebook: it spins up a fresh kernel for each .ipynb, executes every cell top to bottom, and surfaces any failed assertion, test_eq, or raised exception as a cell-level error with traceback. Running it is required to confirm in-notebook tests pass.
Before declaring work complete:
- macOS (Apple Silicon):
nbdev-test --n_workers 0 --do_print— runs in-process; avoids MPS-related Metal compiler crashes that hit the parallel runner under load. - Linux / CI:
nbdev-prepare— bundles export + test + clean.
For targeted spot checks during iteration:
- One or a few notebooks:
nbdev-test --file_re '^(004_|005_|009_)' --n_workers 0 - Slow tests: add
--flags slow - A single symbol's behavior: importing it in a fresh Python process is often faster than running the whole notebook.
Requires Python 3.10 or newer.
# Clone and install with dev dependencies
git clone https://github.com/timeseriesAI/tsai
pip install -e "tsai[dev]"
# Install nbdev git hooks (required for notebook development)
nbdev-install-hooks# Run all tests, export notebooks to Python, and clean notebooks (Linux / CI)
nbdev-prepare
# macOS (Apple Silicon) — run individually with an in-process test runner
# to avoid MPS-related crashes in the parallel runner
nbdev-clean
nbdev-export
nbdev-test --n_workers 0 --do_print
# Run tests only
nbdev-test
# Export notebooks to Python modules
nbdev-export
# Clean notebooks (remove outputs and metadata)
nbdev-clean
# Build documentation (requires quarto; install with `nbdev-install-quarto`)
nbdev-docsThis project uses nbdev for literate programming. Most source code lives in Jupyter notebooks under nbs/ and is exported to Python modules in tsai/ via nbdev-export. Generated files in tsai/ carry an # AUTOGENERATED! DO NOT EDIT! header — edit the corresponding notebook instead. A small number of files in tsai/ are hand-written sources (no AUTOGENERATED header) and are edited directly.
- Notebooks in
nbs/are the source of truth - Python files in
tsai/are auto-generated (marked with# AUTOGENERATED! DO NOT EDIT!) - Use
#|exportat the top of notebook cells to export code to modules - Notebook naming:
NNN_module.submodule.ipynbmaps totsai/module/submodule.py
nbs/- Source notebooks (edit these)tsai/- Auto-generated Python modulestsai/models/- Deep learning model implementationstsai/data/- Data loading, preprocessing, and transformstsai/callback/- Training callbackstutorial_nbs/- Tutorial notebooks (not part of the library)
from tsai.all import * # Import everything
from tsai.basics import * # Import core functionality (smaller import)- TSClassifier, TSRegressor, TSForecaster (
tsai/tslearner.py) - High-level learner classes that wrap fastai's Learner - TSTensor, TSDatasets, TSDataLoaders (
tsai/data/core.py) - Data containers - TSStandardize, SlidingWindow (
tsai/data/preprocessing.py,tsai/data/preparation.py) - Data transforms
Time series data uses 3D arrays: [samples, variables, sequence_length]
Models ending in Plus (e.g., InceptionTimePlus, TSTPlus) support flexible output heads for different tasks. Base models (e.g., InceptionTime, TST) are simpler implementations.
This project follows the fastai code style, not PEP8. Key differences:
- Short variable names are acceptable for numeric/interactive programming
- Compact code layout preferred over verbose
- See https://docs.fast.ai/dev/style.html
Tests can use these flags (configured in pyproject.toml under [tool.nbdev] tst_flags = 'local slow extras onnx'):
#|local- Skip in CI, run locally only#|slow- Skip slow tests by default; opt in withnbdev-test --flags slow#|extras- Requires extra dependencies (sktime, tsfresh, etc.)#|onnx- ONNX-related tests
Project configuration lives in pyproject.toml (PEP 621). Key sections:
[project]- name, version (dynamic fromtsai.__version__), Python requirement (>=3.10), authors, description.[project.dependencies]- Hard runtime dependencies.[project.optional-dependencies]:dev- Development tooling (nbdev, ipykernel).extras- Optional runtime dependencies (sktime, tsfresh, PyWavelets, nbformat).
[tool.nbdev]- nbdev-specific settings (test flags, jupyter hooks, custom sidebar).
Note:
settings.iniandsetup.pywere removed in tsai 1.0.0 —pyproject.tomlis now the single source for both Python packaging and nbdev configuration.