---
title: "stats: single-element quartile errors in Go | VulCode"
description: "In the Go stats library, Quartile, InterQuartileRange, Midhinge, Trimean and QuartileOutliers return an error for one element instead of a silent NaN."
url: "https://vulcode.com/en/opensource/contributions/go-stats"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

montanaflynn/stats

# stats

A Go statistics library with no dependencies: means, median, quartiles, percentiles, outliers and statistical tests.

[See the repository](https://github.com/montanaflynn/stats) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Go
- **GitHub stars**: 3,031
- **Merged changes**: 1

## What we changed

Quartile and the functions built on it, InterQuartileRange, Midhinge, Trimean and QuartileOutliers, return an error for single-element input instead of NaN with a nil error.

### What this work shows

- Error handling in Go

- Descriptive statistics: quartiles and IQR

- NaN values and edge-case input

What was broken

### One number gave NaN quartiles, no error

Quartile([]float64{1}) returned {Q1:NaN Q2:1 Q3:NaN} with a nil err, because the errors from Median were assigned to _. The same NaN flowed on into InterQuartileRange, Midhinge and Trimean, so code that only checked err != nil got NaN as its result.

How we fixed it

### A single element is now an error

Quartile returns EmptyInputErr for fewer than two elements, and InterQuartileRange, Midhinge, Trimean and QuartileOutliers pass that error on instead of dropping it. Each of these functions has a single-element test, and the docs say at least two elements are needed.

[#135](https://github.com/montanaflynn/stats/pull/135)

## Merged change

1 9 September 2026

- [01 #135Merged 9 September 2026 fix: return an error from Quartile and its callers for single-element input](https://github.com/montanaflynn/stats/pull/135)

## What it taught us

We catch errors swallowed in Go by assigning them to _: here NaN passed through several functions as a valid result. The fix passes the error up and has a test for every function it touches.

[More about this technology: Golang](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
