Skip to main content

pedigree-graph

Sparse-matrix pedigree relationship extraction and kinship computation.

Builds parent→child CSR adjacency matrices and extracts relationship categories using sparse matrix algebra (A @ A.T for siblings, A² @ A²ᵀ for cousins, etc.). Each relationship type is parameterised by (up, down, n_ancestors):

  • up: meioses from the first member (the junior role: offspring, descendant, niece_nephew, junior_cousin) up to the common ancestor(s); collateral categories are stored up ≥ down
  • down: meioses from common ancestor(s) down to individual B
  • n_ancestors: 1 (half/lineal) or 2 (full, i.e. mated pair)
  • kinship = n_ancestors × (1/2)^(up + down + 1)

Install

pip install pedigree-graph

Binary wheels cover manylinux x86-64 and AArch64, macOS x86-64 and Apple Silicon, and Windows x86-64 (one abi3 wheel per platform for CPython >= 3.13). Elsewhere pip builds the sdist, which needs a Rust toolchain (rustc >= 1.85).

For development the locked pixi environment carries Python, Rust, and maturin and installs the package editable (the extension module is rebuilt with pixi run maturin develop --release after a Rust change):

git clone https://github.com/rwaples/pedigree-graph.git
cd pedigree-graph
pixi install --locked
pixi run pytest -m "not slow"   # inner loop, about 2.5 minutes
pixi run pytest                 # before a commit, about 13 minutes
pixi run cargo test --release   # the Rust core

Five of the nine slow tests are the random_30k integration gates. Each runs the pair-kinship kernel over the whole 30,300-row pedigree, and a single kernel call there costs 30 to 250 seconds regardless of how many pairs it is asked for, so the full suite is dominated by a handful of tests. The other four are the N=2000 effective-size scaling tests in tests/test_effective_size_scaling.py, which touch neither random_30k nor the pair-kinship kernel.

Requires Python ≥ 3.13. Runtime deps: numpy, scipy, and numba (still used by the inbreeding walk, the equivalent-generation kernel and the lineage kernels); construction, relationships, topology, pairwise kinship, the kinship matrices and the generation kinship summary are compiled Rust (pedigree_graph._native, sources under crates/). Pandas is optional and only needed if you pass DataFrames to the constructors.

Usage

import numpy as np
from pedigree_graph import RELATIONSHIPS, PedigreeGraph

# Construct from arrays (no pandas needed)
pg = PedigreeGraph.from_arrays(
    ids=np.array([0, 1, 2, 3, 4]),
    mother_ids=np.array([-1, -1, 0, 0, 0]),
    father_ids=np.array([-1, -1, 1, 1, 1]),
)

# Or from a table: a dict of columns (pandas-free), or any pandas/polars frame
pg = PedigreeGraph.from_frame(
    {
        "id": np.array([0, 1, 2, 3]),
        "mother": np.array([-1, -1, 0, 0]),
        "father": np.array([-1, -1, 1, 1]),
        "twin": np.array([-1, -1, -1, -1]),
        "sex": np.array([0, 1, 0, 1], dtype=np.int8),
        "generation": np.array([0, 0, 1, 1], dtype=np.int32),
    }
)
# pg = PedigreeGraph.from_frame(df)

# Pairs by relationship category, up to a given degree; each block holds
# read-only int32 first_rows / second_rows in the category's role orientation.
# execution="memory" returns the same blocks at the lowest peak memory
# (the result plus engine state) for about twice the wall time.
pairs = pg.relationship_pairs(max_degree=3)
first, second = pairs["FS"]  # full sibs
print(len(pairs["1C"]))  # 1st cousins (degree 3)
print(RELATIONSHIPS["FS"].nominal_kinship)  # 0.25

# Pedigree-expected kinship for those pairs, or for any two row arrays
kin = pg.pair_kinship(pairs)  # {code: float32 array}
kin_fs = pg.pair_kinship(first, second)

# Exact counts in O(N) memory (no pair lists), and the three kinship-matrix families
counts = pg.relationship_counts(max_degree=3)
K = pg.kinship_matrix()  # complete, CSC float32

# Scalar counts for MZ, MO, FO, FS, MHS and PHS only, also exact
close = pg.close_relative_counts()  # no degree/category selector
assert close["FS"] == counts["FS"]
assert close["GP"] is None  # not computed, not zero

Absent optional columns read as absent: there is no sex default and no generation fallback. Effective-size estimators live in pedigree_graph.effective_size; the FrameLike protocol in pedigree_graph.typing. Migrating from 0.7.1: see the old-to-new table in CHANGELOG.md.

close_relative_counts() is full-graph only. Its requested and exact sets contain the six codes above; all other registry keys map to None. It counts parent edges and sibling groups without pair lists or adjacency powers. For grandparents, avuncular pairs, cousins, or a pedigree view, use relationship_counts() instead. The former estimate_relationship_counts method and the result fields approximate and clamped have been removed.

Relationship registry

