[BUG] TimeSeriesKMeans fails with a callable `averaging_method` of the documented form
Describe the bug
TimeSeriesKMeans documents a callable averaging_method as Callable[[np.ndarray], np.ndarray] (docstring at L87–90 and type hint at L180 of aeon/clustering/_k_means.py). A callable of that form fails in fit. _check_params adds distance and random_state to _average_params for every averaging method other than "mean" and "shift_scale", callables included, and _fit_one_init then calls self._averaging_method(X[curr_labels == j], **self._average_params). When distance is itself a callable, the injected distance is "dtw".
Steps/Code to reproduce the bug
import numpy as np
from aeon.clustering import TimeSeriesKMeans
def my_average(X):
return X.mean(axis=0)
X = np.random.default_rng(0).normal(size=(10, 1, 24))
TimeSeriesKMeans(n_clusters=2, averaging_method=my_average).fit(X)
Expected results
fit runs and calls my_average with the cluster members only, plus any user-supplied average_params.
Actual results
File "aeon/clustering/_k_means.py", line 220, in _fit
labels, centers, inertia, n_iters = self._fit_one_init(X)
File "aeon/clustering/_k_means.py", line 282, in _fit_one_init
cluster_centres[j] = self._averaging_method(
X[curr_labels == j], **self._average_params
)
TypeError: my_average() got an unexpected keyword argument 'distance'
Suggested fix
nly add distance and random_state for the built-in string methods (n_jobs is already limited to strings), and pass a callable only the user's average_params. Alternatively, document that callables receive these keyword arguments and change the documented signature.
Add a test with a callable averaging_method.
Versions
System:
python: 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)]
machine: Windows-11-10.0.26300-SP0
Python dependencies:
aeon: 1.6.0 (main @ 5392155a6)
pip: 25.1.1
setuptools: 82.0.0
scikit-learn: 1.7.2
numpy: 2.3.5
numba: 0.63.1
scipy: 1.17.0
pandas: 2.3.3
Hey, I'd like to take a look at this if available. @aeon-actions-bot assign me