Skip to content

Fix ts unpickling #1298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

**Fixes**

- Tree sequences were not properly init'd after unpickling
(:user:`benjeffery`, :issue:`1297`, :pr:`1298`)

--------------------
[0.3.5] - 2021-03-16
--------------------
Expand Down
6 changes: 5 additions & 1 deletion python/tests/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,11 @@ def test_table_metadata_round_trip_via_row_getters(self):


def test_pickle_round_trip(ts_fixture):
assert ts_fixture.tables == pickle.loads(pickle.dumps(ts_fixture)).tables
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
ts = pickle.loads(pickle.dumps(ts_fixture, protocol=protocol))
assert ts.tables == ts_fixture.tables
# Do some thing to check the ts is init'd properly
ts.draw_text()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be quite an expensive thing to do, maybe something like assert ts.num_trees == len(list(ts.trees()))?

Copy link
Member Author

@benjeffery benjeffery Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't trigger the error unfortunately. The example ts is fixed and takes 40ms to run the current test on my box:

0.04s call     tests/test_highlevel.py::test_pickle_round_trip
0.01s setup    tests/test_highlevel.py::test_pickle_round_trip
0.00s teardown tests/test_highlevel.py::test_pickle_round_trip



class TestFileUuid(HighLevelTestCase):
Expand Down
2 changes: 1 addition & 1 deletion python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -3315,7 +3315,7 @@ def __getstate__(self):
return self.dump_tables()

def __setstate__(self, tc):
self._ll_tree_sequence = tc.tree_sequence().ll_tree_sequence
self.__init__(tc.tree_sequence().ll_tree_sequence)

def __eq__(self, other):
return self.tables == other.tables
Expand Down