cld-reducer for Python
Reduce compact letter displays (CLDs) while preserving the pairwise statistical relationships they encode. This is the Python package of the cld-reducer repository, which also holds an R package and a JavaScript package. All three solve the assignment-minimum clique covering of Ennis, Fayle, and Ennis (2012), https://doi.org/10.1145/2133803.2275596, as a mixed-integer program with HiGHS, and they return the same display for the same input. The rules they follow are in docs/algorithm.md in the repository.
The solver is HiGHS through highspy. The dependencies are highspy, NumPy, and pandas.
Installation
Install from PyPI:
pip install cld-reducer
To install the development version from the repository:
pip install "git+https://github.com/aigorahub/cld-reducer.git#subdirectory=python"
The #subdirectory=python part is needed because the Python package lives in python/. Python 3.10 or later. The module is cld_reducer and the command line tool is cld-reduce.
For development, work from this folder:
cd python
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
ruff check . && ruff format --check . && pytest
Usage
import pandas as pd
from cld_reducer import reduce_letters
# One row for each pair. True means the groups differ significantly.
pairs = pd.DataFrame(
[
("1", "2", False),
("1", "3", False),
("1", "4", True),
("1", "5", True),
("2", "3", False),
("2", "4", False),
("2", "5", True),
("3", "4", False),
("3", "5", False),
("4", "5", False),
],
columns=["group1", "group2", "significant"],
)
means = pd.DataFrame({"group": ["1", "2", "3", "4", "5"], "mean": [3.73, 3.57, 3.46, 3.33, 3.30]})
result = reduce_letters(pairs, means)
print(result.letters)
# {'1': 'A', '2': 'AB', '3': 'AC', '4': 'BC', '5': 'C'}
print(result.to_frame())
# group letters assignments
# 0 1 A A
# 1 2 AB A B
# 2 3 AC A C
# 3 4 BC B C
# 4 5 C C
print(result.stats)
# {'assignments_before': 9, 'assignments_after': 8, 'reduction_pct': 11.11111111111111, 'num_letters_before': 3, 'num_letters_after': 3, 'num_groups': 5, 'num_edges': 7, 'solver_status': 'Optimal', 'objective': 8}
This example works after package installation and needs no external files. reduce_letters takes complete pairwise results: one row for each pair of groups, with a boolean column that tells whether the pair differs significantly. Missing pairs are rejected. means is optional and orders the groups and the letters. If you already have the non-significance matrix, use reduce_from_adjacency; there, True means two groups are not significantly different and must share a letter.
The result, a CLDReductionResult, has:
letters: the display of each group, for example"AC"(tokens are joined with spaces afterZ, as in"Z AA")assignments: the letters of each group as a tuple, the safe machine-readable formstats: the counts before and after the reduction and the solver status;reduction_pctis not roundedrelationship_preserved: alwaysTruefor a returned resultto_frame(): a tidypandas.DataFrame
The public names are reduce_letters, reduce_from_adjacency, CLDReductionResult, CLDReducerError, InvalidInputError, and SolverError.
When several displays have the same, smallest number of assignments, the package returns the canonical one defined in docs/algorithm.md, so R, Python, and JavaScript agree. time_limit is one time budget in seconds for all solves of a call, and max_cliques (10,000 by default; None removes it) bounds the number of maximal cliques.
Command line
cld-reduce examples/simple_abc_to_ac_pairs.csv \
--means examples/simple_abc_to_ac_means.csv \
--time-limit 30 \
--out reduced.csv
The paths above refer to files in a checkout or an extracted source archive. For your own data, pass your CSV paths. The pairs file has the columns group1, group2, and significant; the optional means file has group and mean. The output CSV has the reduced letters and the summary statistics. Other flags: --group1, --group2, --significant, --max-cliques, --no-max-cliques, and --method.
Examples
The following scripts and CSV files are included in a repository checkout or the source archive, but not in the installed wheel. Run them from python/ in a checkout, or from the root of an extracted source archive:
python examples/simple_abc_to_ac.py
python examples/piepho2004_wheat.py
The CSV files in examples/ are identical copies of the files in conformance/data/ at the repository root.
Changes in 0.2.0
The 0.2.0 release moved the package to python/ and the solver to highspy, which can change the display for inputs with several minimal displays and can rename letters. See the root NEWS.md for the full list.
License
MIT. See LICENSE.
Input and release notes
CSV label columns preserve their exact text, including 001, NA, NaN, and
empty strings. A blank CSV label is an empty-string label; missing values in API
objects still raise InvalidInputError. Means must remain finite numbers.
The means table uses group and mean when both exist, or its first two columns.
A list of pair rows preserves each numeric label before conversion to text.
Uneven adjacency rows raise the package's square-matrix error.
The source distribution contains example scripts and CSV files. The wheel
contains the importable package and its license and data notice. Shared
conformance fixtures remain in the repository, so source-distribution tests skip
those cases when the fixtures are absent. CI tests both installed distributions
outside the checkout. See docs/releasing.md in the repository for release steps.
Example data reuse remains subject to the conditions in NOTICE.
Metadata
Release files for cld-reducer 0.2.0
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 |
|---|---|---|---|---|
| cld_reducer-0.2.0.tar.gz | 26.1 kB | With provenance | Details for cld_reducer-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cld_reducer-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for cld_reducer-0.2.0-py3-none-any.whl |
Total release size: 47.0 kB
Release files / cld_reducer-0.2.0.tar.gz
| Download URL | cld_reducer-0.2.0.tar.gz |
|---|---|
| Size | 26.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
625a957c19532eabbb82c438728cfe5c66ecb3b08e72758145b90de600e8b7f3
|
|
BLAKE2b-256 checksum How to use checksums |
37d04d0e05968eea9a7dde21b3c69a4fb093f8cd247549c4546e5c9ff759de6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 10, 2026.
Transparency logRelease files / cld_reducer-0.2.0-py3-none-any.whl
| Download URL | cld_reducer-0.2.0-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48a5c3ea00d281227e7cabbdcaced47b0b1057440b83932885595aa702cd297d
|
|
BLAKE2b-256 checksum How to use checksums |
3d14bfe0834ae9881e2c3ac6049cf16cb98be9567f8a077a31850ce1eb2ddb9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 10, 2026.
Transparency logSecurity for cld-reducer 0.2.0
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 cld_reducer-0.2.0.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 10, 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.