Skip to content

Fix Jiffle sdev() returning the range instead of the standard deviation - #314

Open
james-willis wants to merge 1 commit into
geosolutions-it:masterfrom
james-willis:fix/jiffle-sdev
Open

Fix Jiffle sdev() returning the range instead of the standard deviation#314
james-willis wants to merge 1 commit into
geosolutions-it:masterfrom
james-willis:fix/jiffle-sdev

Conversation

@james-willis

@james-willis james-willis commented Jul 21, 2026

Copy link
Copy Markdown

Bug

JiffleFunctions.sdev delegates to SampleStats.range instead of SampleStats.sdev:

public double sdev(List values) {
    return SampleStats.range(listToArray(values), true);
}

so the Jiffle sdev() script function actually returns the range of its input list, e.g. sdev([1, 2, 3, 4]) returns 3.0 instead of sqrt(5/3) ≈ 1.29099. variance() is unaffected (it correctly delegates to SampleStats.variance).

Fix

One-line delegation fix, plus two new tests in StatsFunctionsTest: sdevListArg asserts the sample standard deviation of a fixed list, and sdevIsSquareRootOfVariance asserts sdev(z)*sdev(z) == variance(z) per pixel.

mvn -pl jt-jiffle/jt-jiffle-language test passes (291 tests) under JDK 8.

Compatibility note

Any script relying on the buggy behavior will see different results after this fix; range() remains available for callers who actually want the range.

JiffleFunctions.sdev called SampleStats.range rather than
SampleStats.sdev, so the Jiffle sdev() function returned the range of
its input list. Fix the delegation and add tests: one asserting the
sample standard deviation of a known list, one asserting
sdev(z)^2 == variance(z).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant