Skip to content

Commit 1057996

Browse files
samay2504github-actions[bot]
authored andcommitted
Automatic pre-commit fixes
1 parent 61b5784 commit 1057996

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

aeon/segmentation/_hidalgo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _get_neighbourhood_params(self, X):
170170
n_neighbors=q + 1, algorithm="ball_tree", metric=metric
171171
).fit(X)
172172
distances, Iin = nbrs.kneighbors(X)
173-
173+
174174
# Add numerical stability: prevent division by zero when duplicate points exist
175175
# Use epsilon to handle cases where r1 (distances[:, 1]) is zero or near-zero
176176
eps = 1e-12
@@ -362,10 +362,10 @@ def sample_p(K, p, pp, c1, _rng):
362362
eps = 1e-12
363363
denom = max(c1[k] - 1 + c1[K - 1] - 1, eps)
364364
rmax = (c1[k] - 1) / denom
365-
365+
366366
# Prevent division by zero when rmax is 0 or 1
367367
rmax = np.clip(rmax, eps, 1.0 - eps)
368-
368+
369369
frac = ((r1 / rmax) ** (c1[k] - 1)) * (
370370
((1 - r1) / (1 - rmax)) ** (c1[K - 1] - 1)
371371
)

aeon/segmentation/tests/test_hidalgo.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@ def test_partition_function():
1717
def test_hidalgo_zero_distance_stability():
1818
"""
1919
Test Hidalgo segmenter with duplicate/near-duplicate points.
20-
20+
2121
Regression test for issue #3068: AssertionError when data contains
2222
identical rows, causing zero distances in nearest neighbor search.
2323
This should not crash but handle duplicates gracefully.
2424
"""
2525
# Create data with exact duplicates (causes zero distances)
26-
X = np.array([[0.1, 0.2, 0.3],
27-
[0.1, 0.2, 0.3], # Exact duplicate
28-
[0.4, 0.5, 0.6],
29-
[0.7, 0.8, 0.9],
30-
[0.7, 0.8, 0.9]]) # Another duplicate
31-
26+
X = np.array(
27+
[
28+
[0.1, 0.2, 0.3],
29+
[0.1, 0.2, 0.3], # Exact duplicate
30+
[0.4, 0.5, 0.6],
31+
[0.7, 0.8, 0.9],
32+
[0.7, 0.8, 0.9],
33+
]
34+
) # Another duplicate
35+
3236
# This should not raise AssertionError or divide-by-zero warnings
3337
hidalgo = HidalgoSegmenter(K=2, q=2, n_iter=100, burn_in=0.5)
34-
38+
3539
# Should complete without errors
3640
result = hidalgo.fit_predict(X, axis=0)
37-
41+
3842
# Basic sanity checks
3943
assert result is not None
4044
assert len(result) >= 0 # May return empty array if no changepoints
@@ -44,17 +48,16 @@ def test_hidalgo_zero_distance_stability():
4448
def test_hidalgo_normal_data():
4549
"""
4650
Test Hidalgo segmenter with normal random data.
47-
51+
4852
Verifies that the fix doesn't break normal operation.
4953
"""
5054
# Random data without duplicates
5155
rng = np.random.RandomState(42)
5256
X = rng.rand(50, 3)
53-
57+
5458
hidalgo = HidalgoSegmenter(K=3, q=3, n_iter=200, burn_in=0.8)
5559
result = hidalgo.fit_predict(X, axis=0)
56-
60+
5761
# Should work as before
5862
assert result is not None
5963
assert isinstance(result, np.ndarray)
60-

0 commit comments

Comments
 (0)