An open API service indexing awesome lists of open source software.

https://github.com/sktime/sktime-cython

Cython-compiled estimators for sktime
https://github.com/sktime/sktime-cython

Last synced: 10 days ago
JSON representation

Cython-compiled estimators for sktime

Awesome Lists containing this project

README

          

# sktime-cython

Cython-compiled estimators for [sktime](https://github.com/sktime/sktime).

This package hosts ahead-of-time compiled implementations of sktime algorithms,
isolating the C-compilation and binary-wheel complexity from the main `sktime`
package. Estimators here expose a plain numpy-in/numpy-out compute layer with
**no sktime runtime dependency**; `sktime` keeps thin `BaseTransformer` /
`BaseEstimator` wrappers that delegate to this package.

Why a separate package: compiled extensions need a C toolchain, per-platform
wheels, and `cibuildwheel` release machinery. Keeping that here lets `sktime`
stay pure-Python while still offering compiled, numba-free fast paths.

## Estimators

| Estimator | Compute API | Notes |
|-----------|-------------|-------|
| Multivariate MiniRocket | `sktime_cython.fit` / `transform` | numba-free; equivalent to `MiniRocketMultivariate`, no JIT warmup |

Logic for further `sktime` cython based estimators should be added in this package,
for a recipe, see the [extension guide](https://github.com/sktime/sktime-cython#adding-an-estimator) below.

Runtime dependency: numpy only.

## Development

Requires a C compiler and Python 3.10+. Run from the project root.

```bash
# editable install with the dev extra (pulls sktime + numba for equivalence
# tests, plus pre-commit); compiles the Cython extensions via build isolation
uv pip install -e ".[dev]" # or: pip install -e ".[dev]"

# install the git pre-commit hooks ONCE — this is what stops CI lint failures
pre-commit install

# run the tests
python -m pytest sktime_cython -v
```

After editing a `.pyx`, recompile with `pip install -e .` again (or `make build`).

`make` shortcuts (auto-detect `uv`, falling back to `pip`/`python`):
`make install`, `make build`, `make test`, `make clean`.

## Before you push (avoid CI failures)

CI runs the pre-commit hooks and **fails if they reformat anything**. Running
`pre-commit install` (above) auto-runs them on every `git commit`. To check the
whole tree on demand:

```bash
pre-commit run --all-files
```

This runs `ruff check` (lint) and `ruff format`. If `ruff format` reports "files
were modified", it already fixed them — `git add` the changes and commit again.

## CI workflows

- **`test.yml`** (push / PR to `main`): a `code-quality` job running the
pre-commit hooks, plus a matrix that builds the Cython extensions and runs
pytest across Python 3.10–3.14 on Linux, macOS, and Windows.
- **`release.yml`** (on GitHub release): builds binary wheels with
[`cibuildwheel`](https://cibuildwheel.pypa.io/) for all platforms, builds an
sdist (with `.pyx` sources), and publishes to PyPI via trusted publishing.

## Adding an estimator

1. Drop the kernel `.pyx` (and optional `.pyi` stub) in a subfolder of the package.
The package structure mirrors that of `sktime`, files should be added paralleling
its primary import location in `sktime`
2. Register the kernel as an `Extension` in `setup.py`.
3. Add a numpy compute-layer module `sktime_cython/.py` exposing the
estimator's public functions. Keep them in the submodule — do not re-export
at the top level (avoids name collisions across estimators).
4. Add tests in a subfolder `tests`, in the same folder as the kernel.

## Package structure

Cython kernels and python layers should be added in a parallel location as in the
`sktime` package.

Example for minirocket:

```
sktime_cython/
transformations/
rocket/
__init__.py # public compute-layer exports
_minirocket.py # numpy fit/transform layer
_minirocket_multivariate_cython.pyx # compiled kernels
_minirocket_multivariate_cython.pyi # type stubs
tests/
__init__.py
test_minirocket.py # tests
```

## License

BSD 3-Clause License — see [LICENSE](LICENSE).