From 120069e931b6228a8758b94ea169592377680c31 Mon Sep 17 00:00:00 2001 From: Jorge Polanco <55784702+Jorge-Polanco-Roque@users.noreply.github.com> Date: Sun, 30 Aug 2026 14:33:11 -0600 Subject: [PATCH] [BUG] Preserve input dtype in shift_scale_invariant zero-padding The zero-padding in the shift branches of the shift-scale-invariant distance used an untyped np.zeros (float64), so shifted_y could not unify with float32 input inside the numba-compiled function, raising a TypingError. Pass dtype=y.dtype in both branches. Fixes #3722 --- aeon/distances/_shift_scale_invariant.py | 4 ++-- .../tests/test_miscellaneous_distances.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/aeon/distances/_shift_scale_invariant.py b/aeon/distances/_shift_scale_invariant.py index fbe5d3174a..b790b76e90 100644 --- a/aeon/distances/_shift_scale_invariant.py +++ b/aeon/distances/_shift_scale_invariant.py @@ -141,10 +141,10 @@ def _univariate_shift_scale_invariant_distance( shifted_y = y elif sh < 0: # Shift left - shifted_y = np.append(y[-sh:], np.zeros(-sh)) + shifted_y = np.append(y[-sh:], np.zeros(-sh, dtype=y.dtype)) else: # Shift right - shifted_y = np.append(np.zeros(sh), y[:-sh]) + shifted_y = np.append(np.zeros(sh, dtype=y.dtype), y[:-sh]) dist = _scale_d(x, shifted_y) diff --git a/aeon/distances/tests/test_miscellaneous_distances.py b/aeon/distances/tests/test_miscellaneous_distances.py index 319622f38b..0f3dcf4b89 100644 --- a/aeon/distances/tests/test_miscellaneous_distances.py +++ b/aeon/distances/tests/test_miscellaneous_distances.py @@ -35,3 +35,18 @@ def test_shift_scale_invariant_distance(): assert univariate_shift[1].shape == (10,) assert isinstance(multivariate_shift[1], np.ndarray) assert multivariate_shift[1].shape == (3, 10) + + +def test_shift_scale_invariant_distance_float32(): + """Test that float32 input does not raise a numba TypingError (#3722). + + The zero-padding in the shift branches used to default to float64, which could + not unify with the float32 input inside the numba-compiled distance. + """ + x = make_example_2d_numpy_series(n_channels=1, n_timepoints=10, random_state=1) + y = make_example_2d_numpy_series(n_channels=1, n_timepoints=10, random_state=2) + + dist64 = shift_scale_invariant_distance(x.astype(np.float64), y.astype(np.float64)) + dist32 = shift_scale_invariant_distance(x.astype(np.float32), y.astype(np.float32)) + + assert_almost_equal(dist32, dist64, decimal=4)