labelarray
Labelled N-D arrays in pure NumPy, with exact label semantics and reproducible reductions. It needs NumPy only; xarray is used only to convert to and from xarray objects. It is the array layer of tidy3a, released on its own.
It is deliberately small. What it offers that other array libraries do not:
- Exact labels. Labels match only when they are the same kind
(booleans, numbers, times, durations, text, bytes) and exactly equal, in
lookups, alignment, and joins. The integer
2**53 + 1never matches the float2**53; pandas, and so xarray, pair labels through float64. - Reproducible reductions. Float32 sums and means are correctly rounded: the float32 nearest the exact result, the same in any memory layout. Grouped reductions are bit-identical to reducing each group on its own, and data held in chunks (Dask) gets the same bits whatever the chunking: each chunk's estimate combines in any order, and exact sums settle the few results an error bound cannot.
- Collections. Arrays sharing axes, with one label array per axis, joined and aligned under those rules.
Status: version 0.1.3; the API may still
change before 1.0. What changed in each release is in
CHANGELOG.md.
Installing
Requires Python 3.11 or newer.
pip install labelarray # NumPy only
pip install "labelarray[xarray]" # with xarray: to_xarray() and from_xarray()
pip install "labelarray[fast]" # with Numba: compiled grouped float32 sums and means
Results are the same with or without fast; it only makes large grouped
sums and means faster.
Arrays
An Array is a NumPy array with one name per axis, labels for any of its
axes, attributes, and a name:
import numpy as np
from labelarray import Array
air = Array(
np.array([[271.0, 272.0, 273.0], [281.0, 282.0, 283.0]], dtype="float32"),
dims=("lat", "time"),
coords={"lat": [10.0, 20.0], "time": np.arange("2026-01-01", "2026-01-04", dtype="datetime64[D]")},
attrs={"units": "K"},
name="air",
)
print(air.sel(lat=20.0).data) # [281. 282. 283.]
print(air.isel(time=[0, 2]).labels("time")) # ['2026-01-01' '2026-01-03']
print(air.reduce("mean", ["time"]).data) # [272. 282.]
isel takes positions, slices, or masks; sel takes labels, looked up
exactly; one label or position removes the axis, a list keeps it.
transpose, rename (axes), reduce (sum, mean, min, max, median, std,
var, any, all, count, with na_rm and min_count), and dot (the sum of
products over named axes) complete the methods.
NumPy's ufuncs, np.where, and Python's operators broadcast by axis name.
Labels on a shared axis must match: the same labels in another order are
matched by label, and anything else is an AlignError. There is no outer
join by default; ask for one with Collection.join.
import numpy as np
from labelarray import Array
a = Array([1.0, 2.0, 3.0], ("x",), {"x": [1, 2, 3]})
b = Array([30.0, 10.0, 20.0], ("x",), {"x": [3, 1, 2]})
print((a + b).data) # [11. 22. 33.]
print(np.sqrt(a * 4).data) # [2. 2.82842712 3.46410162]
Labels are copied once into a read-only array the library owns, and each
label array's index is built on first use and kept with it: a sorted index,
a sort-once index for unsorted labels, or a grid index for evenly spaced
numbers and times, which looks labels up arithmetically. register_index
adds index classes for other label types, under the same exactness
obligations.
Collections
A Collection holds variables with different axes, each axis with one size
and at most one label array:
from labelarray import Array, Collection
left = Collection({"a": Array([1.0, 2.0, 3.0], ("k",))}, {"k": [1, 3, 5]})
right = Collection({"b": Array([10.0, 20.0], ("k",))}, {"k": [5, 1]})
both = left.join(right, "inner")
print(both.coords["k"]) # [1 5]
print(both.array("b").data) # [20. 10.]
print(left.join(right, "left").array("b").data) # [20. nan 10.]
isel, sel, select (variables), assign, rename (variables), join
(left, inner, or outer), nearest (each label matched to its nearest within
a tolerance), to_dict, to_xarray, and from_xarray are its methods.
Missing positions after a join promote integers and booleans as xarray
does, and attributes that conflict are dropped.
Grouping
A Grouping assigns each position a group code; factorize makes one from
key values, optionally after a key transform (Bins, Duration, Round,
GridCells), with every missing key (NaN, NaT) one group, dropped unless
asked for. grouped.reduce reduces every group at once:
import numpy as np
from labelarray import Array, Grouping, factorize, grouped
intensity = Array(np.array([10, 20, 30, 40, 50], dtype="float32"), ("point",))
codes, labels = factorize(np.array([0, 0, 1, 1, 2]))
rings = Grouping(codes, labels)
print(grouped.reduce(intensity, "mean", rings, "point", "ring").data) # [15. 35. 50.]
print(grouped.counts(rings, "ring").data) # [2 2 1]
grouped.broadcast puts a result per group back on each position.
Errors
Every error is a LabelArrayError (a ValueError): LabelError for labels
that cannot be found, ordered, or compared; AlignError for axes that
cannot be paired; GroupError for keys that cannot be grouped; and
ShapeError for axis names, sizes, and ranks that do not fit.
Development
From a checkout, install the development dependencies and run the tests:
python -m pip install -e ".[dev]"
python -m pytest -q
xarray and pandas are test dependencies: the tests check the library against xarray and its label lookups against pandas. Before pushing, run the CI checks in fresh environments with only declared dependencies (requires uv):
scripts/check.sh
The release procedure describes the GitHub Release workflow.
License
MIT
Metadata
Release files for labelarray 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| labelarray-0.1.3.tar.gz | 79.1 kB | With provenance | Details for labelarray-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| labelarray-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for labelarray-0.1.3-py3-none-any.whl |
Total release size: 132.9 kB
Release files / labelarray-0.1.3.tar.gz
| Download URL | labelarray-0.1.3.tar.gz |
|---|---|
| Size | 79.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
542038aba4aab762aaa63a5dd7e8c53e1d1a5f9b52383b60411f6deeca416bc1
|
|
BLAKE2b-256 checksum How to use checksums |
a607ce5bab94f9d89829d10cf85359dc1598710ba806c9c31b6cf3ec5b8f77c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logRelease files / labelarray-0.1.3-py3-none-any.whl
| Download URL | labelarray-0.1.3-py3-none-any.whl |
|---|---|
| Size | 53.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16c6bf8d74c29ad4fcd8e86e2084b451d72b108966f659b33782092762ba78f4
|
|
BLAKE2b-256 checksum How to use checksums |
85550ea989e4798b64cc6ed53e7b43e6d6e48097872bde048051d40edca3360f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logSecurity for labelarray 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for labelarray-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.