Skip to content

Commit 3631396

Browse files
benjefferymergify[bot]
authored andcommitted
Fix nbytes when no indexes
1 parent 734311a commit 3631396

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

python/tests/test_tables.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,6 +3326,10 @@ def test_str(self):
33263326
s = str(tables)
33273327
assert len(s) > 0
33283328

3329+
def test_nbytes_empty_tables(self):
3330+
tables = tskit.TableCollection(1)
3331+
assert tables.nbytes == 119
3332+
33293333
def test_nbytes(self, tmp_path, ts_fixture):
33303334
tables = ts_fixture.dump_tables()
33313335
tables.dump(tmp_path / "tables")

python/tskit/tables.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,12 @@ def asdict(self):
309309

310310
@property
311311
def nbytes(self):
312-
return self.edge_insertion_order.nbytes + self.edge_removal_order.nbytes
312+
total = 0
313+
if self.edge_removal_order is not None:
314+
total += self.edge_removal_order.nbytes
315+
if self.edge_insertion_order is not None:
316+
total += self.edge_insertion_order.nbytes
317+
return total
313318

314319

315320
def keep_with_offset(keep, data, offset):

0 commit comments

Comments
 (0)