When reversing Canberra distance inputs changes the sign
A finite distance alone cannot admit a neighbor relation. Compare both directions with a reference derived from the original vectors and preserve the integer absolute-value boundary.
Why reverse the pair
If the distance between the same two observations changes with input order, a retained neighbor list loses a stable meaning. Admit Canberra distances using separate checks for agreement with an independent reference, nonnegativity, and symmetry. Once the operator computes that reference from the original vectors and prepares a comparison table, Truthound Core can provide one bounded step in enforcing the contract. [1, 2, 3]
The report containing the minimum integer
On 2026-10-24, SciPy #26486 reported canberra(u,v)=-1.0 for int64 vectors u=[-9223372036854775808] and v=[0], while the reversed call returned 1.0. A cdist comparison also returned 1.0. The reporter attributed the difference to the first input's integer absolute value and conversion of the second input to float64. Execution on SciPy 1.17.0 was distinguished from inspection of 1.18.1 source; this article does not independently establish that diagnosis by execution. [1]
Keep vector identity beside the calculation policy
Retain pair IDs, original integer values, both call directions, and the computation dtype. Derive a separate reference without losing range during absolute-value calculation, then compare the forward and reverse outputs for the same pair. Keep negative or mismatching distances out of neighbor searches and ranking summaries. Agreement between the two directions is insufficient by itself because both may be wrong. [1, 3]
An illustrative distance between 0 and -4
For illustrative one-dimensional inputs u=[-4] and v=[0], the Canberra formula |u-v|/(|u|+|v|) is 4/4=1. The expected distance 1 comes independently from that formula. An observed distance of 1 passes the comparison, while -1 fails it. This small conceptual counterexample demonstrates rejection of a negative distance; it does not reproduce execution at the int64 minimum. Define the handling of coordinates with a zero denominator separately. [1, 3]
Separate table comparison from numerical computation
ColumnPairValidator in Truthound Python SDK 3.3.2 applies == to nonmissing values in precomputed observed_distance and reference_distance columns. Operators supply vector semantics, the reference computation, and the tolerance policy. Real floating-point workloads need an error rule appropriate to their precision. This Core API does not reimplement Canberra distance or modify SciPy. Passing one pair does not guarantee accuracy of the full distance matrix or safety of the analysis. [1, 2, 3]
Check the cost of a conversion workaround
Test alternatives such as converting both inputs to a common computation type or using a verified cdist path. First check whether conversion of large integers to floating point collapses distinctions the task needs. Workloads requiring exact original integer differences may need a wide-integer or high-precision reference instead. This boundary case has lower priority when the input range is small and both directions are already tested. [1, 3]
Application conditions
Provide original vectors, pair IDs, both directions, and an independent distance reference.
Alternatives
Separately test the range and precision of a common computation type or a verified cdist path.
Limitations
Agreement for one pair does not establish the entire distance matrix or correctness of real neighbor decisions.
Evidence
- Event checked
- Subject checked
- Modified
