Skip to content

Commit d82be7a

Browse files
committed
fix non-deterministic maximum_breaks when gaps are equal
Replace np.argpartition with np.argsort(kind='stable') so that tied gap sizes are broken by index order, consistently selecting the highest-value gaps.
1 parent dc1d4b6 commit d82be7a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

xrspatial/classify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def _compute_maximum_break_bins(values_np, k):
11701170
return uv
11711171
diffs = np.diff(uv)
11721172
n_gaps = min(k - 1, len(diffs))
1173-
top_indices = np.argpartition(diffs, -n_gaps)[-n_gaps:]
1173+
top_indices = np.argsort(diffs, kind='stable')[-n_gaps:]
11741174
top_indices.sort()
11751175
bins = np.array([(uv[i] + uv[i + 1]) / 2.0 for i in top_indices])
11761176
bins = np.append(bins, float(uv[-1]))

0 commit comments

Comments
 (0)