Codes follow the convention up_down_n_anc:

Code Label up down n_anc Kinship Degree
MZ MZ twin 0 0 0 0.5 0
MO Mother–offspring 1 0 1 0.25 1
FO Father–offspring 1 0 1 0.25 1
FS Full sib 1 1 2 0.25 1
MHS Maternal half sib 1 1 1 0.125 2
PHS Paternal half sib 1 1 1 0.125 2
GP Grandparent 2 0 1 0.125 2
Av Avuncular 2 1 2 0.125 2
1C 1st cousin 2 2 2 0.0625 3
... (full registry up to 2nd cousin / kinship 1/64)

See RELATIONSHIPS for the complete list; each RelationshipCategory carries code, label, degree, nominal_kinship, up, down, ancestor_count, and the two positional roles.

Architecture

For contributors: docs/architecture.md maps the module layout and the hidden contracts (coordinate space, exact count coverage, sparse-ID handling, default sex), each with its source of truth and regression test. The relationship/coordinate vocabulary is in CONTEXT.md; design decisions are in docs/adr/.

License

MIT — see LICENSE.

Metadata

Release files for pedigree-graph 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pedigree-graph 0.9.3
File Size Uploaded Provenance
pedigree_graph-0.9.3.tar.gz 615.5 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for pedigree-graph 0.9.3
File
pedigree_graph-0.9.3-cp313-abi3-win_amd64.whl CPython 3.13 abi3 Windows x86-64 Details
pedigree_graph-0.9.3-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 abi3 Linux glibc 2.17+ x86-64 Details
pedigree_graph-0.9.3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 abi3 Linux glibc 2.17+ ARM64 Details
pedigree_graph-0.9.3-cp313-abi3-macosx_11_0_arm64.whl CPython 3.13 abi3 macOS 11.0+ ARM64 Details
pedigree_graph-0.9.3-cp313-abi3-macosx_10_12_x86_64.whl CPython 3.13 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.4 MB

Release files / pedigree_graph-0.9.3.tar.gz

Download URL pedigree_graph-0.9.3.tar.gz
Size 615.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a32d2398a55d7faa227481c46ea46f60b9618df0b2f017d44d263963d2a3c00f
BLAKE2b-256 checksum
How to use checksums
0929a69a13ec0f72359a29e27e6722d95c49221099a656f5a6b1c8f0a709c717
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 Sep 23, 2026.

Transparency log

Release files / pedigree_graph-0.9.3-cp313-abi3-win_amd64.whl

Download URL pedigree_graph-0.9.3-cp313-abi3-win_amd64.whl
Size 499.3 kB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8566c4d87d4e1daa595b302528d3a92decc114f05ff9ea057437548bc5454df4
BLAKE2b-256 checksum
How to use checksums
ee427098c23e35a73e08573aa2a010c95757b4b7ee5e53edfa77c70a8e75fd63
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 Sep 23, 2026.

Transparency log

Release files / pedigree_graph-0.9.3-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pedigree_graph-0.9.3-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 610.0 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
fd91de2b80f7f5a703013854a84fd52c70aaa7b9f4b0e2a769ea7296db48f057
BLAKE2b-256 checksum
How to use checksums
2b7942157c14dd7da153ca494cc6d47fa59b0bb44d9e3e421452d68d68cda15a
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 Sep 23, 2026.

Transparency log

Release files / pedigree_graph-0.9.3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pedigree_graph-0.9.3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 580.8 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
4407d8b85027634d331b0208e6e67668d601ff64dc0fa0f91fbe8477dc174a25
BLAKE2b-256 checksum
How to use checksums
234f665631a139e8c94231964a8d4b9583baa1284861a6ffa9face244287c48c
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 Sep 23, 2026.

Transparency log

Release files / pedigree_graph-0.9.3-cp313-abi3-macosx_11_0_arm64.whl

Download URL pedigree_graph-0.9.3-cp313-abi3-macosx_11_0_arm64.whl
Size 551.4 kB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
23ac2c02b95f690cc0d4453d6d6e59dd9d51d1d6bea97bf4c5675001d31b5bdd
BLAKE2b-256 checksum
How to use checksums
3521df7d2edf2d17df5e6e3c0651842b678d375a4ef9150bc079b90488fc9d5d
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 Sep 23, 2026.

Transparency log

Release files / pedigree_graph-0.9.3-cp313-abi3-macosx_10_12_x86_64.whl

Download URL pedigree_graph-0.9.3-cp313-abi3-macosx_10_12_x86_64.whl
Size 571.1 kB
Tags CPython 3.13 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a907b3cf2c779841e5fcfd04378b9a31f034ba1eed40034c8620f58d82da7a87
BLAKE2b-256 checksum
How to use checksums
5c9b488afcea1618b6bc9d168122247acd46519fb1952b895aabfe03ccac63b6
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 Sep 23, 2026.

Transparency log

Security for pedigree-graph 0.9.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

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for pedigree_graph-0.9.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 Sep 23, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page