Skip to content

Commit eae961c

Browse files
benjefferymergify[bot]
authored andcommitted
Fix dump_text
1 parent 4ab1cd1 commit eae961c

File tree

6 files changed

+271
-185
lines changed

6 files changed

+271
-185
lines changed

python/CHANGELOG.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
----------------------
2+
[0.4.0] - 2022-0X-XX
3+
----------------------
4+
5+
**Fixes**
6+
7+
- ``TreeSequence.dump_text`` now prints decoded metadata if there is a schema.
8+
(:user:`bejeffery`, :issue:`1860`, :issue:`1527`,
9+
10+
111
----------------------
212
[0.4.0] - 2021-12-10
313
----------------------

python/tests/conftest.py

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_something(self, ts_fixture):
4242
import pytest
4343
from pytest import fixture
4444

45-
import tskit
45+
from . import tsutil
4646

4747

4848
def pytest_addoption(parser):
@@ -108,74 +108,7 @@ def ts_fixture():
108108
"""
109109
A tree sequence with data in all fields
110110
"""
111-
demography = msprime.Demography()
112-
demography.add_population(name="A", initial_size=10_000)
113-
demography.add_population(name="B", initial_size=5_000)
114-
demography.add_population(name="C", initial_size=1_000)
115-
demography.add_population(name="D", initial_size=500)
116-
demography.add_population(name="E", initial_size=100)
117-
demography.add_population_split(time=1000, derived=["A", "B"], ancestral="C")
118-
ts = msprime.sim_ancestry(
119-
samples={"A": 10, "B": 10},
120-
demography=demography,
121-
sequence_length=5,
122-
random_seed=42,
123-
recombination_rate=1,
124-
record_migrations=True,
125-
record_provenance=True,
126-
)
127-
ts = msprime.sim_mutations(ts, rate=0.001, random_seed=42)
128-
tables = ts.dump_tables()
129-
# Add locations to individuals
130-
individuals_copy = tables.individuals.copy()
131-
tables.individuals.clear()
132-
for i, individual in enumerate(individuals_copy):
133-
tables.individuals.append(
134-
individual.replace(flags=i, location=[i, i + 1], parents=[i - 1, i - 1])
135-
)
136-
# Ensure all columns have unique values
137-
nodes_copy = tables.nodes.copy()
138-
tables.nodes.clear()
139-
for i, node in enumerate(nodes_copy):
140-
tables.nodes.append(
141-
node.replace(
142-
flags=i,
143-
time=node.time + 0.00001 * i,
144-
individual=i % len(tables.individuals),
145-
population=i % len(tables.populations),
146-
)
147-
)
148-
tables.migrations.add_row(left=0, right=1, node=21, source=1, dest=3, time=1001)
149-
150-
# Add metadata
151-
for name, table in tables.name_map.items():
152-
if name != "provenances":
153-
table.metadata_schema = tskit.MetadataSchema.permissive_json()
154-
metadatas = [f'{{"foo":"n_{name}_{u}"}}' for u in range(len(table))]
155-
metadata, metadata_offset = tskit.pack_strings(metadatas)
156-
table.set_columns(
157-
**{
158-
**table.asdict(),
159-
"metadata": metadata,
160-
"metadata_offset": metadata_offset,
161-
}
162-
)
163-
tables.metadata_schema = tskit.MetadataSchema.permissive_json()
164-
tables.metadata = "Test metadata"
165-
tables.time_units = "Test time units"
166-
167-
tables.reference_sequence.metadata_schema = tskit.MetadataSchema.permissive_json()
168-
tables.reference_sequence.metadata = "Test reference metadata"
169-
tables.reference_sequence.data = "A" * int(ts.sequence_length)
170-
# NOTE: it's unclear whether we'll want to have this set at the same time as
171-
# 'data', but it's useful to have something in all columns for now.
172-
tables.reference_sequence.url = "http://example.com/a_reference"
173-
174-
# Add some more rows to provenance to have enough for testing.
175-
for _ in range(3):
176-
tables.provenances.add_row(record="A")
177-
178-
return tables.tree_sequence()
111+
return tsutil.all_fields_ts()
179112

180113

181114
@fixture(scope="session")

0 commit comments

Comments
 (0)