Skip to content

Commit 69c2eb1

Browse files
Merge pull request #564 from jeromekelleher/yet-more-packaging
Add workflow for testing base API
2 parents 49c9307 + d086fe3 commit 69c2eb1

File tree

9 files changed

+558
-461
lines changed

9 files changed

+558
-461
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ jobs:
8686
run: |
8787
sc2ts info-matches testrun/test.matches.db
8888
89+
bare_api:
90+
name: Bare API tests
91+
runs-on: ubuntu-latest
92+
steps:
93+
- uses: actions/checkout@v4
94+
- uses: actions/setup-python@v5
95+
with:
96+
python-version: '3.11'
97+
- name: Install dependencies
98+
run: |
99+
python -m pip install --upgrade pip
100+
python -m pip install '.'
101+
python -m pip install pytest
102+
- name: Run tests
103+
run: |
104+
# We are careful to pull in the minimum dependencies here
105+
# and only operate on files stored in the repo
106+
python -m pytest -v -c /dev/null -p no:sc2ts_fixtures tests/test_api.py
107+
89108
packaging:
90109
name: Packaging tests
91110
runs-on: ubuntu-latest

sc2ts/jit.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import dataclasses
22
import logging
33

4-
54
import numpy as np
65
import numba
76
import tskit.jit.numba as tskit_numba
@@ -94,8 +93,6 @@ def get_path_mrca(path1, path2, node_time):
9493
)
9594

9695

97-
98-
9996
@dataclasses.dataclass
10097
class ArgCounts:
10198
nodes_max_descendant_samples: np.ndarray
@@ -127,7 +124,9 @@ def _compute_inheritance_counts(
127124
edges_child = numba_ts.edges_child
128125
mutations_node = numba_ts.mutations_node
129126
mutations_parent = numba_ts.mutations_parent
130-
mutations_position = numba_ts.sites_position[numba_ts.mutations_site].astype(np.int32)
127+
mutations_position = numba_ts.sites_position[numba_ts.mutations_site].astype(
128+
np.int32
129+
)
131130
nodes_flags = numba_ts.nodes_flags
132131

133132
parent = np.zeros(num_nodes, dtype=np.int32) - 1
@@ -202,7 +201,7 @@ def count(ts):
202201
)
203202

204203

205-
# FIXME make cache optional
204+
# FIXME make cache optional.
206205
@numba.njit(cache=True)
207206
def encode_alignment(h):
208207
# Just so numba knows this is a constant string.
@@ -220,4 +219,3 @@ def encode_alignment(h):
220219
raise ValueError(f"Allele {h[j]} not recognised")
221220
a[j] = k
222221
return a
223-

sc2ts/stats.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from . import core
2-
from . import jit
32

43
import numpy as np
54
import pandas as pd
@@ -15,7 +14,14 @@ def convert_date(ts, time_array):
1514
return time_zero_date - time_array.astype("timedelta64[D]")
1615

1716

18-
def node_data(ts, inheritance_stats=True):
17+
def run_count(ts):
18+
# TODO Raise a friendly numba-error here
19+
from . import jit
20+
21+
return jit.count(ts)
22+
23+
24+
def node_data(ts, inheritance_stats=False):
1925
"""
2026
Return a pandas dataframe with one row for each node (in node ID order)
2127
from the specified tree sequence. This must be the output of
@@ -41,7 +47,7 @@ def node_data(ts, inheritance_stats=True):
4147
# minlength=ts.num_edges)
4248

4349
if inheritance_stats:
44-
counter = jit.count(ts)
50+
counter = run_count(ts)
4551
cols["max_descendant_samples"] = counter.nodes_max_descendant_samples
4652
dtype["max_descendant_samples"] = "int"
4753
if "time_zero_date" in ts.metadata:
@@ -50,7 +56,7 @@ def node_data(ts, inheritance_stats=True):
5056
return pd.DataFrame(cols).astype(dtype)
5157

5258

53-
def mutation_data(ts, inheritance_stats=True, parsimony_stats=False):
59+
def mutation_data(ts, inheritance_stats=False, parsimony_stats=False):
5460
"""
5561
Return a pandas dataframe with one row for each mutation (in mutation ID order)
5662
from the specified tree sequence. This must be the output of
@@ -70,7 +76,7 @@ def mutation_data(ts, inheritance_stats=True, parsimony_stats=False):
7076
if not isinstance(ts.metadata, bytes) and "time_zero_date" in ts.metadata:
7177
cols["date"] = convert_date(ts, ts.mutations_time)
7278
if inheritance_stats:
73-
counter = jit.count(ts)
79+
counter = run_count(ts)
7480
cols["num_descendants"] = counter.mutations_num_descendants
7581
cols["num_inheritors"] = counter.mutations_num_inheritors
7682

0 commit comments

Comments
 (0)