Skip to content

Add assert_equal to TableCollection and TreeSequence #1076

Description

@jeromekelleher

The '.equalsmethod is very useful, but it doesn't tell us where the problem is when tables are not equal. We should add methodsassert_equal`` which would initially look like

def assert_equal(self, other, ignore_provenance=...) # same signature as equals
    assert self.sequence_length == other.sequence_length
    assert self.nodes == other.nodes
    # etc

This would at least tell us which table the mismatch occurs in. We can imagine providing a more detailed picture of how tables differ at some point, but this could be added later as a refinement. This form assert_equal should integrate nicely with pytest, and clean up our testing code some more.

Seems like a straightforward win?

Activity

  1. added
    Python API
    on Dec 7, 2020
  2. added this to the Python 0.3.5 milestone on Dec 7, 2020
  3. hyanwong commented on Dec 7, 2020

    @hyanwong
    Member

    Definitely. The other way would be for the equality testing code to break at different places. E.g. if it were in python, you could do:

    def equals(self, other):
        if self.table1 != other.table1:
             return False
        if self.table2 != other.table2:
             return False
        ...
        return True
    

    But AFAIK the comparison is in C, so I guess that's not so easy, and a separate assert_equals function (for Python only?) is a much easier win.

  4. jeromekelleher commented on Dec 7, 2020

    @jeromekelleher
    MemberAuthor

    Yes, this is Python only.

  5. added a commit that references this issue on Jan 2, 2021
    88e2f9a
  6. added a commit that references this issue on Jan 29, 2021
    28ca24d
  7. added a commit that references this issue on Feb 2, 2021
    986db65
  8. added a commit that references this issue on Feb 2, 2021
    5011987
  9. added a commit that references this issue on Feb 3, 2021
    5bfe9cd
  10. jeromekelleher commented on Feb 3, 2021

    @jeromekelleher
    MemberAuthor

    Reopening this, as we want it to be part of the public API.

  11. hyanwong commented on Apr 23, 2021

    @hyanwong
    Member

    I've hit this again when debugging tsinfer msprime0.7.4->1.0.0 issues. It would be super useful to port @petrelharp 's code into tskit proper. How much work is it? Do the tests for the method already exist in pyslim?

  12. benjeffery commented on Apr 23, 2021

    @benjeffery
    Member

    Was just working on this funnily enough! It will be in the next release, might be on main later today.

  13. hyanwong commented on Apr 23, 2021

    @hyanwong
    Member

    You star, @benjeffery !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Python API

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions